def test_storage_system_from_paste_config(): this_storage = storage.storage_system_from_paste_config( { 'somestorage_base_url': 'http://example.org/moodia/', 'somestorage_base_dir': '/tmp/', 'somestorage_garbage_arg': 'garbage_arg', 'garbage_arg': 'trash' }, 'somestorage') assert this_storage.base_url == 'http://example.org/moodia/' assert this_storage.base_dir == '/tmp/' assert this_storage.__class__ is storage.BasicFileStorage this_storage = storage.storage_system_from_paste_config( { 'somestorage_foobie': 'eiboof', 'somestorage_blech': 'hcelb', 'somestorage_garbage_arg': 'garbage_arg', 'garbage_arg': 'trash', 'somestorage_storage_class': 'mediagoblin.tests.test_storage:FakeStorageSystem' }, 'somestorage') assert this_storage.foobie == 'eiboof' assert this_storage.blech == 'hcelb' assert this_storage.__class__ is FakeStorageSystem
def paste_app_factory(global_config, **app_config): # Get the database connection connection = mongokit.Connection( app_config.get('db_host'), app_config.get('db_port')) # Set up the storage systems. public_store = storage.storage_system_from_paste_config( app_config, 'publicstore') queue_store = storage.storage_system_from_paste_config( app_config, 'queuestore') # Set up the staticdirect system if app_config.has_key('direct_remote_path'): staticdirector = staticdirect.RemoteStaticDirect( app_config['direct_remote_path'].strip()) elif app_config.has_key('direct_remote_paths'): direct_remote_path_lines = app_config[ 'direct_remote_paths'].strip().splitlines() staticdirector = staticdirect.MultiRemoteStaticDirect( dict([line.strip().split(' ', 1) for line in direct_remote_path_lines])) else: raise ImproperlyConfigured( "One of direct_remote_path or direct_remote_paths must be provided") setup_celery_from_config(app_config, global_config) mgoblin_app = MediaGoblinApp( connection, app_config.get('db_name', 'mediagoblin'), public_store=public_store, queue_store=queue_store, staticdirector=staticdirector, user_template_path=app_config.get('local_templates')) return mgoblin_app
def setup_self(setup_globals_func=setup_globals): """ 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'. 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'. Args: - 'setup_globals_func': this is for testing purposes only. Don't set this! """ mgoblin_conf_file, mgoblin_section = os.environ.get( 'MEDIAGOBLIN_CONFIG', 'mediagoblin.ini:app:mediagoblin').split(':', 1) 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()]) setup_celery_from_config(mgoblin_section, mgoblin_conf, settings_module=OUR_MODULENAME, set_environ=False) connection = mongokit.Connection(mgoblin_section.get('db_host'), mgoblin_section.get('db_port')) db = connection[mgoblin_section.get('db_name', 'mediagoblin')] models.register_models(connection) # 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') setup_globals_func(db_connection=connection, database=db, public_store=public_store, queue_store=queue_store)
def setup_self(setup_globals_func=setup_globals): """ 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'. 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'. Args: - 'setup_globals_func': this is for testing purposes only. Don't set this! """ mgoblin_conf_file, mgoblin_section = os.environ.get("MEDIAGOBLIN_CONFIG", "mediagoblin.ini:app:mediagoblin").split( ":", 1 ) 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()]) setup_celery_from_config(mgoblin_section, mgoblin_conf, settings_module=OUR_MODULENAME, set_environ=False) connection = mongokit.Connection(mgoblin_section.get("db_host"), mgoblin_section.get("db_port")) db = connection[mgoblin_section.get("db_name", "mediagoblin")] models.register_models(connection) # 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") setup_globals_func(db_connection=connection, database=db, public_store=public_store, queue_store=queue_store)
def test_storage_system_from_paste_config(): this_storage = storage.storage_system_from_paste_config( {'somestorage_base_url': 'http://example.org/moodia/', 'somestorage_base_dir': '/tmp/', 'somestorage_garbage_arg': 'garbage_arg', 'garbage_arg': 'trash'}, 'somestorage') assert this_storage.base_url == 'http://example.org/moodia/' assert this_storage.base_dir == '/tmp/' assert this_storage.__class__ is storage.BasicFileStorage this_storage = storage.storage_system_from_paste_config( {'somestorage_foobie': 'eiboof', 'somestorage_blech': 'hcelb', 'somestorage_garbage_arg': 'garbage_arg', 'garbage_arg': 'trash', 'somestorage_storage_class': 'mediagoblin.tests.test_storage:FakeStorageSystem'}, 'somestorage') assert this_storage.foobie == 'eiboof' assert this_storage.blech == 'hcelb' assert this_storage.__class__ is FakeStorageSystem
def paste_app_factory(global_config, **app_config): # Get the database connection connection = mongokit.Connection(app_config.get('db_host'), app_config.get('db_port')) # Set up the storage systems. public_store = storage.storage_system_from_paste_config( app_config, 'publicstore') queue_store = storage.storage_system_from_paste_config( app_config, 'queuestore') # Set up the staticdirect system if app_config.has_key('direct_remote_path'): staticdirector = staticdirect.RemoteStaticDirect( app_config['direct_remote_path'].strip()) elif app_config.has_key('direct_remote_paths'): direct_remote_path_lines = app_config['direct_remote_paths'].strip( ).splitlines() staticdirector = staticdirect.MultiRemoteStaticDirect( dict([ line.strip().split(' ', 1) for line in direct_remote_path_lines ])) else: raise ImproperlyConfigured( "One of direct_remote_path or direct_remote_paths must be provided" ) setup_celery_from_config(app_config, global_config) mgoblin_app = MediaGoblinApp( connection, app_config.get('db_name', 'mediagoblin'), public_store=public_store, queue_store=queue_store, staticdirector=staticdirector, user_template_path=app_config.get('local_templates')) return mgoblin_app