Show More
@@ -0,0 +1,69 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | # Copyright (C) 2016-2016 RhodeCode GmbH | |||
|
4 | # | |||
|
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 | |||
|
7 | # (only), as published by the Free Software Foundation. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
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/>. | |||
|
16 | # | |||
|
17 | # This program is dual-licensed. If you wish to learn more about the | |||
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |||
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |||
|
20 | ||||
|
21 | import logging | |||
|
22 | import os | |||
|
23 | ||||
|
24 | from rhodecode import events | |||
|
25 | from rhodecode.lib.utils2 import str2bool | |||
|
26 | from rhodecode.svn_support.subscribers import generate_mod_dav_svn_config | |||
|
27 | from rhodecode.svn_support import keys | |||
|
28 | ||||
|
29 | ||||
|
30 | log = logging.getLogger(__name__) | |||
|
31 | ||||
|
32 | ||||
|
33 | def includeme(config): | |||
|
34 | settings = config.registry.settings | |||
|
35 | _sanitize_settings_and_apply_defaults(settings) | |||
|
36 | ||||
|
37 | if settings[keys.generate_config]: | |||
|
38 | log.error('Add subscriber') | |||
|
39 | config.add_subscriber( | |||
|
40 | generate_mod_dav_svn_config, events.RepoGroupEvent) | |||
|
41 | ||||
|
42 | ||||
|
43 | def _sanitize_settings_and_apply_defaults(settings): | |||
|
44 | # Convert bool settings from string to bool. | |||
|
45 | settings[keys.generate_config] = str2bool( | |||
|
46 | settings.get(keys.generate_config, 'false')) | |||
|
47 | settings[keys.list_parent_path] = str2bool( | |||
|
48 | settings.get(keys.list_parent_path, 'true')) | |||
|
49 | ||||
|
50 | # Set defaults if key not present. | |||
|
51 | settings.setdefault(keys.config_file_path, None) | |||
|
52 | settings.setdefault(keys.location_root, '/') | |||
|
53 | settings.setdefault(keys.parent_path_root, None) | |||
|
54 | ||||
|
55 | # Append path separator to paths. | |||
|
56 | settings[keys.location_root] = _append_slash( | |||
|
57 | settings[keys.location_root]) | |||
|
58 | settings[keys.parent_path_root] = _append_slash( | |||
|
59 | settings[keys.parent_path_root]) | |||
|
60 | ||||
|
61 | # Validate settings. | |||
|
62 | if settings[keys.generate_config]: | |||
|
63 | assert settings[keys.config_file_path] is not None | |||
|
64 | ||||
|
65 | ||||
|
66 | def _append_slash(path): | |||
|
67 | if isinstance(path, basestring) and not path.endswith(os.path.sep): | |||
|
68 | path += os.path.sep | |||
|
69 | return path |
@@ -0,0 +1,27 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | # Copyright (C) 2016-2016 RhodeCode GmbH | |||
|
4 | # | |||
|
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 | |||
|
7 | # (only), as published by the Free Software Foundation. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
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/>. | |||
|
16 | # | |||
|
17 | # This program is dual-licensed. If you wish to learn more about the | |||
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |||
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |||
|
20 | ||||
|
21 | ||||
|
22 | # Settings keys used in the ini file. | |||
|
23 | config_file_path = 'svn.proxy.config_file_path' | |||
|
24 | generate_config = 'svn.proxy.generate_config' | |||
|
25 | list_parent_path = 'svn.proxy.list_parent_path' | |||
|
26 | location_root = 'svn.proxy.location_root' | |||
|
27 | parent_path_root = 'svn.proxy.parent_path_root' |
@@ -0,0 +1,56 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | # Copyright (C) 2016-2016 RhodeCode GmbH | |||
|
4 | # | |||
|
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 | |||
|
7 | # (only), as published by the Free Software Foundation. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
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/>. | |||
|
16 | # | |||
|
17 | # This program is dual-licensed. If you wish to learn more about the | |||
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |||
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |||
|
20 | ||||
|
21 | ||||
|
22 | import logging | |||
|
23 | ||||
|
24 | from pyramid.renderers import render | |||
|
25 | ||||
|
26 | from rhodecode.model.db import RepoGroup | |||
|
27 | from rhodecode.svn_support import keys | |||
|
28 | ||||
|
29 | ||||
|
30 | log = logging.getLogger(__name__) | |||
|
31 | ||||
|
32 | ||||
|
33 | def generate_mod_dav_svn_config(event): | |||
|
34 | _generate(event.request) | |||
|
35 | ||||
|
36 | ||||
|
37 | def _generate(request): | |||
|
38 | settings = request.registry.settings | |||
|
39 | filepath = settings[keys.config_file_path] | |||
|
40 | repository_root = settings[keys.parent_path_root] | |||
|
41 | list_parent_path = settings[keys.list_parent_path] | |||
|
42 | location_root = settings[keys.location_root] | |||
|
43 | ||||
|
44 | # Render the configuration to string. | |||
|
45 | template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako' | |||
|
46 | context = { | |||
|
47 | 'location_root': location_root, | |||
|
48 | 'repository_root': repository_root, | |||
|
49 | 'repo_groups': RepoGroup.get_all_repo_groups(), | |||
|
50 | 'svn_list_parent_path': list_parent_path, | |||
|
51 | } | |||
|
52 | mod_dav_svn_config = render(template, context) | |||
|
53 | ||||
|
54 | # Write configuration to file. | |||
|
55 | with open(filepath, 'w') as file_: | |||
|
56 | file_.write(mod_dav_svn_config) |
General Comments 0
You need to be logged in to leave comments.
Login now