diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-04-19 16:51:14 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-04-19 16:51:14 -0500 |
commit | c5d8d30182731f8e689574e096f663dcf665360d (patch) | |
tree | 3ebe448eaaced8253004b28d601e05e5a293df9f | |
parent | 97e0a79f394c00d6837a97ad7f55cb4c36a8d930 (diff) | |
download | mediagoblin-c5d8d30182731f8e689574e096f663dcf665360d.tar.lz mediagoblin-c5d8d30182731f8e689574e096f663dcf665360d.tar.xz mediagoblin-c5d8d30182731f8e689574e096f663dcf665360d.zip |
removing old callable utilities and porting stuff over.
-rw-r--r-- | mediagoblin/app.py | 6 | ||||
-rw-r--r-- | mediagoblin/init/celery/__init__.py | 4 | ||||
-rw-r--r-- | mediagoblin/init/celery/from_celery.py | 4 | ||||
-rw-r--r-- | mediagoblin/init/plugins/__init__.py | 2 | ||||
-rw-r--r-- | mediagoblin/tools/pluginapi.py | 68 |
5 files changed, 8 insertions, 76 deletions
diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 2c88e916..bf0e0f13 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -35,7 +35,7 @@ from mediagoblin.init.plugins import setup_plugins from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_global_and_app_config, setup_locales, setup_workbench, setup_database, setup_storage) -from mediagoblin.tools.pluginapi import PluginManager +from mediagoblin.tools.pluginapi import PluginManager, hook_transform from mediagoblin.tools.crypto import setup_crypto @@ -259,8 +259,6 @@ def paste_app_factory(global_config, **app_config): raise IOError("Usable mediagoblin config not found.") mgoblin_app = MediaGoblinApp(mediagoblin_config) - - for callable_hook in PluginManager().get_hook_callables('wrap_wsgi'): - mgoblin_app = callable_hook(mgoblin_app) + mgoblin_app = hook_transform('wrap_wsgi', mgoblin_app) return mgoblin_app diff --git a/mediagoblin/init/celery/__init__.py b/mediagoblin/init/celery/__init__.py index bb0d5989..169cc935 100644 --- a/mediagoblin/init/celery/__init__.py +++ b/mediagoblin/init/celery/__init__.py @@ -18,7 +18,7 @@ import os import sys from celery import Celery -from mediagoblin.tools.pluginapi import callable_runall +from mediagoblin.tools.pluginapi import hook_runall MANDATORY_CELERY_IMPORTS = ['mediagoblin.processing.task'] @@ -66,7 +66,7 @@ def setup_celery_app(app_config, global_config, celery_app = Celery() celery_app.config_from_object(celery_settings) - callable_runall('celery_setup', celery_app) + hook_runall('celery_setup', celery_app) def setup_celery_from_config(app_config, global_config, diff --git a/mediagoblin/init/celery/from_celery.py b/mediagoblin/init/celery/from_celery.py index e2899c0b..b395a826 100644 --- a/mediagoblin/init/celery/from_celery.py +++ b/mediagoblin/init/celery/from_celery.py @@ -22,7 +22,7 @@ from celery.signals import setup_logging from mediagoblin import app, mg_globals from mediagoblin.init.celery import setup_celery_from_config -from mediagoblin.tools.pluginapi import callable_runall +from mediagoblin.tools.pluginapi import hook_runall OUR_MODULENAME = __name__ @@ -47,7 +47,7 @@ def setup_logging_from_paste_ini(loglevel, **kw): logging.config.fileConfig(logging_conf_file) - callable_runall('celery_logging_setup') + hook_runall('celery_logging_setup') setup_logging.connect(setup_logging_from_paste_ini) diff --git a/mediagoblin/init/plugins/__init__.py b/mediagoblin/init/plugins/__init__.py index 72bd5c7d..0df4f381 100644 --- a/mediagoblin/init/plugins/__init__.py +++ b/mediagoblin/init/plugins/__init__.py @@ -59,4 +59,4 @@ def setup_plugins(): pman.register_hooks(plugin.hooks) # Execute anything registered to the setup hook. - pluginapi.callable_runall('setup') + pluginapi.hook_runall('setup') diff --git a/mediagoblin/tools/pluginapi.py b/mediagoblin/tools/pluginapi.py index ab90ed55..3f98aa8a 100644 --- a/mediagoblin/tools/pluginapi.py +++ b/mediagoblin/tools/pluginapi.py @@ -274,73 +274,7 @@ def get_hook_templates(hook_name): return PluginManager().get_template_hooks(hook_name) -########################### -# Callable convenience code -########################### - -class CantHandleIt(Exception): - """ - A callable may call this method if they look at the relevant - arguments passed and decide it's not possible for them to handle - things. - """ - pass - -class UnhandledCallable(Exception): - """ - Raise this method if no callables were available to handle the - specified hook. Only used by callable_runone. - """ - pass - - -def callable_runone(hookname, *args, **kwargs): - """ - Run the callable hook HOOKNAME... run until the first response, - then return. - - This function will run stop at the first hook that handles the - result. Hooks raising CantHandleIt will be skipped. - - Unless unhandled_okay is True, this will error out if no hooks - have been registered to handle this function. - """ - callables = PluginManager().get_hook_callables(hookname) - - unhandled_okay = kwargs.pop("unhandled_okay", False) - - for callable in callables: - try: - return callable(*args, **kwargs) - except CantHandleIt: - continue - - if unhandled_okay is False: - raise UnhandledCallable( - "No hooks registered capable of handling '%s'" % hookname) - - -def callable_runall(hookname, *args, **kwargs): - """ - Run all callables for HOOKNAME. - - This method will run *all* hooks that handle this method (skipping - those that raise CantHandleIt), and will return a list of all - results. - """ - callables = PluginManager().get_hook_callables(hookname) - - results = [] - - for callable in callables: - try: - results.append(callable(*args, **kwargs)) - except CantHandleIt: - continue - - return results - - +############################# ## Hooks: The Next Generation ############################# |