]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
have mac app write a tahoe upon startup
authorrobk-tahoe <robk-tahoe@allmydata.com>
Wed, 23 Jan 2008 03:35:01 +0000 (20:35 -0700)
committerrobk-tahoe <robk-tahoe@allmydata.com>
Wed, 23 Jan 2008 03:35:01 +0000 (20:35 -0700)
upon startup, the .app will look in '/usr/local/bin', '~/bin', '~/Library/bin'
if it finds one of these dirs, and can write into it, and there isn't already
a 'tahoe' present, it will write a small bach script which will launch the
binary contained within the .app bundle

this allows the .app bundle to offer the services of the 'tahoe' script
easily and simply

mac/allmydata_tahoe.py

index 6eb828bb8a52b05cde7ef10166800b6d2b4f3f24..5cdad83267c89a9d605c8f6046d28617d1b3f349 100644 (file)
@@ -5,10 +5,21 @@ _junk = depends # appease pyflakes
 
 import sys
 import os
+import stat
+import traceback
+
+TRY_TO_INSTALL_TAHOE_SCRIPT = True
+TAHOE_SCRIPT = '''#!/bin/bash
+if [ "x${@}x" == "xx" ]
+then
+    %(exe)s --help
+else
+    %(exe)s "${@}"
+fi
+'''
 
 def run_default_node():
     import operator
-    import os
 
     basedir = os.path.expanduser('~/.tahoe')
     if not os.path.isdir(basedir):
@@ -70,6 +81,40 @@ def run_default_node():
         else:
             print 'files missing, not opening initial webish root page'
 
+    def maybe_install_tahoe_script():
+        path_candidates = ['/usr/local/bin', '~/bin', '~/Library/bin']
+        env_path = map(os.path.expanduser, os.environ['PATH'].split(':'))
+        if not sys.executable.endswith('/python'):
+            print 'not installing tahoe script: unexpected sys.exe "%s"' % (sys.executable,)
+            return
+        for path_candidate in map(os.path.expanduser, path_candidates):
+            if path_candidate not in env_path:
+                print path_candidate, 'not in', env_path
+                continue
+            tahoe_path = path_candidate + '/tahoe'
+            try:
+                if os.path.exists(tahoe_path):
+                    print 'not installing "%s": it already exists' % (tahoe_path,)
+                    return
+                print 'trying to install "%s"' % (tahoe_path,)
+                bin_path = (sys.executable[:-6] + 'Allmydata Tahoe').replace(' ', '\\ ')
+                script = TAHOE_SCRIPT % { 'exe': bin_path }
+                f = file(tahoe_path, 'wb')
+                f.write(script)
+                f.close()
+                mode = stat.S_IRUSR|stat.S_IXUSR|stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH
+                os.chmod(tahoe_path, mode)
+                print 'installed "%s"' % (tahoe_path,)
+                return
+            except:
+                print 'unable to write %s' % (tahoe_path,)
+                traceback.print_exc()
+        else:
+            print 'no remaining candidate paths for installation of tahoe script'
+
+    if TRY_TO_INSTALL_TAHOE_SCRIPT:
+        maybe_install_tahoe_script()
+
     # run the node itself
     os.chdir(basedir)
     c = client.Client(basedir)