def setup_database(app): app_config = app.app_config global_config = app.global_config run_migrations = app_config['run_migrations'] # Load all models for media types (plugins, ...) load_models(app_config) # Set up the database db = setup_connection_and_db_from_config(app_config, run_migrations, app=app) # run_migrations is used for tests if run_migrations: # Run the migrations to initialize/update the database. # We only run the alembic migrations in the case of unit # tests, in which case we don't need to run the legacy # migrations. from mediagoblin.gmg_commands.dbupdate import (run_alembic_migrations, run_foundations) run_alembic_migrations(db, app_config, global_config) run_foundations(db, global_config) else: check_db_migrations_current(db) setup_globals(database=db) return db
def setup_database(app): app_config = app.app_config global_config = app.global_config run_migrations = app_config['run_migrations'] # Load all models for media types (plugins, ...) load_models(app_config) # Set up the database db = setup_connection_and_db_from_config( app_config, run_migrations, app=app) # run_migrations is used for tests if run_migrations: # Run the migrations to initialize/update the database. # We only run the alembic migrations in the case of unit # tests, in which case we don't need to run the legacy # migrations. from mediagoblin.gmg_commands.dbupdate import ( run_alembic_migrations, run_foundations) run_alembic_migrations(db, app_config, global_config) run_foundations(db, global_config) else: check_db_migrations_current(db) setup_globals(database=db) return db
def setup_workbench(): app_config = mg_globals.app_config workbench_manager = WorkbenchManager(app_config["workbench_path"]) if not DISABLE_GLOBALS: setup_globals(workbench_manager=workbench_manager) return workbench_manager
def setup_workbench(): app_config = mg_globals.app_config workbench_manager = WorkbenchManager(app_config['workbench_path']) if not DISABLE_GLOBALS: setup_globals(workbench_manager=workbench_manager) return workbench_manager
def setup_global_and_app_config(config_path): global_config, validation_result = read_mediagoblin_config(config_path) app_config = global_config["mediagoblin"] # report errors if necessary validation_report = generate_validation_report(global_config, validation_result) if validation_report: raise ImproperlyConfigured(validation_report) setup_globals(app_config=app_config, global_config=global_config) return global_config, app_config
def setup_beaker_cache(): """ Setup the Beaker Cache manager. """ cache_config = mg_globals.global_config['beaker.cache'] cache_config = dict( [(u'cache.%s' % key, value) for key, value in cache_config.iteritems()]) cache = CacheManager(**parse_cache_config_options(cache_config)) setup_globals(cache=cache) return cache
def test_setup_globals(self): mg_globals.setup_globals(database='my favorite database!', public_store='my favorite public_store!', queue_store='my favorite queue_store!') assert mg_globals.database == 'my favorite database!' assert mg_globals.public_store == 'my favorite public_store!' assert mg_globals.queue_store == 'my favorite queue_store!' pytest.raises(AssertionError, mg_globals.setup_globals, no_such_global_foo="Dummy")
def setup_global_and_app_config(config_path): global_config, validation_result = read_mediagoblin_config(config_path) app_config = global_config['mediagoblin'] # report errors if necessary validation_report = generate_validation_report(global_config, validation_result) if validation_report: raise ImproperlyConfigured(validation_report) setup_globals(app_config=app_config, global_config=global_config) return global_config, app_config
def test_workbench_decorator(self): """Test @get_workbench decorator and automatic cleanup""" # The decorator needs mg_globals.workbench_manager setup_globals(workbench_manager=self.workbench_manager) @get_workbench def create_it(workbench=None): # workbench dir exists? assert os.path.isdir(workbench.dir) return workbench.dir benchdir = create_it() # workbench dir has been cleaned up automatically? assert not os.path.isdir(benchdir)
def setup_database(): app_config = mg_globals.app_config # Load all models for media types (plugins, ...) load_models(app_config) # Set up the database db = setup_connection_and_db_from_config(app_config) check_db_migrations_current(db) setup_globals(database=db) return db
def test_setup_globals(self): mg_globals.setup_globals( database='my favorite database!', public_store='my favorite public_store!', queue_store='my favorite queue_store!') assert mg_globals.database == 'my favorite database!' assert mg_globals.public_store == 'my favorite public_store!' assert mg_globals.queue_store == 'my favorite queue_store!' pytest.raises( AssertionError, mg_globals.setup_globals, no_such_global_foo="Dummy")
def setup_storage(): global_config = mg_globals.global_config key_short = "publicstore" 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(public_store=public_store, queue_store=queue_store) return public_store, queue_store
def setup_storage(): global_config = mg_globals.global_config key_short = 'publicstore' 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(public_store=public_store, queue_store=queue_store) return public_store, queue_store
def setup_database(run_migrations=False): app_config = mg_globals.app_config global_config = mg_globals.global_config # Load all models for media types (plugins, ...) load_models(app_config) # Set up the database db = setup_connection_and_db_from_config(app_config, run_migrations) if run_migrations: #Run the migrations to initialize/update the database. from mediagoblin.gmg_commands.dbupdate import run_all_migrations run_all_migrations(db, app_config, global_config) else: check_db_migrations_current(db) setup_globals(database=db) return db
def setup_gettext(locale): """ Setup the gettext instance based on this locale """ # Later on when we have plugins we may want to enable the # multi-translations system they have so we can handle plugin # translations too # TODO: fallback nicely on translations from pt_PT to pt if not # available, etc. if SETUP_GETTEXTS.has_key(locale): this_gettext = SETUP_GETTEXTS[locale] else: this_gettext = gettext.translation( 'mediagoblin', TRANSLATIONS_PATH, [locale], fallback=True) if exists(locale): SETUP_GETTEXTS[locale] = this_gettext mg_globals.setup_globals( translations=this_gettext)
def __init__(self, config_path, setup_celery=True): """ Initialize the application based on a configuration file. Arguments: - config_path: path to the configuration file we're opening. - setup_celery: whether or not to setup celery during init. (Note: setting 'celery_setup_elsewhere' also disables setting up celery.) """ _log.info("GNU MediaGoblin %s main server starting", __version__) _log.debug("Using config file %s", config_path) ############## # Setup config ############## # Open and setup the config global_config, app_config = setup_global_and_app_config(config_path) media_type_warning() setup_crypto() ########################################## # Setup other connections / useful objects ########################################## # Setup Session Manager, not needed in celery self.session_manager = session.SessionManager() # load all available locales setup_locales() # Set up plugins -- need to do this early so that plugins can # affect startup. _log.info("Setting up plugins.") setup_plugins() # Set up the database self.db = setup_database(app_config['run_migrations']) # Quit app if need to run dbupdate check_db_up_to_date() # Register themes self.theme_registry, self.current_theme = register_themes(app_config) # Get the template environment self.template_loader = get_jinja_loader( app_config.get('local_templates'), self.current_theme, PluginManager().get_template_paths() ) # Check if authentication plugin is enabled and respond accordingly. self.auth = check_auth_enabled() if not self.auth: app_config['allow_comments'] = False # Set up storage systems self.public_store, self.queue_store = setup_storage() # set up routing self.url_map = get_url_map() # set up staticdirector tool self.staticdirector = get_staticdirector(app_config) # Setup celery, if appropriate if setup_celery and not app_config.get('celery_setup_elsewhere'): if os.environ.get('CELERY_ALWAYS_EAGER', 'false').lower() == 'true': setup_celery_from_config( app_config, global_config, force_celery_always_eager=True) else: setup_celery_from_config(app_config, global_config) ####################################################### # Insert appropriate things into mediagoblin.mg_globals # # certain properties need to be accessed globally eg from # validators, etc, which might not access to the request # object. ####################################################### setup_globals(app=self) # Workbench *currently* only used by celery, so this only # matters in always eager mode :) setup_workbench() # instantiate application meddleware self.meddleware = [common.import_component(m)(self) for m in meddleware.ENABLED_MEDDLEWARE]
def setup_workbench(): app_config = mg_globals.app_config workbench_manager = WorkbenchManager(app_config['workbench_path']) setup_globals(workbench_manager=workbench_manager)
def __init__(self, config_path, setup_celery=True): """ Initialize the application based on a configuration file. Arguments: - config_path: path to the configuration file we're opening. - setup_celery: whether or not to setup celery during init. (Note: setting 'celery_setup_elsewhere' also disables setting up celery.) """ ############## # Setup config ############## # Open and setup the config global_config, validation_result = read_mediagoblin_config(config_path) app_config = global_config['mediagoblin'] # report errors if necessary validation_report = generate_validation_report(global_config, validation_result) if validation_report: raise ImproperlyConfigured(validation_report) ########################################## # Setup other connections / useful objects ########################################## # Set up the database self.connection, self.db = setup_connection_and_db_from_config( app_config) # Get the template environment self.template_loader = util.get_jinja_loader( 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') # set up routing self.routing = routing.get_mapper() # set up staticdirector tool if app_config.has_key('direct_remote_path'): self.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() self.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, if appropriate if setup_celery and not app_config.get('celery_setup_elsewhere'): if os.environ.get('CELERY_ALWAYS_EAGER'): setup_celery_from_config(app_config, global_config, force_celery_always_eager=True) else: setup_celery_from_config(app_config, global_config) ####################################################### # Insert appropriate things into mediagoblin.mg_globals # # certain properties need to be accessed globally eg from # validators, etc, which might not access to the request # object. ####################################################### setup_globals( app_config=app_config, global_config=global_config, # TODO: No need to set these two up as globals, we could # just read them out of mg_globals.app_config email_sender_address=app_config['email_sender_address'], email_debug_mode=app_config['email_debug_mode'], # Actual, useful to everyone objects app=self, db_connection=self.connection, database=self.db, public_store=self.public_store, queue_store=self.queue_store, workbench_manager=WorkbenchManager(app_config['workbench_path']))
def __init__(self, config_path, setup_celery=True): """ Initialize the application based on a configuration file. Arguments: - config_path: path to the configuration file we're opening. - setup_celery: whether or not to setup celery during init. (Note: setting 'celery_setup_elsewhere' also disables setting up celery.) """ ############## # Setup config ############## # Open and setup the config global_config, validation_result = read_mediagoblin_config(config_path) app_config = global_config['mediagoblin'] # report errors if necessary validation_report = generate_validation_report( global_config, validation_result) if validation_report: raise ImproperlyConfigured(validation_report) ########################################## # Setup other connections / useful objects ########################################## # Set up the database self.connection, self.db = setup_connection_and_db_from_config( app_config) # Get the template environment self.template_loader = util.get_jinja_loader( 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') # set up routing self.routing = routing.get_mapper() # set up staticdirector tool if app_config.has_key('direct_remote_path'): self.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() self.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, if appropriate if setup_celery and not app_config.get('celery_setup_elsewhere'): if os.environ.get('CELERY_ALWAYS_EAGER'): setup_celery_from_config( app_config, global_config, force_celery_always_eager=True) else: setup_celery_from_config(app_config, global_config) ####################################################### # Insert appropriate things into mediagoblin.mg_globals # # certain properties need to be accessed globally eg from # validators, etc, which might not access to the request # object. ####################################################### setup_globals( app_config=app_config, global_config=global_config, # TODO: No need to set these two up as globals, we could # just read them out of mg_globals.app_config email_sender_address=app_config['email_sender_address'], email_debug_mode=app_config['email_debug_mode'], # Actual, useful to everyone objects app=self, db_connection=self.connection, database=self.db, public_store=self.public_store, queue_store=self.queue_store, workbench_manager=WorkbenchManager(app_config['workbench_path']))