diff options
Diffstat (limited to 'mediagoblin/init/celery')
-rw-r--r-- | mediagoblin/init/celery/__init__.py | 3 | ||||
-rw-r--r-- | mediagoblin/init/celery/from_celery.py | 49 | ||||
-rw-r--r-- | mediagoblin/init/celery/from_tests.py | 33 |
3 files changed, 12 insertions, 73 deletions
diff --git a/mediagoblin/init/celery/__init__.py b/mediagoblin/init/celery/__init__.py index fc595ea7..169cc935 100644 --- a/mediagoblin/init/celery/__init__.py +++ b/mediagoblin/init/celery/__init__.py @@ -18,6 +18,7 @@ import os import sys from celery import Celery +from mediagoblin.tools.pluginapi import hook_runall MANDATORY_CELERY_IMPORTS = ['mediagoblin.processing.task'] @@ -65,6 +66,8 @@ def setup_celery_app(app_config, global_config, celery_app = Celery() celery_app.config_from_object(celery_settings) + hook_runall('celery_setup', celery_app) + def setup_celery_from_config(app_config, global_config, settings_module=DEFAULT_SETTINGS_MODULE, diff --git a/mediagoblin/init/celery/from_celery.py b/mediagoblin/init/celery/from_celery.py index 41fffa45..b395a826 100644 --- a/mediagoblin/init/celery/from_celery.py +++ b/mediagoblin/init/celery/from_celery.py @@ -16,13 +16,13 @@ import os import logging +import logging.config -from configobj import ConfigObj -from ConfigParser import RawConfigParser 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 hook_runall OUR_MODULENAME = __name__ @@ -36,49 +36,18 @@ def setup_logging_from_paste_ini(loglevel, **kw): else: logging_conf_file = 'paste.ini' + # allow users to set up explicitly which paste file to check via the + # PASTE_CONFIG environment variable + logging_conf_file = os.environ.get( + 'PASTE_CONFIG', logging_conf_file) + if not os.path.exists(logging_conf_file): raise IOError('{0} does not exist. Logging can not be set up.'.format( logging_conf_file)) - logging_conf = ConfigObj(logging_conf_file) - - config = logging_conf - - # Read raw config to avoid interpolation of formatting parameters - raw_config = RawConfigParser() - raw_config.readfp(open(logging_conf_file)) - - # Set up formatting - # Get the format string and circumvent configobj interpolation of the value - fmt = raw_config.get('formatter_generic', 'format') - - # Create the formatter - formatter = logging.Formatter(fmt) - - # Check for config values - if not config.get('loggers') or not config['loggers'].get('keys'): - print('No loggers found') - return - - # Iterate all teh loggers.keys values - for name in config['loggers']['keys'].split(','): - if not config.get('logger_{0}'.format(name)): - continue - - log_params = config['logger_{0}'.format(name)] - - qualname = log_params['qualname'] if 'qualname' in log_params else name - - if qualname == 'root': - qualname = None - - logger = logging.getLogger(qualname) - - level = getattr(logging, log_params['level']) - logger.setLevel(level) + logging.config.fileConfig(logging_conf_file) - for handler in logger.handlers: - handler.setFormatter(formatter) + hook_runall('celery_logging_setup') setup_logging.connect(setup_logging_from_paste_ini) diff --git a/mediagoblin/init/celery/from_tests.py b/mediagoblin/init/celery/from_tests.py deleted file mode 100644 index 3149e1ba..00000000 --- a/mediagoblin/init/celery/from_tests.py +++ /dev/null @@ -1,33 +0,0 @@ -# GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -import os - -from mediagoblin.tests.tools import TEST_APP_CONFIG -from mediagoblin.init.celery.from_celery import setup_self - - -OUR_MODULENAME = __name__ -CELERY_SETUP = False - - -if os.environ.get('CELERY_CONFIG_MODULE') == OUR_MODULENAME: - if CELERY_SETUP: - pass - else: - setup_self(check_environ_for_conf=False, module_name=OUR_MODULENAME, - default_conf_file=TEST_APP_CONFIG) - CELERY_SETUP = True |