##// END OF EJS Templates
svn-support: Move try/catch block up to subscriber and also DB interaction.
Martin Bornhold -
r831:64e22267 default
parent child Browse files
Show More
@@ -1,31 +1,44 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2016 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 import logging
21 22
23 from rhodecode.model.settings import SettingsModel
22 24 from .utils import generate_mod_dav_svn_config
23 25
24 26
27 log = logging.getLogger(__name__)
28
29
25 30 def generate_config_subscriber(event):
26 31 """
27 32 Subscriber to the `rhodcode.events.RepoGroupEvent`. This triggers the
28 33 automatic generation of mod_dav_svn config file on repository group
29 34 changes.
30 35 """
31 generate_mod_dav_svn_config(event.request.registry.settings)
36 try:
37 parent_path_root = SettingsModel().get_ui_by_section_and_key(
38 'paths', '/').ui_value
39 generate_mod_dav_svn_config(
40 settings=event.request.registry.settings,
41 parent_path_root=parent_path_root)
42 except Exception:
43 log.exception(
44 'Exception while generating subversion mod_dav_svn configuration.')
@@ -1,88 +1,80 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2016 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
25 25 from pyramid.renderers import render
26 26
27 27 from rhodecode.lib.utils import get_rhodecode_realm
28 28 from rhodecode.model.db import RepoGroup
29 from rhodecode.model.settings import SettingsModel
30 29 from . import config_keys
31 30
32 31
33 32 log = logging.getLogger(__name__)
34 33
35 34
36 def generate_mod_dav_svn_config(settings):
35 def generate_mod_dav_svn_config(settings, parent_path_root):
37 36 """
38 37 Generate the configuration file for use with subversion's mod_dav_svn
39 38 module. The configuration has to contain a <Location> block for each
40 39 available repository group because the mod_dav_svn module does not support
41 40 repositories organized in sub folders.
42 41 """
43 parent_path_root = SettingsModel().get_ui_by_section_and_key(
44 'paths', '/').ui_value
45 42 config = _render_mod_dav_svn_config(
46 43 parent_path_root=parent_path_root,
47 44 list_parent_path=settings[config_keys.list_parent_path],
48 45 location_root=settings[config_keys.location_root],
49 46 repo_groups=RepoGroup.get_all_repo_groups())
50 47 _write_mod_dav_svn_config(config, settings[config_keys.config_file_path])
51 48
52 49
53 50 def _render_mod_dav_svn_config(
54 51 parent_path_root, list_parent_path, location_root, repo_groups):
55 52 """
56 53 Render mod_dav_svn configuration to string.
57 54 """
58 55 repo_group_paths = []
59 56 for repo_group in repo_groups:
60 57 group_path = repo_group.full_path_splitted
61 58 location = os.path.join(location_root, *group_path)
62 59 parent_path = os.path.join(parent_path_root, *group_path)
63 60 repo_group_paths.append((location, parent_path))
64 61
65 62 context = {
66 63 'location_root': location_root,
67 64 'parent_path_root': parent_path_root,
68 65 'repo_group_paths': repo_group_paths,
69 66 'svn_list_parent_path': list_parent_path,
70 67 'rhodecode_realm': get_rhodecode_realm(),
71 68 }
72 69
73 70 # Render the configuration template to string.
74 71 template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako'
75 72 return render(template, context)
76 73
77 74
78 75 def _write_mod_dav_svn_config(config, filepath):
79 76 """
80 Write mod_dav_svn config to file. Log on exceptions but do not raise.
77 Write mod_dav_svn config to file.
81 78 """
82 try:
83 79 with codecs.open(filepath, 'w', encoding='utf-8') as f:
84 80 f.write(config)
85 except Exception:
86 log.exception(
87 'Exception while writing mod_dav_svn configuration to '
88 '"%s"', filepath)
General Comments 0
You need to be logged in to leave comments. Login now