1 #!/bin/false # You must specify a python interpreter.
3 import errno, sys, os, subprocess
5 where = os.path.realpath(sys.argv[0])
6 base = os.path.dirname(os.path.dirname(where))
8 if sys.platform == "win32":
9 perhaps_installed_tahoe = os.path.join(os.path.dirname(sys.executable), 'Scripts', 'tahoe.pyscript')
11 perhaps_installed_tahoe = "/usr/bin/tahoe"
14 I am a "bin%stahoe" executable who is only for the convenience of running
15 Tahoe from its source distribution -- I work only when invoked as the "tahoe"
16 script that lives in the "bin/" subdirectory of a Tahoe source code
17 distribution, and only if you have already run "make".
20 # look for Tahoe.home .
21 homemarker = os.path.join(base, "Tahoe.home")
22 if not os.path.exists(homemarker):
25 I just tried to run and found that I am not living in such a directory, so I
26 am stopping now. To run Tahoe after it has been is installed, please execute
27 my brother, who gets installed into the appropriate place for executables
28 when you run "make install" (perhaps as "%s").
29 ''' % (perhaps_installed_tahoe,)
32 # we've found our home. Put the tahoe support/lib etc. in our PYTHONPATH.
33 if sys.platform == "win32":
34 supportdir = os.path.join(base, "support", "Lib", "site-packages")
36 supportdir = os.path.join(base, "support",
38 "python%d.%d" % sys.version_info[:2],
41 # update PYTHONPATH so that child processes (like twistd) will use this too
42 pp = os.environ.get("PYTHONPATH")
44 pp = os.pathsep.join([supportdir] + pp.split(os.pathsep))
47 os.environ["PYTHONPATH"] = pp
49 # find commandline args and the location of the tahoe executable.
50 if sys.platform == "win32":
52 from ctypes import WINFUNCTYPE, POINTER, byref, c_wchar_p, c_int, windll
54 GetCommandLineW = WINFUNCTYPE(c_wchar_p)(("GetCommandLineW", windll.kernel32))
55 CommandLineToArgvW = WINFUNCTYPE(POINTER(c_wchar_p), c_wchar_p, POINTER(c_int)) \
56 (("CommandLineToArgvW", windll.shell32))
59 argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))
61 # See src/allmydata/scripts/runner.py for the corresponding unmangler.
62 # Note that this doesn't escape \x7F. If it did, test_unicode_arguments_and_output
63 # in test_runner.py wouldn't work.
65 return str(re.sub(ur'[^\x20-\x7F]', lambda m: u'\x7F%x;' % (ord(m.group(0)),), s))
67 argv = [mangle(argv_unicode[i]) for i in xrange(1, argc.value)]
69 # Skip option arguments to the Python interpreter.
72 if not arg.startswith(u"-") or arg == u"-":
76 # sys.argv[0] should really be the absolute path of the module source, but never mind
82 local_tahoe = "Scripts\\tahoe.pyscript"
85 local_tahoe = "bin/tahoe"
87 script = os.path.join(base, "support", local_tahoe)
90 res = subprocess.call([sys.executable, script] + argv[1:], env=os.environ)
91 except (OSError, IOError), le:
92 if le.args[0] == errno.ENOENT:
95 I just tried to run and could not find my brother at
96 "%s". To run Tahoe when it is installed, please execute my
97 brother, who gets installed into the appropriate place for executables
98 when you run "make install" (perhaps as "%s").
99 ''' % (script, perhaps_installed_tahoe)
101 except Exception, le:
104 I just tried to invoke my brother at "%s"
105 and got an exception.