diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 7edf9bd..f639e14 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -68,7 +68,7 @@ def create_tables(db_url, alembic_ini=None, acls=None, debug=False): else: engine = create_engine(db_url, echo=debug, client_encoding='utf8') - from pagure.ui.plugins import get_plugin_tables + from pagure.lib.plugins import get_plugin_tables get_plugin_tables() BASE.metadata.create_all(engine) # engine.execute(collection_package_create_view(driver=engine.driver)) diff --git a/pagure/lib/plugins.py b/pagure/lib/plugins.py new file mode 100644 index 0000000..84c281c --- /dev/null +++ b/pagure/lib/plugins.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +""" + (c) 2016 - Copyright Red Hat Inc + + Authors: + Pierre-Yves Chibon + +""" + +from straight.plugin import load + +from pagure.lib.model import BASE + + +def get_plugin_names(blacklist=None): + ''' Return the list of plugins names. ''' + from pagure.hooks import BaseHook + plugins = load('pagure.hooks', subclasses=BaseHook) + if not blacklist: + blacklist = [] + elif not isinstance(blacklist, list): + blacklist = [blacklist] + + output = [ + plugin.name + for plugin in plugins + if plugin.name not in blacklist + ] + # The default hook is not one we show + if 'default' in output: + output.remove('default') + return sorted(output) + + +def get_plugin_tables(): + ''' Return the list of all plugins. ''' + plugins = load('pagure.hooks', subclasses=BASE) + return plugins + + +def get_plugin(plugin_name): + ''' Return the list of plugins names. ''' + from pagure.hooks import BaseHook + plugins = load('pagure.hooks', subclasses=BaseHook) + for plugin in plugins: + if plugin.name == plugin_name: + return plugin diff --git a/pagure/ui/plugins.py b/pagure/ui/plugins.py index 0f0dc63..b6bf3b2 100644 --- a/pagure/ui/plugins.py +++ b/pagure/ui/plugins.py @@ -14,50 +14,15 @@ import flask from sqlalchemy.exc import SQLAlchemyError -from straight.plugin import load -from pagure.hooks import BaseHook import pagure.exceptions import pagure.lib +import pagure.lib.plugins import pagure.forms from pagure import APP, SESSION, login_required -from pagure.lib.model import BASE from pagure.exceptions import FileNotFoundException -def get_plugin_names(blacklist=None): - ''' Return the list of plugins names. ''' - plugins = load('pagure.hooks', subclasses=BaseHook) - if not blacklist: - blacklist = [] - elif not isinstance(blacklist, list): - blacklist = [blacklist] - - output = [ - plugin.name - for plugin in plugins - if plugin.name not in blacklist - ] - # The default hook is not one we show - if 'default' in output: - output.remove('default') - return sorted(output) - - -def get_plugin_tables(): - ''' Return the list of all plugins. ''' - plugins = load('pagure.hooks', subclasses=BASE) - return plugins - - -def get_plugin(plugin_name): - ''' Return the list of plugins names. ''' - plugins = load('pagure.hooks', subclasses=BaseHook) - for plugin in plugins: - if plugin.name == plugin_name: - return plugin - - @APP.route('//settings//', methods=('GET', 'POST')) @APP.route('//settings/', methods=('GET', 'POST')) @APP.route('///settings//', methods=('GET', 'POST')) @@ -112,7 +77,7 @@ def view_plugin(repo, plugin, username=None, namespace=None, full=True): if plugin in APP.config.get('DISABLED_PLUGINS', []): flask.abort(404, 'Plugin disabled') - plugin = get_plugin(plugin) + plugin = pagure.lib.plugins.get_plugin(plugin) fields = [] new = True dbobj = plugin.db_object() diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index c857a4a..f68584a 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -44,6 +44,7 @@ from binaryornot.helpers import is_binary_string import pagure.exceptions import pagure.lib import pagure.lib.git +import pagure.lib.plugins import pagure.forms import pagure import pagure.ui.plugins @@ -939,7 +940,7 @@ def view_settings(repo, username=None, namespace=None): 403, 'You are not allowed to change the settings for this project') - plugins = pagure.ui.plugins.get_plugin_names( + plugins = pagure.lib.plugins.get_plugin_names( APP.config.get('DISABLED_PLUGINS')) tags = pagure.lib.get_tags_of_project(SESSION, repo) diff --git a/tests/test_pagure_flask_ui_plugins.py b/tests/test_pagure_flask_ui_plugins.py index 4c2e2aa..4546bf1 100644 --- a/tests/test_pagure_flask_ui_plugins.py +++ b/tests/test_pagure_flask_ui_plugins.py @@ -25,8 +25,8 @@ sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) import pagure.lib +import pagure.lib.plugins import pagure.hooks -import pagure.ui.plugins import tests @@ -66,7 +66,7 @@ class PagureFlaskPluginstests(tests.Modeltests): def test_get_plugin_names(self): """ Test the get_plugin_names function. """ - names = pagure.ui.plugins.get_plugin_names() + names = pagure.lib.plugins.get_plugin_names() self.assertEqual( sorted(names), [ @@ -78,7 +78,7 @@ class PagureFlaskPluginstests(tests.Modeltests): def test_get_plugin(self): """ Test the get_plugin function. """ - name = pagure.ui.plugins.get_plugin('Mail') + name = pagure.lib.plugins.get_plugin('Mail') self.assertEqual(str(name), "") def test_view_plugin_page(self):