Show More
@@ -0,0 +1,57 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 os | |
|
22 | ||
|
23 | from pyramid.renderers import render | |
|
24 | ||
|
25 | from rhodecode.model.db import RepoGroup | |
|
26 | from . import keys | |
|
27 | ||
|
28 | ||
|
29 | def generate_mod_dav_svn_config(settings): | |
|
30 | """ | |
|
31 | Generate the configuration file for use with subversion's mod_dav_svn | |
|
32 | module. The configuration has to contain a <Location> block for each | |
|
33 | available repository group because the mod_dav_svn module does not support | |
|
34 | repositories organized in sub folders. | |
|
35 | """ | |
|
36 | filepath = settings[keys.config_file_path] | |
|
37 | parent_path_root = settings[keys.parent_path_root] | |
|
38 | list_parent_path = settings[keys.list_parent_path] | |
|
39 | location_root = settings[keys.location_root] | |
|
40 | ||
|
41 | # Render the configuration to string. | |
|
42 | template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako' | |
|
43 | context = { | |
|
44 | 'location_root': location_root, | |
|
45 | 'location_root_stripped': location_root.rstrip(os.path.sep), | |
|
46 | 'parent_path_root': parent_path_root, | |
|
47 | 'parent_path_root_stripped': parent_path_root.rstrip(os.path.sep), | |
|
48 | 'repo_groups': RepoGroup.get_all_repo_groups(), | |
|
49 | 'svn_list_parent_path': list_parent_path, | |
|
50 | } | |
|
51 | mod_dav_svn_config = render(template, context) | |
|
52 | ||
|
53 | print mod_dav_svn_config | |
|
54 | ||
|
55 | # Write configuration to file. | |
|
56 | with open(filepath, 'w') as file_: | |
|
57 | file_.write(mod_dav_svn_config) |
@@ -1,74 +1,75 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 logging |
|
22 | 22 | import os |
|
23 | 23 | |
|
24 | 24 | from rhodecode import events |
|
25 | 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 | |
|
26 | ||
|
27 | from .subscribers import generate_config_subscriber | |
|
28 | from . import keys | |
|
28 | 29 | |
|
29 | 30 | |
|
30 | 31 | log = logging.getLogger(__name__) |
|
31 | 32 | |
|
32 | 33 | |
|
33 | 34 | def includeme(config): |
|
34 | 35 | settings = config.registry.settings |
|
35 | 36 | _sanitize_settings_and_apply_defaults(settings) |
|
36 | 37 | |
|
37 | 38 | if settings[keys.generate_config]: |
|
38 | 39 | config.add_subscriber( |
|
39 |
generate_ |
|
|
40 | generate_config_subscriber, events.RepoGroupEvent) | |
|
40 | 41 | |
|
41 | 42 | |
|
42 | 43 | def _sanitize_settings_and_apply_defaults(settings): |
|
43 | 44 | """ |
|
44 | 45 | Set defaults, convert to python types and validate settings. |
|
45 | 46 | """ |
|
46 | 47 | # Convert bool settings from string to bool. |
|
47 | 48 | settings[keys.generate_config] = str2bool( |
|
48 | 49 | settings.get(keys.generate_config, 'false')) |
|
49 | 50 | settings[keys.list_parent_path] = str2bool( |
|
50 | 51 | settings.get(keys.list_parent_path, 'true')) |
|
51 | 52 | |
|
52 | 53 | # Set defaults if key not present. |
|
53 | 54 | settings.setdefault(keys.config_file_path, None) |
|
54 | 55 | settings.setdefault(keys.location_root, '/') |
|
55 | 56 | settings.setdefault(keys.parent_path_root, None) |
|
56 | 57 | |
|
57 | 58 | # Append path separator to paths. |
|
58 | 59 | settings[keys.location_root] = _append_path_sep( |
|
59 | 60 | settings[keys.location_root]) |
|
60 | 61 | settings[keys.parent_path_root] = _append_path_sep( |
|
61 | 62 | settings[keys.parent_path_root]) |
|
62 | 63 | |
|
63 | 64 | # Validate settings. |
|
64 | 65 | if settings[keys.generate_config]: |
|
65 | 66 | assert settings[keys.config_file_path] is not None |
|
66 | 67 | |
|
67 | 68 | |
|
68 | 69 | def _append_path_sep(path): |
|
69 | 70 | """ |
|
70 | 71 | Append the path separator if missing. |
|
71 | 72 | """ |
|
72 | 73 | if isinstance(path, basestring) and not path.endswith(os.path.sep): |
|
73 | 74 | path += os.path.sep |
|
74 | 75 | return path |
@@ -1,70 +1,31 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 | |
|
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 | |
|
22 | from .utils import generate_mod_dav_svn_config | |
|
28 | 23 | |
|
29 | 24 | |
|
30 | log = logging.getLogger(__name__) | |
|
31 | ||
|
32 | ||
|
33 | def generate_mod_dav_svn_config(event): | |
|
25 | def generate_config_subscriber(event): | |
|
34 | 26 | """ |
|
35 | 27 | Subscriber to the `rhodcode.events.RepoGroupEvent`. This triggers the |
|
36 | 28 | automatic generation of mod_dav_svn config file on repository group |
|
37 | 29 | changes. |
|
38 | 30 | """ |
|
39 |
|
|
|
40 | ||
|
41 | ||
|
42 | def _generate(settings): | |
|
43 | """ | |
|
44 | Generate the configuration file for use with subversion's mod_dav_svn | |
|
45 | module. The configuration has to contain a <Location> block for each | |
|
46 | available repository group because the mod_dav_svn module does not support | |
|
47 | repositories organized in sub folders. | |
|
48 | ||
|
49 | Currently this is only used by the subscriber above. If we extend this | |
|
50 | to include it as API method and in the web interface this should be moved | |
|
51 | to an appropriate place. | |
|
52 | """ | |
|
53 | filepath = settings[keys.config_file_path] | |
|
54 | repository_root = settings[keys.parent_path_root] | |
|
55 | list_parent_path = settings[keys.list_parent_path] | |
|
56 | location_root = settings[keys.location_root] | |
|
57 | ||
|
58 | # Render the configuration to string. | |
|
59 | template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako' | |
|
60 | context = { | |
|
61 | 'location_root': location_root, | |
|
62 | 'repository_root': repository_root, | |
|
63 | 'repo_groups': RepoGroup.get_all_repo_groups(), | |
|
64 | 'svn_list_parent_path': list_parent_path, | |
|
65 | } | |
|
66 | mod_dav_svn_config = render(template, context) | |
|
67 | ||
|
68 | # Write configuration to file. | |
|
69 | with open(filepath, 'w') as file_: | |
|
70 | file_.write(mod_dav_svn_config) | |
|
31 | generate_mod_dav_svn_config(event.request.registry.settings) |
@@ -1,28 +1,28 b'' | |||
|
1 | 1 | # Auto generated configuration for use with the Apache mod_dav_svn module. |
|
2 | 2 | |
|
3 | 3 | # The mod_dav_svn module does not support subversion repositories which are |
|
4 | 4 | # organized in subfolders. To support the repository groups of RhodeCode it is |
|
5 | 5 | # required to provide a <Location> block for each group pointing to the |
|
6 | 6 | # repository group sub folder. |
|
7 | 7 | |
|
8 | 8 | # To ease the configuration RhodeCode auto generates this file whenever a |
|
9 | 9 | # repository group is created/changed/deleted. Auto generation can be configured |
|
10 | 10 | # in the ini file. |
|
11 | 11 | |
|
12 | 12 | <Location ${location_root}> |
|
13 | 13 | DAV svn |
|
14 | 14 | SVNParentPath ${parent_path_root} |
|
15 | 15 | SVNListParentPath ${'On' if svn_list_parent_path else 'Off'} |
|
16 | 16 | Allow from all |
|
17 | 17 | Order allow,deny |
|
18 | 18 | </Location> |
|
19 | 19 | |
|
20 | 20 | % for repo_group in repo_groups: |
|
21 | <Location ${location_root}${repo_group.full_path}> | |
|
21 | <Location ${location_root_stripped}${repo_group.full_path}> | |
|
22 | 22 | DAV svn |
|
23 | SVNParentPath ${parent_path_root}${repo_group.full_path} | |
|
23 | SVNParentPath ${parent_path_root_stripped}${repo_group.full_path} | |
|
24 | 24 | SVNListParentPath ${'On' if svn_list_parent_path else 'Off'} |
|
25 | 25 | Allow from all |
|
26 | 26 | Order allow,deny |
|
27 | 27 | </Location> |
|
28 | 28 | % endfor |
General Comments 0
You need to be logged in to leave comments.
Login now