# HG changeset patch # User Martin Bornhold # Date 2016-08-05 15:01:00 # Node ID b2c504dedcdad9d66e869baeaaac7d69be20b043 # Parent ecb16d2d63bae45bd88ec32ecb6b6c5f1eb816a6 config: Move initial repo scan up to the pyramid layer. It is now subscribed to the ApplicationCreated event from pyramid. diff --git a/rhodecode/config/environment.py b/rhodecode/config/environment.py --- a/rhodecode/config/environment.py +++ b/rhodecode/config/environment.py @@ -165,9 +165,6 @@ def load_environment(global_conf, app_co if vcs_server_enabled: connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(config)) - import_on_startup = str2bool(config.get('startup.import_repos', False)) - if vcs_server_enabled and import_on_startup: - repo2db_mapper(ScmModel().repo_scan(repos_path), remove_obsolete=False) return config diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -34,6 +34,7 @@ from pyramid.settings import asbool, asl from pyramid.wsgi import wsgiapp from pyramid.httpexceptions import HTTPError, HTTPInternalServerError from pylons.controllers.util import abort, redirect +from pyramid.events import ApplicationCreated import pyramid.httpexceptions as httpexceptions from pyramid.renderers import render_to_response, render from routes.middleware import RoutesMiddleware @@ -51,6 +52,7 @@ from rhodecode.lib.middleware.disable_vc from rhodecode.lib.middleware.https_fixup import HttpsFixup from rhodecode.lib.middleware.vcs import VCSMiddleware from rhodecode.lib.plugins.utils import register_rhodecode_plugin +from rhodecode.subscribers import scan_repositories_if_enabled log = logging.getLogger(__name__) @@ -257,6 +259,9 @@ def includeme(config): config.add_route( 'rhodecode_support', 'https://rhodecode.com/help/', static=True) + # Add subscribers. + config.add_subscriber(scan_repositories_if_enabled, ApplicationCreated) + # Set the authorization policy. authz_policy = ACLAuthorizationPolicy() config.set_authorization_policy(authz_policy) diff --git a/rhodecode/subscribers.py b/rhodecode/subscribers.py --- a/rhodecode/subscribers.py +++ b/rhodecode/subscribers.py @@ -53,3 +53,18 @@ def add_localizer(event): request.localizer = localizer request.translate = auto_translate + + +def scan_repositories_if_enabled(event): + """ + This is subscribed to the `pyramid.events.ApplicationCreated` event. It + does a repository scan if enabled in the settings. + """ + from rhodecode.model.scm import ScmModel + from rhodecode.lib.utils import repo2db_mapper, get_rhodecode_base_path + settings = event.app.registry.settings + vcs_server_enabled = settings['vcs.server.enable'] + import_on_startup = settings['startup.import_repos'] + if vcs_server_enabled and import_on_startup: + repositories = ScmModel().repo_scan(get_rhodecode_base_path()) + repo2db_mapper(repositories, remove_obsolete=False)