##// END OF EJS Templates
svn-support: Use repo root path from DB to generate mod-dav-svn config. Fixes #4203
Martin Bornhold -
r826:f17dcf57 default
parent child Browse files
Show More
@@ -1,28 +1,27 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2016 RhodeCode GmbH
3 # Copyright (C) 2016-2016 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21
21
22 # Definition of setting keys used to configure this module. Defined here to
22 # Definition of setting keys used to configure this module. Defined here to
23 # avoid repetition of keys throughout the module.
23 # avoid repetition of keys throughout the module.
24 config_file_path = 'svn.proxy.config_file_path'
24 config_file_path = 'svn.proxy.config_file_path'
25 generate_config = 'svn.proxy.generate_config'
25 generate_config = 'svn.proxy.generate_config'
26 list_parent_path = 'svn.proxy.list_parent_path'
26 list_parent_path = 'svn.proxy.list_parent_path'
27 location_root = 'svn.proxy.location_root'
27 location_root = 'svn.proxy.location_root'
28 parent_path_root = 'svn.proxy.parent_path_root'
@@ -1,83 +1,86 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2016 RhodeCode GmbH
3 # Copyright (C) 2016-2016 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import logging
21 import logging
22 import os
22 import os
23
23
24 from pyramid.renderers import render
24 from pyramid.renderers import render
25
25
26 from rhodecode.lib.utils import get_rhodecode_realm
26 from rhodecode.lib.utils import get_rhodecode_realm
27 from rhodecode.model.db import RepoGroup
27 from rhodecode.model.db import RepoGroup
28 from rhodecode.model.settings import SettingsModel
28 from . import config_keys
29 from . import config_keys
29
30
30
31
31 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
32
33
33
34
34 def generate_mod_dav_svn_config(settings):
35 def generate_mod_dav_svn_config(settings):
35 """
36 """
36 Generate the configuration file for use with subversion's mod_dav_svn
37 Generate the configuration file for use with subversion's mod_dav_svn
37 module. The configuration has to contain a <Location> block for each
38 module. The configuration has to contain a <Location> block for each
38 available repository group because the mod_dav_svn module does not support
39 available repository group because the mod_dav_svn module does not support
39 repositories organized in sub folders.
40 repositories organized in sub folders.
40 """
41 """
42 parent_path_root = SettingsModel().get_ui_by_section_and_key(
43 'paths', '/').ui_value
41 config = _render_mod_dav_svn_config(
44 config = _render_mod_dav_svn_config(
42 settings[config_keys.parent_path_root],
45 parent_path_root=parent_path_root,
43 settings[config_keys.list_parent_path],
46 list_parent_path=settings[config_keys.list_parent_path],
44 settings[config_keys.location_root],
47 localtion_root=settings[config_keys.location_root],
45 RepoGroup.get_all_repo_groups())
48 repo_groups=RepoGroup.get_all_repo_groups())
46 _write_mod_dav_svn_config(config, settings[config_keys.config_file_path])
49 _write_mod_dav_svn_config(config, settings[config_keys.config_file_path])
47
50
48
51
49 def _render_mod_dav_svn_config(
52 def _render_mod_dav_svn_config(
50 parent_path_root, list_parent_path, location_root, repo_groups):
53 parent_path_root, list_parent_path, location_root, repo_groups):
51 """
54 """
52 Render mod_dav_svn configuration to string.
55 Render mod_dav_svn configuration to string.
53 """
56 """
54 repo_group_paths = []
57 repo_group_paths = []
55 for repo_group in repo_groups:
58 for repo_group in repo_groups:
56 group_path = repo_group.full_path_splitted
59 group_path = repo_group.full_path_splitted
57 location = os.path.join(location_root, *group_path)
60 location = os.path.join(location_root, *group_path)
58 parent_path = os.path.join(parent_path_root, *group_path)
61 parent_path = os.path.join(parent_path_root, *group_path)
59 repo_group_paths.append((location, parent_path))
62 repo_group_paths.append((location, parent_path))
60
63
61 context = {
64 context = {
62 'location_root': location_root,
65 'location_root': location_root,
63 'parent_path_root': parent_path_root,
66 'parent_path_root': parent_path_root,
64 'repo_group_paths': repo_group_paths,
67 'repo_group_paths': repo_group_paths,
65 'svn_list_parent_path': list_parent_path,
68 'svn_list_parent_path': list_parent_path,
66 'rhodecode_realm': get_rhodecode_realm(),
69 'rhodecode_realm': get_rhodecode_realm(),
67 }
70 }
68
71
69 # Render the configuration template to string.
72 # Render the configuration template to string.
70 template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako'
73 template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako'
71 return render(template, context)
74 return render(template, context)
72
75
73
76
74 def _write_mod_dav_svn_config(config, filepath):
77 def _write_mod_dav_svn_config(config, filepath):
75 """
78 """
76 Write mod_dav_svn config to file. Log on exceptions but do not raise.
79 Write mod_dav_svn config to file. Log on exceptions but do not raise.
77 """
80 """
78 try:
81 try:
79 with open(filepath, 'w') as file_:
82 with open(filepath, 'w') as file_:
80 file_.write(config)
83 file_.write(config)
81 except Exception:
84 except Exception:
82 log.exception(
85 log.exception(
83 'Can not write mod_dav_svn configuration to "%s"', filepath)
86 'Can not write mod_dav_svn configuration to "%s"', filepath)
General Comments 0
You need to be logged in to leave comments. Login now