##// 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 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2016 RhodeCode GmbH
3 # Copyright (C) 2016-2016 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
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
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
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/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import logging
21 import logging
22 import os
22 import os
23 import shlex
23 import shlex
24
24
25 # Do not use `from rhodecode import events` here, it will be overridden by the
25 # Do not use `from rhodecode import events` here, it will be overridden by the
26 # events module in this package due to pythons import mechanism.
26 # events module in this package due to pythons import mechanism.
27 from rhodecode.events import RepoGroupEvent
27 from rhodecode.events import RepoGroupEvent
28 from rhodecode.subscribers import AsyncSubprocessSubscriber
28 from rhodecode.subscribers import AsyncSubprocessSubscriber
29 from rhodecode.config.middleware import (
29 from rhodecode.config.middleware import (
30 _bool_setting, _string_setting, _int_setting)
30 _bool_setting, _string_setting, _int_setting)
31
31
32 from .events import ModDavSvnConfigChange
32 from .events import ModDavSvnConfigChange
33 from .subscribers import generate_config_subscriber
33 from .subscribers import generate_config_subscriber
34 from . import config_keys
34 from . import config_keys
35
35
36
36
37 log = logging.getLogger(__name__)
37 log = logging.getLogger(__name__)
38
38
39
39
40 def includeme(config):
40 def includeme(config):
41 settings = config.registry.settings
41 settings = config.registry.settings
42 _sanitize_settings_and_apply_defaults(settings)
42 _sanitize_settings_and_apply_defaults(settings)
43
43
44 if settings[config_keys.generate_config]:
44 if settings[config_keys.generate_config]:
45 # Add subscriber to generate the Apache mod dav svn configuration on
45 # Add subscriber to generate the Apache mod dav svn configuration on
46 # repository group events.
46 # repository group events.
47 config.add_subscriber(generate_config_subscriber, RepoGroupEvent)
47 config.add_subscriber(generate_config_subscriber, RepoGroupEvent)
48
48
49 # Prepare reload command to pass it to the subprocess module and add a
49 # If a reload command is set add a subscriber to execute it on
50 # subscriber to execute it on configuration changes.
50 # configuration changes.
51 reload_cmd = shlex.split(settings[config_keys.reload_command])
51 reload_cmd = shlex.split(settings[config_keys.reload_command])
52 reload_timeout = settings[config_keys.reload_timeout] or None
52 if reload_cmd:
53 config_change_subscriber = AsyncSubprocessSubscriber(
53 reload_timeout = settings[config_keys.reload_timeout] or None
54 cmd=reload_cmd, timeout=reload_timeout)
54 reload_subscriber = AsyncSubprocessSubscriber(
55 config.add_subscriber(config_change_subscriber, ModDavSvnConfigChange)
55 cmd=reload_cmd, timeout=reload_timeout)
56 config.add_subscriber(reload_subscriber, ModDavSvnConfigChange)
56
57
57
58
58 def _sanitize_settings_and_apply_defaults(settings):
59 def _sanitize_settings_and_apply_defaults(settings):
59 """
60 """
60 Set defaults, convert to python types and validate settings.
61 Set defaults, convert to python types and validate settings.
61 """
62 """
62 _bool_setting(settings, config_keys.generate_config, 'false')
63 _bool_setting(settings, config_keys.generate_config, 'false')
63 _bool_setting(settings, config_keys.list_parent_path, 'true')
64 _bool_setting(settings, config_keys.list_parent_path, 'true')
64 _int_setting(settings, config_keys.reload_timeout, 10)
65 _int_setting(settings, config_keys.reload_timeout, 10)
65 _string_setting(settings, config_keys.config_file_path, '', lower=False)
66 _string_setting(settings, config_keys.config_file_path, '', lower=False)
66 _string_setting(settings, config_keys.location_root, '/', lower=False)
67 _string_setting(settings, config_keys.location_root, '/', lower=False)
67 _string_setting(settings, config_keys.reload_command, '', lower=False)
68 _string_setting(settings, config_keys.reload_command, '', lower=False)
68
69
69 # Convert negative timeout values to zero.
70 # Convert negative timeout values to zero.
70 if settings[config_keys.reload_timeout] < 0:
71 if settings[config_keys.reload_timeout] < 0:
71 settings[config_keys.reload_timeout] = 0
72 settings[config_keys.reload_timeout] = 0
72
73
73 # Append path separator to location root.
74 # Append path separator to location root.
74 settings[config_keys.location_root] = _append_path_sep(
75 settings[config_keys.location_root] = _append_path_sep(
75 settings[config_keys.location_root])
76 settings[config_keys.location_root])
76
77
77 # Validate settings.
78 # Validate settings.
78 if settings[config_keys.generate_config]:
79 if settings[config_keys.generate_config]:
79 assert len(settings[config_keys.config_file_path]) > 0
80 assert len(settings[config_keys.config_file_path]) > 0
80
81
81
82
82 def _append_path_sep(path):
83 def _append_path_sep(path):
83 """
84 """
84 Append the path separator if missing.
85 Append the path separator if missing.
85 """
86 """
86 if isinstance(path, basestring) and not path.endswith(os.path.sep):
87 if isinstance(path, basestring) and not path.endswith(os.path.sep):
87 path += os.path.sep
88 path += os.path.sep
88 return path
89 return path
General Comments 0
You need to be logged in to leave comments. Login now