Storage Config: Use own section
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 31 Jul 2011 11:54:07 +0000 (13:54 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Tue, 9 Aug 2011 11:13:04 +0000 (13:13 +0200)
Instead of configuring storage X by parameters in the main
section "X_class = backend" and "X_param = value", use a
new section in the config: "[storage:X]" and use "class =
backend" and "param = value" there.

This is the beginning, it includes a try at being backward
compatible. But that try isn't really fully useful anyway.

mediagoblin.ini
mediagoblin/config_spec.ini
mediagoblin/init/__init__.py
mediagoblin/storage.py

index e889646abeb73824dd17aefa774e6b9ac35b06b1..c22d12d7b98fc27c608b07d73e2b2f934ae05077 100644 (file)
@@ -1,7 +1,4 @@
 [mediagoblin]
-queuestore_base_dir = %(here)s/user_dev/media/queue
-publicstore_base_dir = %(here)s/user_dev/media/public
-publicstore_base_url = /mgoblin_media/
 direct_remote_path = /mgoblin_static/
 email_sender_address = "notice@mediagoblin.example.org"
 
@@ -14,5 +11,12 @@ allow_registration = true
 ## Uncomment this to put some user-overriding templates here
 #local_templates = %(here)s/user_dev/templates/
 
+[storage:queuestore]
+base_dir = %(here)s/user_dev/media/queue
+
+[storage:publicstore]
+base_dir = %(here)s/user_dev/media/public
+base_url = /mgoblin_media/
+
 [celery]
 # Put celery stuff here
index bbc1f7d62545a292112fcf3487181a8d6002d24b..6e0d52b4b770e23db28f7bfda5a6b4009152f5f3 100644 (file)
@@ -4,15 +4,10 @@ db_host = string()
 db_name = string(default="mediagoblin")
 db_port = integer()
 
-# 
-queuestore_base_dir = string(default="%(here)s/user_dev/media/queue")
-publicstore_base_dir = string(default="%(here)s/user_dev/media/public")
 
 # Where temporary files used in processing and etc are kept
 workbench_path = string(default="%(here)s/user_dev/media/workbench")
 
-# 
-publicstore_base_url = string(default="/mgoblin_media/")
 
 # Where mediagoblin-builtin static assets are kept
 direct_remote_path = string(default="/mgoblin_static/")
@@ -37,6 +32,13 @@ local_templates = string()
 # itself)
 celery_setup_elsewhere = boolean(default=False)
 
+[storage:publicstore]
+base_dir = string(default="%(here)s/user_dev/media/public")
+base_url = string(default="/mgoblin_media/")
+
+[storage:queuestore]
+base_dir = string(default="%(here)s/user_dev/media/queue")
+
 [celery]
 # known booleans
 celery_result_persistent = boolean()
index ff005703053ffddead0f0c12af01d5dacd65384c..b87bd7a434ed98b8104d16428c10c0e500c2035f 100644 (file)
@@ -113,9 +113,23 @@ def get_staticdirector(app_config):
 
 def setup_storage():
     app_config = mg_globals.app_config
+    global_config = mg_globals.global_config
 
-    public_store = storage_system_from_config(app_config, 'publicstore')
-    queue_store = storage_system_from_config(app_config, 'queuestore')
+    key_short = 'publicstore'
+    key_long = "storage:" + key_short
+    if global_config.has_key(key_long):
+        print "New style"
+        public_store = storage_system_from_config(global_config[key_long], None)
+    else:
+        print "old style"
+        public_store = storage_system_from_config(app_config, key_short)
+
+    key_short = 'queuestore'
+    key_long = "storage:" + key_short
+    if global_config.has_key(key_long):
+        queue_store = storage_system_from_config(global_config[key_long], None)
+    else:
+        queue_store = storage_system_from_config(app_config, key_short)
 
     setup_globals(
         public_store = public_store,
index 88c748cecf532cb8873fd4651a29838738d83d6d..46a0c040355397e9ddf8a5367035d8f770dab448 100644 (file)
@@ -472,7 +472,10 @@ def storage_system_from_config(paste_config, storage_prefix):
            base_url='/media/',
            base_dir='/var/whatever/media')
     """
-    prefix_re = re.compile('^%s_(.+)$' % re.escape(storage_prefix))
+    if storage_prefix is not None:
+        prefix_re = re.compile('^%s_(.+)$' % re.escape(storage_prefix))
+    else:
+        prefix_re = re.compile('^(.+)$')
 
     config_params = dict(
         [(prefix_re.match(key).groups()[0], value)
@@ -485,5 +488,7 @@ def storage_system_from_config(paste_config, storage_prefix):
     else:
         storage_class = "mediagoblin.storage:BasicFileStorage"
 
+    print storage_class, repr(config_params)
+
     storage_class = util.import_component(storage_class)
     return storage_class(**config_params)