Move setting up of storage into init/__init__.py
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 17 Jul 2011 14:09:22 +0000 (16:09 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 18 Jul 2011 12:20:58 +0000 (14:20 +0200)
Factoring out this one should be the last one needed to
rewrite the celery setup. The idea is to not setup the
whole app, but just call a bunch of individual setup_*
functions and be done.

mediagoblin/app.py
mediagoblin/init/__init__.py

index 85c3c0c7c0d21c5c6252648e75603fd78b55a2e5..58db4e8db7023c0d163c73eb14bc2c28d97035cb 100644 (file)
@@ -20,11 +20,12 @@ import urllib
 import routes
 from webob import Request, exc
 
-from mediagoblin import routing, util, storage
+from mediagoblin import routing, util
 from mediagoblin.mg_globals import setup_globals
 from mediagoblin.init.celery import setup_celery_from_config
 from mediagoblin.init import get_jinja_loader, get_staticdirector, \
-    setup_global_and_app_config, setup_workbench, setup_database
+    setup_global_and_app_config, setup_workbench, setup_database, \
+    setup_storage
 
 
 class MediaGoblinApp(object):
@@ -62,10 +63,7 @@ class MediaGoblinApp(object):
             app_config.get('user_template_path'))
         
         # Set up storage systems
-        self.public_store = storage.storage_system_from_config(
-            app_config, 'publicstore')
-        self.queue_store = storage.storage_system_from_config(
-            app_config, 'queuestore')
+        self.public_store, self.queue_store = setup_storage()
 
         # set up routing
         self.routing = routing.get_mapper()
@@ -90,10 +88,7 @@ class MediaGoblinApp(object):
         # object.
         #######################################################
 
-        setup_globals(
-            app=self,
-            public_store=self.public_store,
-            queue_store=self.queue_store)
+        setup_globals(app = self)
 
         # Workbench *currently* only used by celery, so this only
         # matters in always eager mode :)
index 1e519cc9ca70004ad6aecf2640c782baaa23ba69..64fa9b9248e13e9c48d30a797262798d560906c0 100644 (file)
@@ -23,6 +23,7 @@ from mediagoblin.mg_globals import setup_globals
 from mediagoblin.db.open import setup_connection_and_db_from_config
 from mediagoblin.db.util import MigrationManager
 from mediagoblin.workbench import WorkbenchManager
+from mediagoblin.storage import storage_system_from_config
 
 
 class Error(Exception): pass
@@ -103,6 +104,19 @@ def get_staticdirector(app_config):
             "direct_remote_paths must be provided")
 
 
+def setup_storage():
+    app_config = mg_globals.app_config
+
+    public_store = storage_system_from_config(app_config, 'publicstore')
+    queue_store = storage_system_from_config(app_config, 'queuestore')
+
+    setup_globals(
+        public_store = public_store,
+        queue_store = queue_store)
+
+    return public_store, queue_store
+
+
 def setup_workbench():
     app_config = mg_globals.app_config