incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [4/4] git commit: [#6830] Let derived tools 'inherit' static resources from parent
Date Tue, 10 Dec 2013 02:07:34 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/6ccfafc9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/6ccfafc9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/6ccfafc9

Branch: refs/heads/tv/6830
Commit: 6ccfafc9205616c87097df38af46050da84a5133
Parents: 942f4c0
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Tue Dec 10 02:06:31 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue Dec 10 02:06:31 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/6ccfafc9/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