Merge remote branch 'remotes/elrond/dev/storage_config'

This commit is contained in:
Christopher Allan Webber 2011-08-21 13:51:05 -05:00
commit bd3b566dbe
4 changed files with 32 additions and 29 deletions

View File

@ -1,7 +1,4 @@
[mediagoblin] [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/ direct_remote_path = /mgoblin_static/
email_sender_address = "notice@mediagoblin.example.org" email_sender_address = "notice@mediagoblin.example.org"
@ -14,5 +11,12 @@ allow_registration = true
## Uncomment this to put some user-overriding templates here ## Uncomment this to put some user-overriding templates here
#local_templates = %(here)s/user_dev/templates/ #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] [celery]
# Put celery stuff here # Put celery stuff here

View File

@ -4,15 +4,10 @@ db_host = string()
db_name = string(default="mediagoblin") db_name = string(default="mediagoblin")
db_port = integer() 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 # Where temporary files used in processing and etc are kept
workbench_path = string(default="%(here)s/user_dev/media/workbench") workbench_path = string(default="%(here)s/user_dev/media/workbench")
#
publicstore_base_url = string(default="/mgoblin_media/")
# Where mediagoblin-builtin static assets are kept # Where mediagoblin-builtin static assets are kept
direct_remote_path = string(default="/mgoblin_static/") direct_remote_path = string(default="/mgoblin_static/")
@ -37,6 +32,13 @@ local_templates = string()
# itself) # itself)
celery_setup_elsewhere = boolean(default=False) 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] [celery]
# known booleans # known booleans
celery_result_persistent = boolean() celery_result_persistent = boolean()

View File

@ -112,10 +112,15 @@ def get_staticdirector(app_config):
def setup_storage(): def setup_storage():
app_config = mg_globals.app_config global_config = mg_globals.global_config
public_store = storage_system_from_config(app_config, 'publicstore') key_short = 'publicstore'
queue_store = storage_system_from_config(app_config, 'queuestore') key_long = "storage:" + key_short
public_store = storage_system_from_config(global_config[key_long])
key_short = 'queuestore'
key_long = "storage:" + key_short
queue_store = storage_system_from_config(global_config[key_long])
setup_globals( setup_globals(
public_store = public_store, public_store = public_store,

View File

@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os import os
import re
import shutil import shutil
import urlparse import urlparse
import uuid import uuid
@ -456,41 +455,34 @@ def clean_listy_filepath(listy_filepath):
return cleaned_filepath return cleaned_filepath
def storage_system_from_config(paste_config, storage_prefix): def storage_system_from_config(config_section):
""" """
Utility for setting up a storage system from the paste app config. Utility for setting up a storage system from a config section.
Note that a special argument may be passed in to the paste_config Note that a special argument may be passed in to
which is "${storage_prefix}_storage_class" which will provide an the config_section which is "storage_class" which will provide an
import path to a storage system. This defaults to import path to a storage system. This defaults to
"mediagoblin.storage:BasicFileStorage" if otherwise undefined. "mediagoblin.storage:BasicFileStorage" if otherwise undefined.
Arguments: Arguments:
- paste_config: dictionary of config parameters - config_section: dictionary of config parameters
- storage_prefix: the storage system we're setting up / will be
getting keys/arguments from. For example 'publicstore' will
grab all arguments that are like 'publicstore_FOO'.
Returns: Returns:
An instantiated storage system. An instantiated storage system.
Example: Example:
storage_system_from_config( storage_system_from_config(
{'publicstore_base_url': '/media/', {'base_url': '/media/',
'publicstore_base_dir': '/var/whatever/media/'}, 'base_dir': '/var/whatever/media/'})
'publicstore')
Will return: Will return:
BasicFileStorage( BasicFileStorage(
base_url='/media/', base_url='/media/',
base_dir='/var/whatever/media') base_dir='/var/whatever/media')
""" """
prefix_re = re.compile('^%s_(.+)$' % re.escape(storage_prefix)) # This construct is needed, because dict(config) does
# not replace the variables in the config items.
config_params = dict( config_params = dict(config_section.iteritems())
[(prefix_re.match(key).groups()[0], value)
for key, value in paste_config.iteritems()
if prefix_re.match(key)])
if 'storage_class' in config_params: if 'storage_class' in config_params:
storage_class = config_params['storage_class'] storage_class = config_params['storage_class']