]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - bin/tahoe-script.template
674a27d99aa3c2b96223f14a1197bba17db9a250
[tahoe-lafs/tahoe-lafs.git] / bin / tahoe-script.template
1 #!/bin/false # You must specify a python interpreter.
2
3 import errno, sys, os, subprocess
4
5 where = os.path.realpath(sys.argv[0])
6 base = os.path.dirname(os.path.dirname(where))
7
8 whoami = '''\
9 I am a "bin/tahoe" executable who is only for the convenience of running
10 Tahoe from its source distribution -- I work only when invoked as the "tahoe"
11 script that lives in the "bin/" subdirectory of a Tahoe source code
12 distribution, and only if you have already run "make".
13 '''
14
15 # look for Tahoe.home .
16 homemarker = os.path.join(base, "Tahoe.home")
17 if not os.path.exists(homemarker):
18     print whoami
19     print '''\
20 I just tried to run and found that I am not living in such a directory, so I
21 am stopping now. To run Tahoe after it has been is installed, please execute
22 my brother, also named "tahoe", who gets installed into the appropriate place
23 for executables when you run "make install" (perhaps as /usr/bin/tahoe).
24 '''
25     sys.exit(1)
26
27 # we've found our home. Put the tahoe support/lib etc. in our PYTHONPATH.
28 if sys.platform == "win32":
29     supportdir = os.path.join(base, "support", "Lib", "site-packages")
30 else:
31     supportdir = os.path.join(base, "support",
32                               "lib",
33                               "python%d.%d" % sys.version_info[:2],
34                               "site-packages")
35
36 # update PYTHONPATH so that child processes (like twistd) will use this too
37 pp = os.environ.get("PYTHONPATH")
38 if pp:
39     pp = os.pathsep.join([supportdir] + pp.split(os.pathsep))
40 else:
41     pp = supportdir
42 os.environ["PYTHONPATH"] = pp
43
44 # find the location of the tahoe executable.
45 bin_dir = "bin"
46 if sys.platform == "win32":
47     bin_dir = "Scripts"
48 executable = os.path.join(base, "support", bin_dir, "tahoe")
49
50 try:
51     res = subprocess.call([executable] + sys.argv[1:], env=os.environ)
52 except (OSError, IOError), le:
53     if le.args[0] == errno.ENOENT:
54         print whoami
55         print '''\
56 I just tried to run and could not find my brother, named
57 "../support/bin/tahoe". To run Tahoe when it is installed, please execute my
58 brother, also named "tahoe", who gets installed into the appropriate place
59 for executables when you run "make install" (perhaps as /usr/bin/tahoe).
60 '''
61         raise
62 except Exception, le:
63     print whoami
64     print '''\
65 I just tried to invoke my brother, named "../support/bin/tahoe" and got an
66 exception.
67 '''
68     raise
69 else:
70     sys.exit(res)