incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [02/29] git commit: [#6611] provide mechanism to disable any allura entry point
Date Thu, 12 Sep 2013 20:51:52 GMT
[#6611] provide mechanism to disable any allura entry point


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

Branch: refs/heads/tv/6457
Commit: 1581f299c20aa4babfa8a5a1f781625e49534346
Parents: 10cb90c
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Wed Aug 28 19:05:30 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Aug 28 19:05:38 2013 +0000

----------------------------------------------------------------------
 Allura/allura/command/base.py                    |  3 +--
 Allura/allura/config/resources.py                |  6 ++++--
 Allura/allura/controllers/project.py             |  4 ++--
 Allura/allura/ext/admin/admin_main.py            |  2 +-
 Allura/allura/lib/app_globals.py                 |  2 +-
 Allura/allura/lib/custom_middleware.py           |  4 ++--
 Allura/allura/lib/helpers.py                     | 12 +++++++++++-
 Allura/allura/lib/package_path_loader.py         |  7 +++----
 Allura/allura/model/auth.py                      |  1 -
 Allura/docs/extending.rst                        | 10 +++++++++-
 ForgeImporters/forgeimporters/base.py            | 10 ++++------
 ForgeImporters/forgeimporters/tests/test_base.py |  8 ++++----
 scripts/rethumb.py                               |  6 ++++--
 13 files changed, 46 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/Allura/allura/command/base.py
----------------------------------------------------------------------
diff --git a/Allura/allura/command/base.py b/Allura/allura/command/base.py
index 536159d..38bb0d5 100644
--- a/Allura/allura/command/base.py
+++ b/Allura/allura/command/base.py
@@ -20,7 +20,6 @@ import sys
 import logging
 import shlex
 from multiprocessing import Process
-from pkg_resources import iter_entry_points
 
 import pylons
 from paste.script import command
@@ -31,6 +30,7 @@ import activitystream
 import ming
 from allura.config.environment import load_environment
 from allura.lib.decorators import task
+from allura.lib.helpers import iter_entry_points
 
 log = None
 
@@ -117,4 +117,3 @@ class Command(command.Command):
 
     def teardown_globals(self):
         self.registry.cleanup()
-

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/Allura/allura/config/resources.py
----------------------------------------------------------------------
diff --git a/Allura/allura/config/resources.py b/Allura/allura/config/resources.py
index 9122687..6e231e4 100644
--- a/Allura/allura/config/resources.py
+++ b/Allura/allura/config/resources.py
@@ -20,6 +20,8 @@ import logging
 
 import pkg_resources
 
+from allura.lib.helpers import iter_entry_points
+
 log = logging.getLogger(__name__)
 
 def register_ew_resources(manager):
@@ -29,7 +31,7 @@ def register_ew_resources(manager):
         'css', pkg_resources.resource_filename('allura', 'lib/widgets/resources/css'))
     manager.register_directory(
         'allura', pkg_resources.resource_filename('allura', 'public/nf'))
-    for ep in pkg_resources.iter_entry_points('allura'):
+    for ep in iter_entry_points('allura'):
         try:
             manager.register_directory(
                 'tool/%s' % ep.name.lower(),
@@ -39,7 +41,7 @@ def register_ew_resources(manager):
         except ImportError:
             log.warning('Cannot import entry point %s', ep)
             raise
-    for ep in pkg_resources.iter_entry_points('allura.theme'):
+    for ep in iter_entry_points('allura.theme'):
         try:
             theme = ep.load()
             theme.register_ew_resources(manager, ep.name)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 5f293a6..9914dc9 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -20,7 +20,6 @@ import logging
 from datetime import datetime, timedelta
 from urllib import unquote
 from itertools import chain, islice
-from pkg_resources import iter_entry_points
 
 from bson import ObjectId
 from tg import expose, flash, redirect, validate, request, response, config
@@ -38,6 +37,7 @@ from allura import model as M
 from allura.app import SitemapEntry
 from allura.lib.base import WsgiDispatchController
 from allura.lib import helpers as h
+from allura.lib.helpers import iter_entry_points
 from allura.lib import utils
 from allura.lib.decorators import require_post
 from allura.controllers.error import ErrorController
@@ -310,7 +310,7 @@ class ProjectController(FeedController):
         for s in c.project.grouped_navbar_entries():
             entry = dict(name=s.label, url=s.url, icon=s.ui_icon, tool_name=s.tool_name)
             if s.children:
-                entry['children'] = [dict(name=child.label, url=child.url, icon=child.ui_icon,
tool_name=child.tool_name) 
+                entry['children'] = [dict(name=child.label, url=child.url, icon=child.ui_icon,
tool_name=child.tool_name)
                                     for child in s.children]
             menu.append(entry)
         return dict(menu=menu)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index 22bd228..314c3a9 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -292,7 +292,7 @@ class ProjectAdminController(BaseController):
                 '<input name="source_url">'
                 '<input type="submit">'
                 '</form>')
-        for ep in pkg_resources.iter_entry_points('allura', repo_type):
+        for ep in h.iter_entry_points('allura', repo_type):
             break
         if ep is None or source_url is None:
             raise exc.HTTPNotFound

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 7f45f69..276af63 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -178,7 +178,7 @@ class Globals(object):
         # Cache some loaded entry points
         def _cache_eps(section_name, dict_cls=dict):
             d = dict_cls()
-            for ep in pkg_resources.iter_entry_points(section_name):
+            for ep in h.iter_entry_points(section_name):
                 value = ep.load()
                 d[ep.name] = value
             return d

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/Allura/allura/lib/custom_middleware.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index 4458c48..d4652ab 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -35,7 +35,7 @@ import allura.model.repo
 log = logging.getLogger(__name__)
 
 
-tool_entry_points = list(pkg_resources.iter_entry_points('allura'))
+tool_entry_points = list(h.iter_entry_points('allura'))
 
 class StaticFilesMiddleware(object):
     '''Custom static file middleware
@@ -169,7 +169,7 @@ class SSLMiddleware(object):
         if not resp:
             resp = self.app
         return resp(environ, start_response)
-    
+
 class AlluraTimerMiddleware(TimerMiddleware):
     def timers(self):
         import genshi

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index b7b0060..3715de6 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -49,7 +49,7 @@ from tg.decorators import before_validate
 from formencode.variabledecode import variable_decode
 import formencode
 from jinja2 import Markup
-from paste.deploy.converters import asbool
+from paste.deploy.converters import asbool, aslist
 
 from webhelpers import date, feedgenerator, html, number, misc, text
 
@@ -984,3 +984,13 @@ def plain2markdown(text, preserve_multiple_spaces=False, has_html_entities=False
     text = re_angle_bracket_open.sub('&lt;', text)
     text = re_angle_bracket_close.sub('&gt;', text)
     return text
+
+
+def iter_entry_points(group, *a, **kw):
+    '''
+    yield entry points that have not been disabled in the config
+    '''
+    disabled = aslist(tg.config.get('disable_entry_points.' + group), sep=',')
+    for ep in pkg_resources.iter_entry_points(group, *a, **kw):
+        if ep.name not in disabled:
+            yield ep

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/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 9bee4c4..8272acf 100644
--- a/Allura/allura/lib/package_path_loader.py
+++ b/Allura/allura/lib/package_path_loader.py
@@ -124,12 +124,11 @@ The positioners are:
 """
 import pkg_resources
 import os
-from collections import defaultdict
 
 import jinja2
 from ming.utils import LazyProperty
 
-from allura.lib.helpers import topological_sort
+from allura.lib.helpers import topological_sort, iter_entry_points
 
 
 class PackagePathLoader(jinja2.BaseLoader):
@@ -163,7 +162,7 @@ class PackagePathLoader(jinja2.BaseLoader):
         paths = self.default_paths[:]  # copy default_paths
         paths[-1:0] = [  # insert all eps just before last item, by default
                 [ep.name, pkg_resources.resource_filename(ep.module_name, "")]
-                for ep in pkg_resources.iter_entry_points(self.override_entrypoint)
+                for ep in iter_entry_points(self.override_entrypoint)
             ]
         return paths
 
@@ -190,7 +189,7 @@ class PackagePathLoader(jinja2.BaseLoader):
         """
         order_rules = []
         replacement_rules = {}
-        for ep in pkg_resources.iter_entry_points(self.override_entrypoint):
+        for ep in iter_entry_points(self.override_entrypoint):
             for rule in getattr(ep.load(), 'template_path_rules', []):
                 if rule[0] == '>':
                     order_rules.append((ep.name, rule[1]))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index fb58ce9..b048ce6 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -28,7 +28,6 @@ from hashlib import sha256
 import uuid
 from pytz import timezone
 from datetime import timedelta, date, datetime, time
-from pkg_resources import iter_entry_points
 
 import iso8601
 import pymongo

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/Allura/docs/extending.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/extending.rst b/Allura/docs/extending.rst
index a430202..6a6abe0 100644
--- a/Allura/docs/extending.rst
+++ b/Allura/docs/extending.rst
@@ -37,7 +37,15 @@ The available extension points for Allura are:
 
 A listing of available 3rd-party extensions is at https://sourceforge.net/p/allura/wiki/Extensions/
 
-Other entry points are used to provider ``paster`` commands and ``easy_widget`` configuration.
+To disable any Allura entry point, simply add an entry in your ``.ini`` config file
+with names and values corresponding to entry points defined in any ``setup.py`` file.
+For example if you have ForgeImporter set up, but want to disable the google code importers::
+
+    disable_entry_points.allura.project_importers = google-code
+    disable_entry_points.allura.importers = google-code-tracker, google-code-repo
+
+Other entry points are used to provide ``paster`` commands and ``easy_widget`` configuration,
+which are not part of Allura but are used by Allura.
 
 
 Event Handlers

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index bdff43b..7f25e69 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -20,8 +20,6 @@ import urllib
 import urllib2
 from collections import defaultdict
 
-from pkg_resources import iter_entry_points
-
 from BeautifulSoup import BeautifulSoup
 from tg import expose, validate, flash, redirect, config
 from tg.decorators import with_trailing_slash
@@ -176,7 +174,7 @@ class ProjectImporter(BaseController):
         as this project importer.
         """
         tools = {}
-        for ep in iter_entry_points('allura.importers'):
+        for ep in h.iter_entry_points('allura.importers'):
             epv = ep.load()
             if epv.source == self.source:
                 tools[ep.name] = epv()
@@ -289,7 +287,7 @@ class ToolImporter(object):
         """
         Return a ToolImporter subclass instance given its entry-point name.
         """
-        for ep in iter_entry_points('allura.importers', name):
+        for ep in h.iter_entry_points('allura.importers', name):
             return ep.load()()
 
     @staticmethod
@@ -298,7 +296,7 @@ class ToolImporter(object):
         Return a ToolImporter subclass instance given its target_app class.
         """
         importers = {}
-        for ep in iter_entry_points('allura.importers'):
+        for ep in h.iter_entry_points('allura.importers'):
             importer = ep.load()
             if app in aslist(importer.target_app):
                 importers[ep.name] = importer()
@@ -370,7 +368,7 @@ class ProjectToolsImportController(object):
     def index(self, *a, **kw):
         importer_matrix = defaultdict(dict)
         tools_with_importers = set()
-        for ep in iter_entry_points('allura.importers'):
+        for ep in h.iter_entry_points('allura.importers'):
             importer = ep.load()
             for tool in aslist(importer.target_app):
                 tools_with_importers.add(tool.tool_label)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/ForgeImporters/forgeimporters/tests/test_base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py
index f1c93ad..92fb0cc 100644
--- a/ForgeImporters/forgeimporters/tests/test_base.py
+++ b/ForgeImporters/forgeimporters/tests/test_base.py
@@ -66,7 +66,7 @@ def ep(name, source=None, importer=None, **kw):
 
 
 class TestProjectImporter(TestCase):
-    @mock.patch.object(base, 'iter_entry_points')
+    @mock.patch.object(base.h, 'iter_entry_points')
     def test_tool_importers(self, iep):
         eps = iep.return_value = [ep('ep1', 'foo'), ep('ep2', 'bar'), ep('ep3', 'foo')]
         pi = base.ProjectImporter(mock.Mock(name='neighborhood'))
@@ -100,7 +100,7 @@ class TI3(base.ToolImporter):
 class TestToolImporter(TestCase):
 
 
-    @mock.patch.object(base, 'iter_entry_points')
+    @mock.patch.object(base.h, 'iter_entry_points')
     def test_by_name(self, iep):
         eps = iep.return_value = [ep('my-name', 'my-source')]
         importer = base.ToolImporter.by_name('my-name')
@@ -113,7 +113,7 @@ class TestToolImporter(TestCase):
         iep.assert_called_once_with('allura.importers', 'other-name')
         self.assertEqual(importer, None)
 
-    @mock.patch.object(base, 'iter_entry_points')
+    @mock.patch.object(base.h, 'iter_entry_points')
     def test_by_app(self, iep):
         eps = iep.return_value = [
                 ep('importer1', importer=TI1),
@@ -190,7 +190,7 @@ class TestProjectToolsImportController(TestController):
 
     def test_pages(self):
         admin_page = self.app.get('/admin/')
-        with mock.patch.object(base, 'iter_entry_points') as iep:
+        with mock.patch.object(base.h, 'iter_entry_points') as iep:
             iep.return_value = [
                 ep('importer1', importer=TI1),
                 ep('importer2', importer=TI2),

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1581f299/scripts/rethumb.py
----------------------------------------------------------------------
diff --git a/scripts/rethumb.py b/scripts/rethumb.py
index 5f753ff..6ee190a 100644
--- a/scripts/rethumb.py
+++ b/scripts/rethumb.py
@@ -18,14 +18,16 @@
 import sys
 import time
 
-import pkg_resources
 import PIL
 import tg
 from pylons import tmpl_context as c
 from paste.deploy.converters import asint
 
 from ming.orm import mapper, ThreadLocalORMSession, session, state, Mapper
+
 from allura.command import base
+from allura.lib.helpers import iter_entry_points
+
 import forgetracker.model
 
 
@@ -109,7 +111,7 @@ class RethumbCommand(base.Command):
                 self.process_att_of_type(M.DiscussionAttachment, {'app_config_id': app._id,
'discussion_id': {'$ne': None}})
 
                 # Otherwise, we'll take attachment classes belonging to app's package
-                ep = pkg_resources.iter_entry_points('allura', app.tool_name).next()
+                ep = iter_entry_points('allura', app.tool_name).next()
                 app_package = ep.module_name.split('.', 1)[0]
                 if app_package == 'allura':
                     # Apps in allura known to not define own attachment types


Mime
View raw message