db: Move db setup code to seperate function.

This commit is contained in:
Johannes Bornhold 2016-06-07 17:17:28 +02:00
parent a9e7becc0e
commit ec516d16f1
2 changed files with 20 additions and 15 deletions

View file

@ -174,3 +174,19 @@ def _use_direct_hook_calls(config):
def _get_vcs_hooks_protocol(config): def _get_vcs_hooks_protocol(config):
protocol = config.get('vcs.hooks.protocol', 'pyro4').lower() protocol = config.get('vcs.hooks.protocol', 'pyro4').lower()
return protocol return protocol
def load_pyramid_environment(global_config, settings):
# Some parts of the code expect a merge of global and app settings.
settings_merged = global_config.copy()
settings_merged.update(settings)
# If this is a test run we prepare the test environment like
# creating a test database, test search index and test repositories.
# This has to be done before the database connection is initialized.
if settings['is_test']:
rhodecode.is_test = True
utils.initialize_test_environment(settings_merged)
# Initialize the database connection.
utils.initialize_database(settings_merged)

View file

@ -36,8 +36,9 @@ from routes.middleware import RoutesMiddleware
import routes.util import routes.util
import rhodecode import rhodecode
from rhodecode.config import patches, utils from rhodecode.config import patches
from rhodecode.config.environment import load_environment from rhodecode.config.environment import (
load_environment, load_pyramid_environment)
from rhodecode.lib.middleware import csrf from rhodecode.lib.middleware import csrf
from rhodecode.lib.middleware.appenlight import wrap_in_appenlight_if_enabled from rhodecode.lib.middleware.appenlight import wrap_in_appenlight_if_enabled
from rhodecode.lib.middleware.disable_vcs import DisableVCSPagesWrapper from rhodecode.lib.middleware.disable_vcs import DisableVCSPagesWrapper
@ -157,23 +158,11 @@ def make_pyramid_app(global_config, **settings):
# behavior in the old application. # behavior in the old application.
settings_pylons = settings.copy() settings_pylons = settings.copy()
# Some parts of the code expect a merge of global and app settings.
settings_merged = global_config.copy()
settings_merged.update(settings)
sanitize_settings_and_apply_defaults(settings) sanitize_settings_and_apply_defaults(settings)
config = Configurator(settings=settings) config = Configurator(settings=settings)
add_pylons_compat_data(config.registry, global_config, settings_pylons) add_pylons_compat_data(config.registry, global_config, settings_pylons)
# If this is a test run we prepare the test environment like load_pyramid_environment(global_config, settings)
# creating a test database, test search index and test repositories.
# This has to be done before the database connection is initialized.
if settings['is_test']:
rhodecode.is_test = True
utils.initialize_test_environment(settings_merged)
# Initialize the database connection.
utils.initialize_database(settings_merged)
includeme(config) includeme(config)
includeme_last(config) includeme_last(config)