2009-01-29 01:07:16 +00:00
#!/bin/false # You must specify a python interpreter.
2013-03-15 04:41:53 +00:00
import sys; assert sys.version_info < (3,), ur"Tahoe-LAFS does not run under Python 3. Please use a version of Python between 2.5 and 2.7.x inclusive."
2006-12-05 19:25:23 +00:00
2013-03-15 04:41:53 +00:00
import os, subprocess
2008-04-10 21:40:37 +00:00
where = os.path.realpath(sys.argv[0])
base = os.path.dirname(os.path.dirname(where))
2010-07-25 08:32:16 +00:00
if sys.platform == "win32":
2010-11-01 04:26:02 +00:00
perhaps_installed_tahoe = os.path.join(os.path.dirname(sys.executable), 'Scripts', 'tahoe.pyscript')
2010-07-25 08:32:16 +00:00
else:
2010-11-01 04:26:02 +00:00
perhaps_installed_tahoe = "/usr/bin/tahoe"
2010-07-25 08:32:16 +00:00
2008-09-12 01:02:25 +00:00
whoami = '''\
2011-08-17 22:26:51 +00:00
I am a "bin%stahoe" executable for the convenience of running Tahoe-LAFS
from its source distribution -- I work only when invoked as the "tahoe"
2011-01-19 04:53:24 +00:00
script that lives in the "bin" subdirectory of a Tahoe source code
distribution, and only if you have already run "python setup.py build".
2010-07-25 08:32:16 +00:00
''' % (os.path.sep,)
2008-09-12 01:02:25 +00:00
2008-04-10 21:40:37 +00:00
# look for Tahoe.home .
homemarker = os.path.join(base, "Tahoe.home")
if not os.path.exists(homemarker):
2013-03-15 04:28:35 +00:00
print(whoami)
print('''\
2008-09-12 01:02:25 +00:00
I just tried to run and found that I am not living in such a directory, so I
am stopping now. To run Tahoe after it has been is installed, please execute
2010-07-25 08:32:16 +00:00
my brother, who gets installed into the appropriate place for executables
when you run "make install" (perhaps as "%s").
2013-03-15 04:28:35 +00:00
''' % (perhaps_installed_tahoe,))
2008-04-10 21:40:37 +00:00
sys.exit(1)
# we've found our home. Put the tahoe support/lib etc. in our PYTHONPATH.
if sys.platform == "win32":
supportdir = os.path.join(base, "support", "Lib", "site-packages")
else:
supportdir = os.path.join(base, "support",
"lib",
"python%d.%d" % sys.version_info[:2],
"site-packages")
# update PYTHONPATH so that child processes (like twistd) will use this too
pp = os.environ.get("PYTHONPATH")
if pp:
pp = os.pathsep.join([supportdir] + pp.split(os.pathsep))
else:
pp = supportdir
os.environ["PYTHONPATH"] = pp
2010-07-25 08:32:16 +00:00
# find commandline args and the location of the tahoe executable.
2009-01-09 19:42:22 +00:00
if sys.platform == "win32":
2010-07-25 08:32:16 +00:00
import re
from ctypes import WINFUNCTYPE, POINTER, byref, c_wchar_p, c_int, windll
GetCommandLineW = WINFUNCTYPE(c_wchar_p)(("GetCommandLineW", windll.kernel32))
CommandLineToArgvW = WINFUNCTYPE(POINTER(c_wchar_p), c_wchar_p, POINTER(c_int)) \
(("CommandLineToArgvW", windll.shell32))
argc = c_int(0)
argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))
# See src/allmydata/scripts/runner.py for the corresponding unmangler.
# Note that this doesn't escape \x7F. If it did, test_unicode_arguments_and_output
# in test_runner.py wouldn't work.
def mangle(s):
2013-03-15 04:41:53 +00:00
return str(re.sub(u'[^\\x20-\\x7F]', lambda m: u'\x7F%x;' % (ord(m.group(0)),), s))
2010-07-25 08:32:16 +00:00
2011-01-19 04:53:24 +00:00
argv = [mangle(argv_unicode[i]) for i in xrange(0, argc.value)]
2010-07-28 06:27:31 +00:00
2011-01-19 04:53:24 +00:00
# Take only the suffix with the same number of arguments as sys.argv.
# This accounts for anything that can cause initial arguments to be stripped,
# for example, the Python interpreter or any options passed to it, or runner
# scripts such as 'coverage run'. It works even if there are no such arguments,
# as in the case of a frozen executable created by bb-freeze or similar.
2010-07-28 06:27:31 +00:00
2011-01-19 04:53:24 +00:00
argv = argv[-len(sys.argv):]
2010-11-27 23:26:50 +00:00
# On Windows, the script is not directly executable and must be run via python.
2011-01-19 04:53:24 +00:00
prefix = [sys.executable]
script = os.path.join(base, "support", "Scripts", "tahoe.pyscript")
args = argv[1:]
2010-07-25 08:32:16 +00:00
else:
2010-11-27 23:26:50 +00:00
# On non-Windows, invoke the script directly, so that 'top' for example shows 'tahoe'.
2011-01-19 04:53:24 +00:00
prefix = []
script = os.path.join(base, "support", "bin", "tahoe")
args = sys.argv[1:]
2008-04-10 21:40:37 +00:00
2011-01-19 05:11:37 +00:00
# Support indirection via another "runner" script (e.g. coverage).
# For example: bin/tahoe @RUNNER RUNNER_ARGS @tahoe TAHOE_ARGS
if len(args) >= 1 and args[0].startswith('@'):
runner = args[0][1:]
if runner.endswith('.py') or runner.endswith('.pyscript'):
prefix = [sys.executable]
else:
prefix = []
def _subst(a):
if a == '@tahoe': return script
return a
command = prefix + [runner] + map(_subst, args[1:])
else:
2011-08-17 22:26:51 +00:00
runner = script
2011-01-19 05:11:37 +00:00
command = prefix + [script] + args
2011-01-19 04:53:24 +00:00
2011-08-17 22:26:51 +00:00
if not os.path.exists(script):
2013-03-15 04:28:35 +00:00
print(whoami)
print('''\
2011-08-17 22:26:51 +00:00
I could not find the support script
"%s".
To run an installed version of Tahoe-LAFS, please execute the "tahoe"
script that is installed into the appropriate place for executables
when you run "python setup.py install" (perhaps as "%s").
2013-03-15 04:28:35 +00:00
''' % (script, perhaps_installed_tahoe))
2011-08-17 22:26:51 +00:00
sys.exit(1)
2011-01-19 04:53:24 +00:00
try:
res = subprocess.call(command, env=os.environ)
2013-03-15 04:28:35 +00:00
except Exception as le:
print(whoami)
print('''\
2011-08-17 22:26:51 +00:00
I just tried to invoke "%s"
2010-07-25 08:32:16 +00:00
and got an exception.
2013-03-15 04:28:35 +00:00
''' % (runner,))
2008-04-10 21:40:37 +00:00
raise
2009-01-24 01:49:11 +00:00
else:
sys.exit(res)