mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-09 03:44:23 +00:00
added tweaked sibpath implementation
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.
This commit is contained in:
parent
38ff96b2f8
commit
9ed5533760
@ -1,11 +1,10 @@
|
||||
|
||||
from nevow import inevow, loaders, rend, tags as T
|
||||
from twisted.python import util
|
||||
import math
|
||||
from allmydata.util import mathutil
|
||||
from allmydata.util import mathutil, sibpath
|
||||
|
||||
def getxmlfile(name):
|
||||
return loaders.xmlfile(util.sibpath(__file__, "web/%s" % name))
|
||||
return loaders.xmlfile(sibpath.sibpath(__file__, "web/%s" % name))
|
||||
|
||||
# factorial and binomial copied from
|
||||
# http://mail.python.org/pipermail/python-list/2007-April/435718.html
|
||||
|
24
src/allmydata/util/sibpath.py
Normal file
24
src/allmydata/util/sibpath.py
Normal file
@ -0,0 +1,24 @@
|
||||
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
|
||||
|
@ -3,12 +3,12 @@ from base64 import b32encode
|
||||
import os.path
|
||||
from twisted.application import service, strports, internet
|
||||
from twisted.web import static, resource, server, html, http
|
||||
from twisted.python import util, log
|
||||
from twisted.python import log
|
||||
from twisted.internet import defer
|
||||
from twisted.internet.interfaces import IConsumer
|
||||
from nevow import inevow, rend, loaders, appserver, url, tags as T
|
||||
from nevow.static import File as nevow_File # TODO: merge with static.File?
|
||||
from allmydata.util import fileutil
|
||||
from allmydata.util import fileutil, sibpath
|
||||
import simplejson
|
||||
from allmydata.interfaces import IDownloadTarget, IDirectoryNode, IFileNode, \
|
||||
IMutableFileNode
|
||||
@ -21,7 +21,7 @@ import urllib
|
||||
from formless import webform
|
||||
|
||||
def getxmlfile(name):
|
||||
return loaders.xmlfile(util.sibpath(__file__, "web/%s" % name))
|
||||
return loaders.xmlfile(sibpath.sibpath(__file__, "web/%s" % name))
|
||||
|
||||
class IClient(Interface):
|
||||
pass
|
||||
@ -1302,7 +1302,7 @@ class Root(rend.Page):
|
||||
return rend.Page.locateChild(self, ctx, segments)
|
||||
|
||||
child_webform_css = webform.defaultCSS
|
||||
child_tahoe_css = nevow_File(util.sibpath(__file__, "web/tahoe.css"))
|
||||
child_tahoe_css = nevow_File(sibpath.sibpath(__file__, "web/tahoe.css"))
|
||||
|
||||
child_provisioning = provisioning.ProvisioningTool()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user