##// END OF EJS Templates
fix(backend): fixed broken backends function after python3 migration...
super-admin -
r5524:fb58a2b4 default
parent child Browse files
Show More
@@ -1,98 +1,98 b''
1 # Copyright (C) 2010-2023 RhodeCode GmbH
1 # Copyright (C) 2010-2023 RhodeCode GmbH
2 #
2 #
3 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU Affero General Public License, version 3
4 # it under the terms of the GNU Affero General Public License, version 3
5 # (only), as published by the Free Software Foundation.
5 # (only), as published by the Free Software Foundation.
6 #
6 #
7 # This program is distributed in the hope that it will be useful,
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
10 # GNU General Public License for more details.
11 #
11 #
12 # You should have received a copy of the GNU Affero General Public License
12 # You should have received a copy of the GNU Affero General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 #
14 #
15 # This program is dual-licensed. If you wish to learn more about the
15 # This program is dual-licensed. If you wish to learn more about the
16 # RhodeCode Enterprise Edition, including its added features, Support services,
16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18
18
19 import logging
19 import logging
20 import rhodecode
20 import rhodecode
21 import collections
21 import collections
22
22
23 from rhodecode.config import utils
23 from rhodecode.config import utils
24
24
25 from rhodecode.lib.utils import load_rcextensions
25 from rhodecode.lib.utils import load_rcextensions
26 from rhodecode.lib.utils2 import str2bool
26 from rhodecode.lib.utils2 import str2bool
27 from rhodecode.lib.vcs import connect_vcs
27 from rhodecode.lib.vcs import connect_vcs
28
28
29 log = logging.getLogger(__name__)
29 log = logging.getLogger(__name__)
30
30
31
31
32 def propagate_rhodecode_config(global_config, settings, config):
32 def propagate_rhodecode_config(global_config, settings, config):
33 # Store the settings to make them available to other modules.
33 # Store the settings to make them available to other modules.
34 settings_merged = global_config.copy()
34 settings_merged = global_config.copy()
35 settings_merged.update(settings)
35 settings_merged.update(settings)
36 if config:
36 if config:
37 settings_merged.update(config)
37 settings_merged.update(config)
38
38
39 rhodecode.PYRAMID_SETTINGS = settings_merged
39 rhodecode.PYRAMID_SETTINGS = settings_merged
40 rhodecode.CONFIG = settings_merged
40 rhodecode.CONFIG = settings_merged
41
41
42 if 'default_user_id' not in rhodecode.CONFIG:
42 if 'default_user_id' not in rhodecode.CONFIG:
43 rhodecode.CONFIG['default_user_id'] = utils.get_default_user_id()
43 rhodecode.CONFIG['default_user_id'] = utils.get_default_user_id()
44 log.debug('set rhodecode.CONFIG data')
44 log.debug('set rhodecode.CONFIG data')
45
45
46
46
47 def load_pyramid_environment(global_config, settings):
47 def load_pyramid_environment(global_config, settings):
48 # Some parts of the code expect a merge of global and app settings.
48 # Some parts of the code expect a merge of global and app settings.
49 settings_merged = global_config.copy()
49 settings_merged = global_config.copy()
50 settings_merged.update(settings)
50 settings_merged.update(settings)
51
51
52 # TODO(marcink): probably not required anymore
52 # TODO(marcink): probably not required anymore
53 # configure channelstream,
53 # configure channelstream,
54 settings_merged['channelstream_config'] = {
54 settings_merged['channelstream_config'] = {
55 'enabled': str2bool(settings_merged.get('channelstream.enabled', False)),
55 'enabled': str2bool(settings_merged.get('channelstream.enabled', False)),
56 'server': settings_merged.get('channelstream.server'),
56 'server': settings_merged.get('channelstream.server'),
57 'secret': settings_merged.get('channelstream.secret')
57 'secret': settings_merged.get('channelstream.secret')
58 }
58 }
59
59
60 # If this is a test run we prepare the test environment like
60 # If this is a test run we prepare the test environment like
61 # creating a test database, test search index and test repositories.
61 # creating a test database, test search index and test repositories.
62 # This has to be done before the database connection is initialized.
62 # This has to be done before the database connection is initialized.
63 if rhodecode.is_test:
63 if rhodecode.is_test:
64 rhodecode.disable_error_handler = True
64 rhodecode.disable_error_handler = True
65 from rhodecode import authentication
65 from rhodecode import authentication
66 authentication.plugin_default_auth_ttl = 0
66 authentication.plugin_default_auth_ttl = 0
67
67
68 utils.initialize_test_environment(settings_merged)
68 utils.initialize_test_environment(settings_merged)
69
69
70 # Initialize the database connection.
70 # Initialize the database connection.
71 utils.initialize_database(settings_merged)
71 utils.initialize_database(settings_merged)
72
72
73 load_rcextensions(root_path=settings_merged['here'])
73 load_rcextensions(root_path=settings_merged['here'])
74
74
75 # Limit backends to `vcs.backends` from configuration, and preserve the order
75 # Limit backends to `vcs.backends` from configuration, and preserve the order
76 for alias in rhodecode.BACKENDS.keys():
76 for alias in list(rhodecode.BACKENDS.keys()):
77 if alias not in settings['vcs.backends']:
77 if alias not in settings['vcs.backends']:
78 del rhodecode.BACKENDS[alias]
78 del rhodecode.BACKENDS[alias]
79
79
80 _sorted_backend = sorted(rhodecode.BACKENDS.items(),
80 _sorted_backend = sorted(rhodecode.BACKENDS.items(),
81 key=lambda item: settings['vcs.backends'].index(item[0]))
81 key=lambda item: settings['vcs.backends'].index(item[0]))
82 rhodecode.BACKENDS = collections.OrderedDict(_sorted_backend)
82 rhodecode.BACKENDS = collections.OrderedDict(_sorted_backend)
83
83
84 log.info('Enabled VCS backends: %s', rhodecode.BACKENDS.keys())
84 log.info('Enabled VCS backends: %s', list(rhodecode.BACKENDS.keys()))
85
85
86 # initialize vcs client and optionally run the server if enabled
86 # initialize vcs client and optionally run the server if enabled
87 vcs_server_uri = settings['vcs.server']
87 vcs_server_uri = settings['vcs.server']
88 vcs_server_enabled = settings['vcs.server.enable']
88 vcs_server_enabled = settings['vcs.server.enable']
89
89
90 utils.configure_vcs(settings)
90 utils.configure_vcs(settings)
91
91
92 # first run, to store data...
92 # first run, to store data...
93 propagate_rhodecode_config(global_config, settings, {})
93 propagate_rhodecode_config(global_config, settings, {})
94
94
95 if vcs_server_enabled:
95 if vcs_server_enabled:
96 connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings))
96 connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings))
97 else:
97 else:
98 log.warning('vcs-server not enabled, vcs connection unavailable')
98 log.warning('vcs-server not enabled, vcs connection unavailable')
General Comments 0
You need to be logged in to leave comments. Login now