aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/init
diff options
context:
space:
mode:
authorBrandon Invergo <brandon@invergo.net>2013-05-19 13:23:17 +0200
committerBrandon Invergo <brandon@invergo.net>2013-05-19 13:23:17 +0200
commite02b7b6b3bd6b20c65aeb2ca5fd1e0030b631b88 (patch)
tree988b9505a649f824f2ea53ac04bdfbc3a0da983a /mediagoblin/init
parent60c42337ef7bc9b4aec0d3f1b2cb5f19a09d9a7f (diff)
parent041d2fd785f9b3e18f9fd758f91dbfa7715d317c (diff)
downloadmediagoblin-e02b7b6b3bd6b20c65aeb2ca5fd1e0030b631b88.tar.lz
mediagoblin-e02b7b6b3bd6b20c65aeb2ca5fd1e0030b631b88.tar.xz
mediagoblin-e02b7b6b3bd6b20c65aeb2ca5fd1e0030b631b88.zip
Merge branch 'master' of git://gitorious.org/mediagoblin/mediagoblin
Diffstat (limited to 'mediagoblin/init')
-rw-r--r--mediagoblin/init/__init__.py31
-rw-r--r--mediagoblin/init/celery/__init__.py3
-rw-r--r--mediagoblin/init/celery/from_celery.py49
-rw-r--r--mediagoblin/init/celery/from_tests.py33
-rw-r--r--mediagoblin/init/config.py42
-rw-r--r--mediagoblin/init/plugins/__init__.py4
6 files changed, 65 insertions, 97 deletions
diff --git a/mediagoblin/init/__init__.py b/mediagoblin/init/__init__.py
index 9b0025c9..d16027db 100644
--- a/mediagoblin/init/__init__.py
+++ b/mediagoblin/init/__init__.py
@@ -14,18 +14,17 @@
# 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
+from mediagoblin.tools.translate import set_available_locales
from mediagoblin.init.config import (
read_mediagoblin_config, generate_validation_report)
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
@@ -37,6 +36,11 @@ class ImproperlyConfigured(Error):
pass
+def setup_locales():
+ """Checks which language translations are available and sets them"""
+ set_available_locales()
+
+
def setup_global_and_app_config(config_path):
global_config, validation_result = read_mediagoblin_config(config_path)
app_config = global_config['mediagoblin']
@@ -60,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,
@@ -142,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/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
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')