incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [3/9] git commit: [#6325] using jinja2.TemplateNotFound for bad paths
Date Thu, 06 Jun 2013 17:49:01 GMT
[#6325] using jinja2.TemplateNotFound for bad paths

Signed-off-by: Nicholas Bollweg (Nick) <nick.bollweg@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/ca90e5c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ca90e5c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ca90e5c7

Branch: refs/heads/master
Commit: ca90e5c761f9c500daae23b799cc1a44aeeeac25
Parents: cf0d391
Author: Nicholas Bollweg (Nick) <nick.bollweg@gmail.com>
Authored: Fri Mar 2 17:14:35 2012 -0500
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Tue Jun 4 20:51:31 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/package_path_loader.py |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ca90e5c7/Allura/allura/lib/package_path_loader.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/package_path_loader.py b/Allura/allura/lib/package_path_loader.py
index aee8e1a..fe3f4b9 100644
--- a/Allura/allura/lib/package_path_loader.py
+++ b/Allura/allura/lib/package_path_loader.py
@@ -43,7 +43,8 @@ For the examples, assume the following directory structure:
                    |- file.html     <- actual template
 
 To override the above example, a Tool implementer would
-add the following line to their Tool's setup.py:
+add the following line to their Tool's setup.py (assuming usage in Allura,
+with the default app_cfg):
 
     [allura.theme.override]
     newtool = newtool.app:NewToolApp
@@ -195,6 +196,7 @@ class PackagePathLoader(jinja2.BaseLoader):
         package, path = None, None
         src = None
         bits = template.split(':')
+
         if len(bits) == 2:
             # splitting out the Python module name from the template string...
             # the default allura behavior
@@ -206,14 +208,15 @@ class PackagePathLoader(jinja2.BaseLoader):
             path = bits[0]
             path_fragment = os.path.join(self.override_root, path)
         else:
-            raise Exception('malformed template path')
+            raise jinja2.TemplateNotFound(
+                'Malformed template path %s' % template)
 
         # look in all of the customized search locations...
         try:
             src = self.fs_loader.get_source(environment, path_fragment)
-        except Exception:
-            # no Tool implemented an override... not even sure if this will
-            # throw an error, but we're ready for it!
+        except jinja2.TemplateNotFound:
+            # ...this doesn't mean it's really not found... it's probably
+            # just specified in the Allura-normal manner
             pass
 
         # ...but if you don't find anything, fall back to the explicit package
@@ -221,11 +224,13 @@ class PackagePathLoader(jinja2.BaseLoader):
         if src is None and package is not None:
             # gets the absolute filename of the template
             filename = pkg_resources.resource_filename(package, path)
-            # get the filename relative to the fs root (/).. if this fails
-            # this error is not caught, so should get propagated normally
+            # get the filename relative to the root: (default '/').. if this
+            # fails this error is not caught, so should get propagated
+            # normally
             src = self.fs_loader.get_source(environment, filename)
         elif src is None:
-            raise Exception(('Template %s not found in search path ' +
+            raise jinja2.TemplateNotFound(
+                ('Template %s not found in search path ' +
                   'and no module specified') % (
                     path,
                   ))


Mime
View raw message