aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/celery_setup/from_celery.py
diff options
context:
space:
mode:
authorcfdv <caldavis@gmail.com>2011-06-19 17:39:32 -0500
committercfdv <caldavis@gmail.com>2011-06-19 17:39:32 -0500
commit0e66e6a6c6e60b8cc7c4ab1fc0c443c5b8234ada (patch)
tree7a0936a9a83f9f39a090f96e41a274ac77ddaee4 /mediagoblin/celery_setup/from_celery.py
parente8fda91bc2326911ea9a0197e595bc333540c282 (diff)
parent188240e312b8c5ff50bef276c97b36e5b3835f1e (diff)
downloadmediagoblin-0e66e6a6c6e60b8cc7c4ab1fc0c443c5b8234ada.tar.lz
mediagoblin-0e66e6a6c6e60b8cc7c4ab1fc0c443c5b8234ada.tar.xz
mediagoblin-0e66e6a6c6e60b8cc7c4ab1fc0c443c5b8234ada.zip
Merge branch 'is330', remote-tracking branch 'origin/master' into is330
Diffstat (limited to 'mediagoblin/celery_setup/from_celery.py')
-rw-r--r--mediagoblin/celery_setup/from_celery.py74
1 files changed, 18 insertions, 56 deletions
diff --git a/mediagoblin/celery_setup/from_celery.py b/mediagoblin/celery_setup/from_celery.py
index c8ccebc8..046aaa50 100644
--- a/mediagoblin/celery_setup/from_celery.py
+++ b/mediagoblin/celery_setup/from_celery.py
@@ -16,81 +16,43 @@
import os
-from paste.deploy.loadwsgi import NicerConfigParser
-from paste.deploy.converters import asbool
-
-from mediagoblin import storage
-from mediagoblin.db.open import setup_connection_and_db_from_config
+from mediagoblin import app, mg_globals
from mediagoblin.celery_setup import setup_celery_from_config
-from mediagoblin.mg_globals import setup_globals
-from mediagoblin.workbench import WorkbenchManager, DEFAULT_WORKBENCH_DIR
OUR_MODULENAME = __name__
-def setup_self():
+def setup_self(check_environ_for_conf=True, module_name=OUR_MODULENAME):
"""
Transform this module into a celery config module by reading the
mediagoblin config file. Set the environment variable
- MEDIAGOBLIN_CONFIG to specify where this config file is at and
- what section it uses.
-
- By default it defaults to 'mediagoblin.ini:app:mediagoblin'.
+ MEDIAGOBLIN_CONFIG to specify where this config file is.
- The first colon ":" is a delimiter between the filename and the
- config section, so in this case the filename is 'mediagoblin.ini'
- and the section where mediagoblin is defined is 'app:mediagoblin'.
+ By default it defaults to 'mediagoblin.ini'.
- Args:
- - 'setup_globals_func': this is for testing purposes only. Don't
- set this!
+ Note that if celery_setup_elsewhere is set in your config file,
+ this simply won't work.
"""
- mgoblin_conf_file, mgoblin_section = os.environ.get(
- 'MEDIAGOBLIN_CONFIG', 'mediagoblin.ini:app:mediagoblin').split(':', 1)
+ if check_environ_for_conf:
+ mgoblin_conf_file = os.path.abspath(
+ os.environ.get('MEDIAGOBLIN_CONFIG', 'mediagoblin.ini'))
+ else:
+ mgoblin_conf_file = 'mediagoblin.ini'
+
if not os.path.exists(mgoblin_conf_file):
raise IOError(
"MEDIAGOBLIN_CONFIG not set or file does not exist")
- parser = NicerConfigParser(mgoblin_conf_file)
- parser.read(mgoblin_conf_file)
- parser._defaults.setdefault(
- 'here', os.path.dirname(os.path.abspath(mgoblin_conf_file)))
- parser._defaults.setdefault(
- '__file__', os.path.abspath(mgoblin_conf_file))
-
- mgoblin_section = dict(parser.items(mgoblin_section))
- mgoblin_conf = dict(
- [(section_name, dict(parser.items(section_name)))
- for section_name in parser.sections()])
+ # By setting the environment variable here we should ensure that
+ # this is the module that gets set up.
+ os.environ['CELERY_CONFIG_MODULE'] = module_name
+ app.MediaGoblinApp(mgoblin_conf_file, setup_celery=False)
setup_celery_from_config(
- mgoblin_section, mgoblin_conf,
- settings_module=OUR_MODULENAME,
+ mg_globals.app_config, mg_globals.global_config,
+ settings_module=module_name,
set_environ=False)
- connection, db = setup_connection_and_db_from_config(mgoblin_section)
-
- # Set up the storage systems.
- public_store = storage.storage_system_from_paste_config(
- mgoblin_section, 'publicstore')
- queue_store = storage.storage_system_from_paste_config(
- mgoblin_section, 'queuestore')
-
- workbench_manager = WorkbenchManager(
- mgoblin_section.get(
- 'workbench_path', DEFAULT_WORKBENCH_DIR))
-
- setup_globals(
- db_connection=connection,
- database=db,
- public_store=public_store,
- email_debug_mode=asbool(mgoblin_section.get('email_debug_mode')),
- email_sender_address=mgoblin_section.get(
- 'email_sender_address',
- 'notice@mediagoblin.example.org'),
- queue_store=queue_store,
- workbench_manager=workbench_manager)
-
if os.environ['CELERY_CONFIG_MODULE'] == OUR_MODULENAME:
setup_self()