summaryrefslogtreecommitdiff
path: root/repoze/bfg/resource.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2010-02-04 18:32:36 +0000
committerChris McDonough <chrism@agendaless.com>2010-02-04 18:32:36 +0000
commit89968dce0273f49cf34e07480077f7843593f54e (patch)
treebc7f1f02d0af23c497bbb612e962def3a044d6fc /repoze/bfg/resource.py
parentd43b02fbe101233ad89eee605d558ca6f60a7e01 (diff)
downloadpyramid-89968dce0273f49cf34e07480077f7843593f54e.tar.gz
pyramid-89968dce0273f49cf34e07480077f7843593f54e.tar.bz2
pyramid-89968dce0273f49cf34e07480077f7843593f54e.zip
- Fix a bug whereby a ``renderer`` argument to the ``@bfg_view``
decorator that provided a package-relative template filename might not have been resolved properly. Symptom: inappropriate ``Missing template resource`` errors.
Diffstat (limited to 'repoze/bfg/resource.py')
-rw-r--r--repoze/bfg/resource.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/repoze/bfg/resource.py b/repoze/bfg/resource.py
index 25e6af4f7..ff10273e4 100644
--- a/repoze/bfg/resource.py
+++ b/repoze/bfg/resource.py
@@ -5,6 +5,7 @@ from zope.interface import implements
from repoze.bfg.interfaces import IPackageOverrides
+from repoze.bfg.path import package_path
from repoze.bfg.threadlocal import get_current_registry
class OverrideProvider(pkg_resources.DefaultProvider):
@@ -180,3 +181,18 @@ def resolve_resource_spec(spec, package_name='__main__'):
elif package_name is None:
package_name, filename = None, spec
return package_name, filename
+
+def resource_spec_from_abspath(abspath, package):
+ """ Try to convert an absolute path to a resource in a package to
+ a resource specification if possible; otherwise return the
+ absolute path. """
+ if getattr(package, '__name__', None) == '__main__':
+ return abspath
+ pp = package_path(package) + os.path.sep
+ if abspath.startswith(pp):
+ relpath = abspath[len(pp):]
+ return '%s:%s' % (package.__name__,
+ relpath.replace(os.path.sep, '/'))
+ return abspath
+
+