2009-01-29 01:07:16 +00:00
|
|
|
#!/bin/false # You must specify a python interpreter.
|
2006-12-05 19:25:23 +00:00
|
|
|
|
2009-01-09 19:03:00 +00:00
|
|
|
import errno, sys, 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 = '''\
|
2010-07-25 08:32:16 +00:00
|
|
|
I am a "bin%stahoe" executable who is only for the convenience of running
|
2008-09-12 01:02:25 +00:00
|
|
|
Tahoe from its source distribution -- I work only when invoked as the "tahoe"
|
|
|
|
script that lives in the "bin/" subdirectory of a Tahoe source code
|
|
|
|
distribution, and only if you have already run "make".
|
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):
|
2008-09-12 01:02:25 +00:00
|
|
|
print whoami
|
|
|
|
print '''\
|
|
|
|
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").
|
2010-11-01 04:26:02 +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):
|
|
|
|
return str(re.sub(ur'[^\x20-\x7F]', lambda m: u'\x7F%x;' % (ord(m.group(0)),), s))
|
|
|
|
|
|
|
|
argv = [mangle(argv_unicode[i]) for i in xrange(1, argc.value)]
|
2010-07-28 06:27:31 +00:00
|
|
|
|
|
|
|
# Skip option arguments to the Python interpreter.
|
|
|
|
while len(argv) > 0:
|
|
|
|
arg = argv[0]
|
|
|
|
if not arg.startswith(u"-") or arg == u"-":
|
|
|
|
break
|
|
|
|
argv = argv[1:]
|
2010-11-27 23:26:50 +00:00
|
|
|
if arg == u'-m' or arg == u'-c':
|
2010-07-28 06:27:31 +00:00
|
|
|
break
|
|
|
|
|
2010-11-27 23:26:50 +00:00
|
|
|
script = os.path.join(base, "support", "Scripts", "tahoe.pyscript")
|
|
|
|
|
|
|
|
# On Windows, the script is not directly executable and must be run via python.
|
|
|
|
args = [sys.executable, script] + argv[1:]
|
2010-07-25 08:32:16 +00:00
|
|
|
else:
|
2010-11-27 23:26:50 +00:00
|
|
|
script = os.path.join(base, "support", "bin", "tahoe")
|
2010-07-25 08:32:16 +00:00
|
|
|
|
2010-11-27 23:26:50 +00:00
|
|
|
# On non-Windows, invoke the script directly, so that 'top' for example shows 'tahoe'.
|
|
|
|
args = [script] + sys.argv[1:]
|
2008-04-10 21:40:37 +00:00
|
|
|
|
|
|
|
try:
|
2010-11-27 23:26:50 +00:00
|
|
|
res = subprocess.call(args, env=os.environ)
|
2008-04-10 21:40:37 +00:00
|
|
|
except (OSError, IOError), le:
|
|
|
|
if le.args[0] == errno.ENOENT:
|
2008-09-12 01:02:25 +00:00
|
|
|
print whoami
|
|
|
|
print '''\
|
2010-07-25 08:32:16 +00:00
|
|
|
I just tried to run and could not find my brother at
|
|
|
|
"%s". To run Tahoe when it is installed, please execute my
|
|
|
|
brother, who gets installed into the appropriate place for executables
|
|
|
|
when you run "make install" (perhaps as "%s").
|
2010-11-01 04:26:02 +00:00
|
|
|
''' % (script, perhaps_installed_tahoe)
|
2008-04-10 21:40:37 +00:00
|
|
|
raise
|
|
|
|
except Exception, le:
|
2008-09-12 01:02:25 +00:00
|
|
|
print whoami
|
|
|
|
print '''\
|
2010-07-25 08:32:16 +00:00
|
|
|
I just tried to invoke my brother at "%s"
|
|
|
|
and got an exception.
|
|
|
|
''' % (script,)
|
2008-04-10 21:40:37 +00:00
|
|
|
raise
|
2009-01-24 01:49:11 +00:00
|
|
|
else:
|
|
|
|
sys.exit(res)
|
2009-02-11 18:19:35 +00:00
|
|
|
|