]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - bin/tahoe
d15064300a363982b2e64c752051d67949b26b69
[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)/allmydata-tahoe
11 #  .../(BASE)/bin/allmydata-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         sys.path.extend(support_eggs)
34
35         # also update PYTHONPATH so that child processes (like twistd) will
36         # use this too
37         pp = os.environ.get("PYTHONPATH")
38         if pp:
39             pp = os.pathsep.join([srcdir] + pp.split(os.pathsep) + support_eggs)
40         else:
41             pp = os.pathsep.join([srcdir] + support_eggs)
42         os.environ["PYTHONPATH"] = pp
43
44 from allmydata.scripts import runner
45 runner.run()