]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - bin/tahoe
setup: fix bin/tahoe to include .egg's from the source tree root dir as well
[tahoe-lafs/tahoe-lafs.git] / bin / tahoe
1 #!/usr/bin/env python
2
3 # This preamble is adapted from Twisted. If we're being run from a source
4 # tree, add that tree's libdir to our path, so tahoe can be run from source
5 # without a lot of tedious PYTHONPATH changes.
6 import sys, os.path
7 where = os.path.realpath(sys.argv[0]).split(os.sep)
8
9 # look for Tahoe.home . Two cases:
10 #  ...(not BASE)/tahoe
11 #  .../(BASE)/bin/tahoe
12 if len(where) >= 2 and where[-2] == "bin":
13     base = os.sep.join(where[:-2])
14
15     if os.path.exists(os.path.join(base, "Tahoe.home")):
16         # we've found our home. Put the tahoe source at the front of sys.path
17         srcdir = os.path.join(base, "src")
18         sys.path.insert(0, srcdir)
19         # and put any support eggs at the end of sys.path
20         if sys.platform == "win32":
21             supportdir = os.path.join(base, "support", "Lib", "site-packages")
22         else:
23             supportdir = os.path.join(base, "support",
24                                       "lib",
25                                       "python%d.%d" % sys.version_info[:2],
26                                       "site-packages")
27         support_eggs = []
28         if os.path.exists(supportdir):
29             for fn in os.listdir(supportdir):
30                 if fn.endswith(".egg"):
31                     support_eggs.append(os.path.join(supportdir, fn))
32
33         # We also need to include .egg's in the base dir, because if there is an
34         # .egg there then "make build-deps" will take that as satisfying its
35         # requirements.
36         for fn in os.listdir(base):
37             if fn.endswith(".egg"):
38                 support_eggs.append(os.path.abspath(os.path.join(base, fn)))
39
40         sys.path.extend(support_eggs)
41
42         # also update PYTHONPATH so that child processes (like twistd) will
43         # use this too
44         pp = os.environ.get("PYTHONPATH")
45         if pp:
46             pp = os.pathsep.join([srcdir] + pp.split(os.pathsep) + support_eggs)
47         else:
48             pp = os.pathsep.join([srcdir] + support_eggs)
49         os.environ["PYTHONPATH"] = pp
50
51 from allmydata.scripts import runner
52 runner.run()