]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/util/sibpath.py
added tweaked sibpath implementation
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / util / sibpath.py
1 import os
2 import sys
3 from twisted.python.util import sibpath as tsibpath
4
5 def sibpath(path, sibling):
6     """
7     Looks for a named sibling relative to the given path.  If such a file
8     exists, its path will be returned, otherwise a second search will be
9     made for the named sibling relative to the path of the executable
10     currently running.  This is useful in the case that something built
11     with py2exe, for example, needs to find data files relative to its
12     install.  Note hence that care should be taken not to search for
13     private package files whose names might collide with files which might
14     be found installed alongside the python interpreter itself.  If no
15     file is found in either place, the sibling relative to the given path
16     is returned, likely leading to a file not found error.
17     """
18     sib = tsibpath(path, sibling)
19     if not os.path.exists(sib):
20         exe_sib = tsibpath(sys.executable, sibling)
21         if os.path.exists(exe_sib):
22             return exe_sib
23     return sib
24