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