##// END OF EJS Templates
svn: split generate and write parts for easier usage in automation scripts.
marcink -
r3223:95dfd17a default
parent child Browse files
Show More
@@ -1,93 +1,97 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2018 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import codecs
22 22 import logging
23 23 import os
24 24 from pyramid.renderers import render
25 25
26 26 from rhodecode.events import trigger
27 27 from rhodecode.lib.utils import get_rhodecode_realm, get_rhodecode_base_path
28 28 from rhodecode.lib.utils2 import str2bool
29 29 from rhodecode.model.db import RepoGroup
30 30
31 31 from . import config_keys
32 32 from .events import ModDavSvnConfigChange
33 33
34 34
35 35 log = logging.getLogger(__name__)
36 36
37 37
38 def generate_mod_dav_svn_config(registry):
39 """
40 Generate the configuration file for use with subversion's mod_dav_svn
41 module. The configuration has to contain a <Location> block for each
42 available repository group because the mod_dav_svn module does not support
43 repositories organized in sub folders.
44 """
45 settings = registry.settings
46 use_ssl = str2bool(registry.settings['force_https'])
38 def write_mod_dav_svn_config(settings):
39 use_ssl = str2bool(settings['force_https'])
47 40
48 41 config = _render_mod_dav_svn_config(
49 42 use_ssl=use_ssl,
50 43 parent_path_root=get_rhodecode_base_path(),
51 44 list_parent_path=settings[config_keys.list_parent_path],
52 45 location_root=settings[config_keys.location_root],
53 46 repo_groups=RepoGroup.get_all_repo_groups(),
54 47 realm=get_rhodecode_realm(), template=settings[config_keys.template])
55 48 _write_mod_dav_svn_config(config, settings[config_keys.config_file_path])
56 49
50
51 def generate_mod_dav_svn_config(registry):
52 """
53 Generate the configuration file for use with subversion's mod_dav_svn
54 module. The configuration has to contain a <Location> block for each
55 available repository group because the mod_dav_svn module does not support
56 repositories organized in sub folders.
57 """
58 settings = registry.settings
59 write_mod_dav_svn_config(settings)
60
57 61 # Trigger an event on mod dav svn configuration change.
58 62 trigger(ModDavSvnConfigChange(), registry)
59 63
60 64
61 65 def _render_mod_dav_svn_config(
62 66 parent_path_root, list_parent_path, location_root, repo_groups, realm,
63 67 use_ssl, template):
64 68 """
65 69 Render mod_dav_svn configuration to string.
66 70 """
67 71 repo_group_paths = []
68 72 for repo_group in repo_groups:
69 73 group_path = repo_group.full_path_splitted
70 74 location = os.path.join(location_root, *group_path)
71 75 parent_path = os.path.join(parent_path_root, *group_path)
72 76 repo_group_paths.append((location, parent_path))
73 77
74 78 context = {
75 79 'location_root': location_root,
76 80 'parent_path_root': parent_path_root,
77 81 'repo_group_paths': repo_group_paths,
78 82 'svn_list_parent_path': list_parent_path,
79 83 'rhodecode_realm': realm,
80 84 'use_https': use_ssl,
81 85 }
82 86 template = template or \
83 87 'rhodecode:apps/svn_support/templates/mod-dav-svn.conf.mako'
84 88 # Render the configuration template to string.
85 89 return render(template, context)
86 90
87 91
88 92 def _write_mod_dav_svn_config(config, filepath):
89 93 """
90 94 Write mod_dav_svn config to file.
91 95 """
92 96 with codecs.open(filepath, 'w', encoding='utf-8') as f:
93 97 f.write(config)
General Comments 0
You need to be logged in to leave comments. Login now