diff options
Diffstat (limited to 'mediagoblin/init')
-rw-r--r-- | mediagoblin/init/__init__.py | 25 | ||||
-rw-r--r-- | mediagoblin/init/celery/__init__.py | 3 | ||||
-rw-r--r-- | mediagoblin/init/celery/from_celery.py | 49 | ||||
-rw-r--r-- | mediagoblin/init/config.py | 42 | ||||
-rw-r--r-- | mediagoblin/init/plugins/__init__.py | 4 |
5 files changed, 59 insertions, 64 deletions
diff --git a/mediagoblin/init/__init__.py b/mediagoblin/init/__init__.py index 8d70c4ef..d16027db 100644 --- a/mediagoblin/init/__init__.py +++ b/mediagoblin/init/__init__.py @@ -14,8 +14,6 @@ # 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/>. -from beaker.cache import CacheManager -from beaker.util import parse_cache_config_options import jinja2 from mediagoblin.tools import staticdirect @@ -26,7 +24,7 @@ from mediagoblin import mg_globals from mediagoblin.mg_globals import setup_globals from mediagoblin.db.open import setup_connection_and_db_from_config, \ check_db_migrations_current, load_models -from mediagoblin.workbench import WorkbenchManager +from mediagoblin.tools.workbench import WorkbenchManager from mediagoblin.storage import storage_system_from_config @@ -66,15 +64,13 @@ def setup_database(): load_models(app_config) # Set up the database - connection, db = setup_connection_and_db_from_config(app_config) + db = setup_connection_and_db_from_config(app_config) check_db_migrations_current(db) - setup_globals( - db_connection=connection, - database=db) + setup_globals(database=db) - return connection, db + return db def get_jinja_loader(user_template_path=None, current_theme=None, @@ -148,16 +144,3 @@ def setup_workbench(): workbench_manager = WorkbenchManager(app_config['workbench_path']) setup_globals(workbench_manager=workbench_manager) - - -def setup_beaker_cache(): - """ - Setup the Beaker Cache manager. - """ - cache_config = mg_globals.global_config['beaker.cache'] - cache_config = dict( - [(u'cache.%s' % key, value) - for key, value in cache_config.iteritems()]) - cache = CacheManager(**parse_cache_config_options(cache_config)) - setup_globals(cache=cache) - return cache 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/config.py b/mediagoblin/init/config.py index ac4ab9bf..11a91cff 100644 --- a/mediagoblin/init/config.py +++ b/mediagoblin/init/config.py @@ -14,6 +14,7 @@ # 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 logging import os import pkg_resources @@ -21,6 +22,9 @@ from configobj import ConfigObj, flatten_errors from validate import Validator +_log = logging.getLogger(__name__) + + CONFIG_SPEC_PATH = pkg_resources.resource_filename( 'mediagoblin', 'config_spec.ini') @@ -42,6 +46,9 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH): Also provides %(__file__)s and %(here)s values of this file and its directory respectively similar to paste deploy. + Also reads for [plugins] section, appends all config_spec.ini + files from said plugins into the general config_spec specification. + This function doesn't itself raise any exceptions if validation fails, you'll have to do something @@ -57,10 +64,45 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH): """ config_path = os.path.abspath(config_path) + # PRE-READ of config file. This allows us to fetch the plugins so + # we can add their plugin specs to the general config_spec. + config = ConfigObj( + config_path, + interpolation='ConfigParser') + + plugins = config.get("plugins", {}).keys() + plugin_configs = {} + + for plugin in plugins: + try: + plugin_config_spec_path = pkg_resources.resource_filename( + plugin, "config_spec.ini") + if not os.path.exists(plugin_config_spec_path): + continue + + plugin_config_spec = ConfigObj( + plugin_config_spec_path, + encoding='UTF8', list_values=False, _inspec=True) + _setup_defaults(plugin_config_spec, config_path) + + if not "plugin_spec" in plugin_config_spec: + continue + + plugin_configs[plugin] = plugin_config_spec["plugin_spec"] + + except ImportError: + _log.warning( + "When setting up config section, could not import '%s'" % + plugin) + + # Now load the main config spec config_spec = ConfigObj( config_spec, encoding='UTF8', list_values=False, _inspec=True) + # append the plugin specific sections of the config spec + config_spec['plugins'] = plugin_configs + _setup_defaults(config_spec, config_path) config = ConfigObj( diff --git a/mediagoblin/init/plugins/__init__.py b/mediagoblin/init/plugins/__init__.py index cdf9b5ad..0df4f381 100644 --- a/mediagoblin/init/plugins/__init__.py +++ b/mediagoblin/init/plugins/__init__.py @@ -59,6 +59,4 @@ def setup_plugins(): pman.register_hooks(plugin.hooks) # Execute anything registered to the setup hook. - setup_list = pman.get_hook_callables('setup') - for fun in setup_list: - fun() + pluginapi.hook_runall('setup') |