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
--- /dev/null
+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
+
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
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
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()