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