diff --git a/rhodecode/svn_support/__init__.py b/rhodecode/svn_support/__init__.py --- a/rhodecode/svn_support/__init__.py +++ b/rhodecode/svn_support/__init__.py @@ -23,8 +23,9 @@ import os from rhodecode import events from rhodecode.lib.utils2 import str2bool -from rhodecode.svn_support.subscribers import generate_mod_dav_svn_config -from rhodecode.svn_support import keys + +from .subscribers import generate_config_subscriber +from . import keys log = logging.getLogger(__name__) @@ -36,7 +37,7 @@ def includeme(config): if settings[keys.generate_config]: config.add_subscriber( - generate_mod_dav_svn_config, events.RepoGroupEvent) + generate_config_subscriber, events.RepoGroupEvent) def _sanitize_settings_and_apply_defaults(settings): diff --git a/rhodecode/svn_support/subscribers.py b/rhodecode/svn_support/subscribers.py --- a/rhodecode/svn_support/subscribers.py +++ b/rhodecode/svn_support/subscribers.py @@ -19,52 +19,13 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ -import logging - -from pyramid.renderers import render - -from rhodecode.model.db import RepoGroup -from rhodecode.svn_support import keys +from .utils import generate_mod_dav_svn_config -log = logging.getLogger(__name__) - - -def generate_mod_dav_svn_config(event): +def generate_config_subscriber(event): """ Subscriber to the `rhodcode.events.RepoGroupEvent`. This triggers the automatic generation of mod_dav_svn config file on repository group changes. """ - _generate(event.request.registry.settings) - - -def _generate(settings): - """ - Generate the configuration file for use with subversion's mod_dav_svn - module. The configuration has to contain a block for each - available repository group because the mod_dav_svn module does not support - repositories organized in sub folders. - - Currently this is only used by the subscriber above. If we extend this - to include it as API method and in the web interface this should be moved - to an appropriate place. - """ - filepath = settings[keys.config_file_path] - repository_root = settings[keys.parent_path_root] - list_parent_path = settings[keys.list_parent_path] - location_root = settings[keys.location_root] - - # Render the configuration to string. - template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako' - context = { - 'location_root': location_root, - 'repository_root': repository_root, - 'repo_groups': RepoGroup.get_all_repo_groups(), - 'svn_list_parent_path': list_parent_path, - } - mod_dav_svn_config = render(template, context) - - # Write configuration to file. - with open(filepath, 'w') as file_: - file_.write(mod_dav_svn_config) + generate_mod_dav_svn_config(event.request.registry.settings) diff --git a/rhodecode/svn_support/templates/mod-dav-svn.conf.mako b/rhodecode/svn_support/templates/mod-dav-svn.conf.mako --- a/rhodecode/svn_support/templates/mod-dav-svn.conf.mako +++ b/rhodecode/svn_support/templates/mod-dav-svn.conf.mako @@ -18,9 +18,9 @@ % for repo_group in repo_groups: - + DAV svn - SVNParentPath ${parent_path_root}${repo_group.full_path} + SVNParentPath ${parent_path_root_stripped}${repo_group.full_path} SVNListParentPath ${'On' if svn_list_parent_path else 'Off'} Allow from all Order allow,deny diff --git a/rhodecode/svn_support/utils.py b/rhodecode/svn_support/utils.py new file mode 100644 --- /dev/null +++ b/rhodecode/svn_support/utils.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2016-2016 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ + +import os + +from pyramid.renderers import render + +from rhodecode.model.db import RepoGroup +from . import keys + + +def generate_mod_dav_svn_config(settings): + """ + Generate the configuration file for use with subversion's mod_dav_svn + module. The configuration has to contain a block for each + available repository group because the mod_dav_svn module does not support + repositories organized in sub folders. + """ + filepath = settings[keys.config_file_path] + parent_path_root = settings[keys.parent_path_root] + list_parent_path = settings[keys.list_parent_path] + location_root = settings[keys.location_root] + + # Render the configuration to string. + template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako' + context = { + 'location_root': location_root, + 'location_root_stripped': location_root.rstrip(os.path.sep), + 'parent_path_root': parent_path_root, + 'parent_path_root_stripped': parent_path_root.rstrip(os.path.sep), + 'repo_groups': RepoGroup.get_all_repo_groups(), + 'svn_list_parent_path': list_parent_path, + } + mod_dav_svn_config = render(template, context) + + print mod_dav_svn_config + + # Write configuration to file. + with open(filepath, 'w') as file_: + file_.write(mod_dav_svn_config)