Show More
@@ -1,86 +1,87 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 | import shlex | |
|
23 | 24 | |
|
24 | 25 | # Do not use `from rhodecode import events` here, it will be overridden by the |
|
25 | 26 | # events module in this package due to pythons import mechanism. |
|
26 | 27 | from rhodecode.events import RepoGroupEvent |
|
27 | 28 | from rhodecode.config.middleware import ( |
|
28 | 29 | _bool_setting, _string_setting, _int_setting) |
|
29 | 30 | |
|
30 | 31 | from .events import ModDavSvnConfigChange |
|
31 | 32 | from .subscribers import generate_config_subscriber, AsyncSubprocessSubscriber |
|
32 | 33 | from . import config_keys |
|
33 | 34 | |
|
34 | 35 | |
|
35 | 36 | log = logging.getLogger(__name__) |
|
36 | 37 | |
|
37 | 38 | |
|
38 | 39 | def includeme(config): |
|
39 | 40 | settings = config.registry.settings |
|
40 | 41 | _sanitize_settings_and_apply_defaults(settings) |
|
41 | 42 | |
|
42 | 43 | if settings[config_keys.generate_config]: |
|
43 | 44 | # Add subscriber to generate the Apache mod dav svn configuration on |
|
44 | 45 | # repository group events. |
|
45 | 46 | config.add_subscriber(generate_config_subscriber, RepoGroupEvent) |
|
46 | 47 | |
|
47 | 48 | # Prepare reload command to pass it to the subprocess module and add a |
|
48 | 49 | # subscriber to execute it on configuration changes. |
|
49 | cmd = settings[config_keys.reload_command] | |
|
50 | cmd = cmd.split(' ') if cmd else cmd | |
|
51 | config.add_subscriber( | |
|
52 | AsyncSubprocessSubscriber(cmd=cmd, timeout=5), | |
|
53 | ModDavSvnConfigChange) | |
|
50 | reload_cmd = shlex.split(settings[config_keys.reload_command]) | |
|
51 | reload_timeout = settings[config_keys.reload_timeout] or None | |
|
52 | config_change_subscriber = AsyncSubprocessSubscriber( | |
|
53 | cmd=reload_cmd, timeout=reload_timeout) | |
|
54 | config.add_subscriber(config_change_subscriber, ModDavSvnConfigChange) | |
|
54 | 55 | |
|
55 | 56 | |
|
56 | 57 | def _sanitize_settings_and_apply_defaults(settings): |
|
57 | 58 | """ |
|
58 | 59 | Set defaults, convert to python types and validate settings. |
|
59 | 60 | """ |
|
60 | 61 | _bool_setting(settings, config_keys.generate_config, 'false') |
|
61 | 62 | _bool_setting(settings, config_keys.list_parent_path, 'true') |
|
62 | 63 | _int_setting(settings, config_keys.reload_timeout, 10) |
|
63 | 64 | _string_setting(settings, config_keys.config_file_path, '', lower=False) |
|
64 | 65 | _string_setting(settings, config_keys.location_root, '/', lower=False) |
|
65 | 66 | _string_setting(settings, config_keys.reload_command, '', lower=False) |
|
66 | 67 | |
|
67 | 68 | # Convert negative timeout values to zero. |
|
68 | 69 | if settings[config_keys.reload_timeout] < 0: |
|
69 | 70 | settings[config_keys.reload_timeout] = 0 |
|
70 | 71 | |
|
71 | 72 | # Append path separator to location root. |
|
72 | 73 | settings[config_keys.location_root] = _append_path_sep( |
|
73 | 74 | settings[config_keys.location_root]) |
|
74 | 75 | |
|
75 | 76 | # Validate settings. |
|
76 | 77 | if settings[config_keys.generate_config]: |
|
77 | 78 | assert len(settings[config_keys.config_file_path]) > 0 |
|
78 | 79 | |
|
79 | 80 | |
|
80 | 81 | def _append_path_sep(path): |
|
81 | 82 | """ |
|
82 | 83 | Append the path separator if missing. |
|
83 | 84 | """ |
|
84 | 85 | if isinstance(path, basestring) and not path.endswith(os.path.sep): |
|
85 | 86 | path += os.path.sep |
|
86 | 87 | return path |
General Comments 0
You need to be logged in to leave comments.
Login now