Starting to deprecate the app_config, global_config by attaching stuff to app

- app.global_config, app.app_config
 - making setup_crypto use app.app_config
 - setting app.workbench_manager
This commit is contained in:
Christopher Allan Webber 2014-11-30 16:40:10 -06:00
parent a4768df0ca
commit b8e2ab2f55
3 changed files with 23 additions and 18 deletions

View File

@ -85,11 +85,11 @@ class MediaGoblinApp(object):
############## ##############
# Open and setup the config # Open and setup the config
global_config, app_config = setup_global_and_app_config(config_path) self.global_config, self.app_config = setup_global_and_app_config(config_path)
media_type_warning() media_type_warning()
setup_crypto() setup_crypto(self.app_config)
########################################## ##########################################
# Setup other connections / useful objects # Setup other connections / useful objects
@ -108,9 +108,9 @@ class MediaGoblinApp(object):
# Set up the database # Set up the database
if DISABLE_GLOBALS: if DISABLE_GLOBALS:
self.db_manager = setup_database(app_config['run_migrations']) self.db_manager = setup_database(self.app_config['run_migrations'])
else: else:
self.db = setup_database(app_config['run_migrations']) self.db = setup_database(self.app_config['run_migrations'])
# Quit app if need to run dbupdate # Quit app if need to run dbupdate
## NOTE: This is currently commented out due to session errors.. ## NOTE: This is currently commented out due to session errors..
@ -118,11 +118,11 @@ class MediaGoblinApp(object):
# check_db_up_to_date() # check_db_up_to_date()
# Register themes # Register themes
self.theme_registry, self.current_theme = register_themes(app_config) self.theme_registry, self.current_theme = register_themes(self.app_config)
# Get the template environment # Get the template environment
self.template_loader = get_jinja_loader( self.template_loader = get_jinja_loader(
app_config.get('local_templates'), self.app_config.get('local_templates'),
self.current_theme, self.current_theme,
PluginManager().get_template_paths() PluginManager().get_template_paths()
) )
@ -130,7 +130,7 @@ class MediaGoblinApp(object):
# Check if authentication plugin is enabled and respond accordingly. # Check if authentication plugin is enabled and respond accordingly.
self.auth = check_auth_enabled() self.auth = check_auth_enabled()
if not self.auth: if not self.auth:
app_config['allow_comments'] = False self.app_config['allow_comments'] = False
# Set up storage systems # Set up storage systems
self.public_store, self.queue_store = setup_storage() self.public_store, self.queue_store = setup_storage()
@ -139,16 +139,16 @@ class MediaGoblinApp(object):
self.url_map = get_url_map() self.url_map = get_url_map()
# set up staticdirector tool # set up staticdirector tool
self.staticdirector = get_staticdirector(app_config) self.staticdirector = get_staticdirector(self.app_config)
# Setup celery, if appropriate # Setup celery, if appropriate
if setup_celery and not app_config.get('celery_setup_elsewhere'): if setup_celery and not self.app_config.get('celery_setup_elsewhere'):
if os.environ.get('CELERY_ALWAYS_EAGER', 'false').lower() == 'true': if os.environ.get('CELERY_ALWAYS_EAGER', 'false').lower() == 'true':
setup_celery_from_config( setup_celery_from_config(
app_config, global_config, self.app_config, self.global_config,
force_celery_always_eager=True) force_celery_always_eager=True)
else: else:
setup_celery_from_config(app_config, global_config) setup_celery_from_config(self.app_config, self.global_config)
####################################################### #######################################################
# Insert appropriate things into mediagoblin.mg_globals # Insert appropriate things into mediagoblin.mg_globals
@ -167,14 +167,14 @@ class MediaGoblinApp(object):
# Workbench *currently* only used by celery, so this only # Workbench *currently* only used by celery, so this only
# matters in always eager mode :) # matters in always eager mode :)
setup_workbench() self.workbench_manager = setup_workbench()
# instantiate application meddleware # instantiate application meddleware
self.meddleware = [common.import_component(m)(self) self.meddleware = [common.import_component(m)(self)
for m in meddleware.ENABLED_MEDDLEWARE] for m in meddleware.ENABLED_MEDDLEWARE]
@contextmanager @contextmanager
def gen_context(self, ctx=None): def gen_context(self, ctx=None, **kwargs):
""" """
Attach contextual information to request, or generate a context object Attach contextual information to request, or generate a context object
@ -188,7 +188,7 @@ class MediaGoblinApp(object):
else: else:
yield self._gen_context(self.db, ctx) yield self._gen_context(self.db, ctx)
def _gen_context(self, db, ctx): def _gen_context(self, db, ctx, **kwargs):
# Set up context # Set up context
# -------------- # --------------

View File

@ -28,6 +28,8 @@ from mediagoblin.tools.pluginapi import hook_runall
from mediagoblin.tools.workbench import WorkbenchManager from mediagoblin.tools.workbench import WorkbenchManager
from mediagoblin.storage import storage_system_from_config from mediagoblin.storage import storage_system_from_config
from mediagoblin.tools.transition import DISABLE_GLOBALS
class Error(Exception): class Error(Exception):
pass pass
@ -154,4 +156,7 @@ def setup_workbench():
workbench_manager = WorkbenchManager(app_config['workbench_path']) workbench_manager = WorkbenchManager(app_config['workbench_path'])
setup_globals(workbench_manager=workbench_manager) if not DISABLE_GLOBALS:
setup_globals(workbench_manager=workbench_manager)
return workbench_manager

View File

@ -36,7 +36,7 @@ try:
except AttributeError: except AttributeError:
getrandbits = random.getrandbits getrandbits = random.getrandbits
# TODO: This should be attached to the MediaGoblinApp
__itsda_secret = None __itsda_secret = None
@ -73,9 +73,9 @@ def create_key(key_dir, key_filepath):
_log.info("Saved new key for It's Dangerous") _log.info("Saved new key for It's Dangerous")
def setup_crypto(): def setup_crypto(app_config):
global __itsda_secret global __itsda_secret
key_dir = mg_globals.app_config["crypto_path"] key_dir = app_config["crypto_path"]
key_filepath = os.path.join(key_dir, 'itsdangeroussecret.bin') key_filepath = os.path.join(key_dir, 'itsdangeroussecret.bin')
try: try:
load_key(key_filepath) load_key(key_filepath)