tahoe-lafs/bin/tahoe-script.template

111 lines
3.8 KiB
Plaintext
Raw Normal View History

#!/bin/false # You must specify a python interpreter.
import errno, sys, os, subprocess
where = os.path.realpath(sys.argv[0])
base = os.path.dirname(os.path.dirname(where))
if sys.platform == "win32":
perhaps_installed_tahoe = os.path.join(os.path.dirname(sys.executable), 'Scripts', 'tahoe.pyscript')
else:
perhaps_installed_tahoe = "/usr/bin/tahoe"
2008-09-12 01:02:25 +00:00
whoami = '''\
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".
''' % (os.path.sep,)
2008-09-12 01:02:25 +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
my brother, who gets installed into the appropriate place for executables
when you run "make install" (perhaps as "%s").
''' % (perhaps_installed_tahoe,)
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
# find commandline args and the location of the tahoe executable.
2009-01-09 19:42:22 +00:00
if sys.platform == "win32":
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)]
# 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:]
if arg == u'-m':
# sys.argv[0] should really be the absolute path of the module source, but never mind
break
if arg == u'-c':
argv[0] = u'-c'
break
local_tahoe = "Scripts\\tahoe.pyscript"
else:
argv = sys.argv
local_tahoe = "bin/tahoe"
script = os.path.join(base, "support", local_tahoe)
try:
res = subprocess.call([sys.executable, script] + argv[1:], env=os.environ)
except (OSError, IOError), le:
if le.args[0] == errno.ENOENT:
2008-09-12 01:02:25 +00:00
print whoami
print '''\
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").
''' % (script, perhaps_installed_tahoe)
raise
except Exception, le:
2008-09-12 01:02:25 +00:00
print whoami
print '''\
I just tried to invoke my brother at "%s"
and got an exception.
''' % (script,)
raise
else:
sys.exit(res)
2009-02-11 18:19:35 +00:00