incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [34/45] git commit: [#6830] Let derived tools 'inherit' static resources from parent
Date Fri, 13 Dec 2013 05:08:20 GMT
[#6830] Let derived tools 'inherit' static resources from parent

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@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/4aeceac3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/4aeceac3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/4aeceac3

Branch: refs/heads/tv/6942
Commit: 4aeceac3483f90ab06b31e25188d1fc99a150493
Parents: 6a47d3d
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Tue Dec 10 02:06:31 2013 +0000
Committer: Cory Johns <admin1@users.sf.net>
Committed: Thu Dec 12 17:55:08 2013 +0000

----------------------------------------------------------------------
 Allura/allura/config/resources.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4aeceac3/Allura/allura/config/resources.py
----------------------------------------------------------------------
diff --git a/Allura/allura/config/resources.py b/Allura/allura/config/resources.py
index 6e231e4..1f1ce53 100644
--- a/Allura/allura/config/resources.py
+++ b/Allura/allura/config/resources.py
@@ -20,6 +20,7 @@ import logging
 
 import pkg_resources
 
+from allura.app import Application
 from allura.lib.helpers import iter_entry_points
 
 log = logging.getLogger(__name__)
@@ -33,11 +34,22 @@ def register_ew_resources(manager):
         'allura', pkg_resources.resource_filename('allura', 'public/nf'))
     for ep in iter_entry_points('allura'):
         try:
+            # Allow derived tools to "inherit" static resources from a parent.
+            module_name = ep.module_name
+            resource_path = os.path.join('nf', ep.name.lower())
+            if not pkg_resources.resource_exists(module_name, resource_path):
+                for cls in [c for c in ep.load().__mro__[1:]
+                        if issubclass(c, Application)]:
+                    module_name = cls.__module__
+                    if pkg_resources.resource_exists(module_name, resource_path):
+                        break
+                else:
+                    continue
+
             manager.register_directory(
                 'tool/%s' % ep.name.lower(),
                 pkg_resources.resource_filename(
-                    ep.module_name,
-                    os.path.join('nf', ep.name.lower())))
+                    module_name, resource_path))
         except ImportError:
             log.warning('Cannot import entry point %s', ep)
             raise


Mime
View raw message