1 #!/bin/false # You must specify a python interpreter.
2 u"Tahoe-LAFS does not run under Python 3. Please use a version of Python between 2.4.4 and 2.7.x inclusive."
4 import sys, os, subprocess
6 where = os.path.realpath(sys.argv[0])
7 base = os.path.dirname(os.path.dirname(where))
9 if sys.platform == "win32":
10 perhaps_installed_tahoe = os.path.join(os.path.dirname(sys.executable), 'Scripts', 'tahoe.pyscript')
12 perhaps_installed_tahoe = "/usr/bin/tahoe"
15 I am a "bin%stahoe" executable who is only for the convenience of running
16 Tahoe from its source distribution -- I work only when invoked as the "tahoe"
17 script that lives in the "bin" subdirectory of a Tahoe source code
18 distribution, and only if you have already run "python setup.py build".
21 # look for Tahoe.home .
22 homemarker = os.path.join(base, "Tahoe.home")
23 if not os.path.exists(homemarker):
26 I just tried to run and found that I am not living in such a directory, so I
27 am stopping now. To run Tahoe after it has been is installed, please execute
28 my brother, who gets installed into the appropriate place for executables
29 when you run "make install" (perhaps as "%s").
30 ''' % (perhaps_installed_tahoe,)
33 # we've found our home. Put the tahoe support/lib etc. in our PYTHONPATH.
34 if sys.platform == "win32":
35 supportdir = os.path.join(base, "support", "Lib", "site-packages")
37 supportdir = os.path.join(base, "support",
39 "python%d.%d" % sys.version_info[:2],
42 # update PYTHONPATH so that child processes (like twistd) will use this too
43 pp = os.environ.get("PYTHONPATH")
45 pp = os.pathsep.join([supportdir] + pp.split(os.pathsep))
48 os.environ["PYTHONPATH"] = pp
50 # find commandline args and the location of the tahoe executable.
51 if sys.platform == "win32":
53 from ctypes import WINFUNCTYPE, POINTER, byref, c_wchar_p, c_int, windll
55 GetCommandLineW = WINFUNCTYPE(c_wchar_p)(("GetCommandLineW", windll.kernel32))
56 CommandLineToArgvW = WINFUNCTYPE(POINTER(c_wchar_p), c_wchar_p, POINTER(c_int)) \
57 (("CommandLineToArgvW", windll.shell32))
60 argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))
62 # See src/allmydata/scripts/runner.py for the corresponding unmangler.
63 # Note that this doesn't escape \x7F. If it did, test_unicode_arguments_and_output
64 # in test_runner.py wouldn't work.
66 return str(re.sub(ur'[^\x20-\x7F]', lambda m: u'\x7F%x;' % (ord(m.group(0)),), s))
68 argv = [mangle(argv_unicode[i]) for i in xrange(0, argc.value)]
70 # Take only the suffix with the same number of arguments as sys.argv.
71 # This accounts for anything that can cause initial arguments to be stripped,
72 # for example, the Python interpreter or any options passed to it, or runner
73 # scripts such as 'coverage run'. It works even if there are no such arguments,
74 # as in the case of a frozen executable created by bb-freeze or similar.
76 argv = argv[-len(sys.argv):]
78 # On Windows, the script is not directly executable and must be run via python.
79 prefix = [sys.executable]
80 script = os.path.join(base, "support", "Scripts", "tahoe.pyscript")
83 # On non-Windows, invoke the script directly, so that 'top' for example shows 'tahoe'.
85 script = os.path.join(base, "support", "bin", "tahoe")
88 if not os.path.exists(script):
91 I just tried to run and could not find my brother at
92 "%s". To run Tahoe when it is installed, please execute my
93 brother, who gets installed into the appropriate place for executables
94 when you run "python setup.py install" (perhaps as "%s").
95 ''' % (script, perhaps_installed_tahoe)
98 command = prefix + [script] + args
101 res = subprocess.call(command, env=os.environ)
102 except Exception, le:
105 I just tried to invoke my brother at "%s"
106 and got an exception.