mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-29 09:18:53 +00:00
9ed5533760
use of twisted.python.util.sibpath to find files relative to modules doesn't work when those modules are bundled into a library by py2exe. this provides an alternative implementation (in allmydata.util.sibpath) which checks for the existence of the file, and if it is not found, attempts to find it relative to sys.executable instead.
25 lines
1023 B
Python
25 lines
1023 B
Python
import os
|
|
import sys
|
|
from twisted.python.util import sibpath as tsibpath
|
|
|
|
def sibpath(path, sibling):
|
|
"""
|
|
Looks for a named sibling relative to the given path. If such a file
|
|
exists, its path will be returned, otherwise a second search will be
|
|
made for the named sibling relative to the path of the executable
|
|
currently running. This is useful in the case that something built
|
|
with py2exe, for example, needs to find data files relative to its
|
|
install. Note hence that care should be taken not to search for
|
|
private package files whose names might collide with files which might
|
|
be found installed alongside the python interpreter itself. If no
|
|
file is found in either place, the sibling relative to the given path
|
|
is returned, likely leading to a file not found error.
|
|
"""
|
|
sib = tsibpath(path, sibling)
|
|
if not os.path.exists(sib):
|
|
exe_sib = tsibpath(sys.executable, sibling)
|
|
if os.path.exists(exe_sib):
|
|
return exe_sib
|
|
return sib
|
|
|