##// END OF EJS Templates
fix(backend): fixed broken backends function after python3 migration
super-admin -
r5523:112c3403 stable
parent child Browse files
Show More
@@ -1,87 +1,87 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 os
19 import os
20 import logging
20 import logging
21 import rhodecode
21 import rhodecode
22 import collections
22 import collections
23
23
24 from rhodecode.config import utils
24 from rhodecode.config import utils
25
25
26 from rhodecode.lib.utils import load_rcextensions
26 from rhodecode.lib.utils import load_rcextensions
27 from rhodecode.lib.utils2 import str2bool
27 from rhodecode.lib.utils2 import str2bool
28 from rhodecode.lib.vcs import connect_vcs
28 from rhodecode.lib.vcs import connect_vcs
29
29
30 log = logging.getLogger(__name__)
30 log = logging.getLogger(__name__)
31
31
32
32
33 def load_pyramid_environment(global_config, settings):
33 def load_pyramid_environment(global_config, settings):
34 # Some parts of the code expect a merge of global and app settings.
34 # Some parts of the code expect a merge of global and app settings.
35 settings_merged = global_config.copy()
35 settings_merged = global_config.copy()
36 settings_merged.update(settings)
36 settings_merged.update(settings)
37
37
38 # TODO(marcink): probably not required anymore
38 # TODO(marcink): probably not required anymore
39 # configure channelstream,
39 # configure channelstream,
40 settings_merged['channelstream_config'] = {
40 settings_merged['channelstream_config'] = {
41 'enabled': str2bool(settings_merged.get('channelstream.enabled', False)),
41 'enabled': str2bool(settings_merged.get('channelstream.enabled', False)),
42 'server': settings_merged.get('channelstream.server'),
42 'server': settings_merged.get('channelstream.server'),
43 'secret': settings_merged.get('channelstream.secret')
43 'secret': settings_merged.get('channelstream.secret')
44 }
44 }
45
45
46 # If this is a test run we prepare the test environment like
46 # If this is a test run we prepare the test environment like
47 # creating a test database, test search index and test repositories.
47 # creating a test database, test search index and test repositories.
48 # This has to be done before the database connection is initialized.
48 # This has to be done before the database connection is initialized.
49 if rhodecode.is_test:
49 if rhodecode.is_test:
50 rhodecode.disable_error_handler = True
50 rhodecode.disable_error_handler = True
51 from rhodecode import authentication
51 from rhodecode import authentication
52 authentication.plugin_default_auth_ttl = 0
52 authentication.plugin_default_auth_ttl = 0
53
53
54 utils.initialize_test_environment(settings_merged)
54 utils.initialize_test_environment(settings_merged)
55
55
56 # Initialize the database connection.
56 # Initialize the database connection.
57 utils.initialize_database(settings_merged)
57 utils.initialize_database(settings_merged)
58
58
59 load_rcextensions(root_path=settings_merged['here'])
59 load_rcextensions(root_path=settings_merged['here'])
60
60
61 # Limit backends to `vcs.backends` from configuration, and preserve the order
61 # Limit backends to `vcs.backends` from configuration, and preserve the order
62 for alias in rhodecode.BACKENDS.keys():
62 for alias in list(rhodecode.BACKENDS.keys()):
63 if alias not in settings['vcs.backends']:
63 if alias not in settings['vcs.backends']:
64 del rhodecode.BACKENDS[alias]
64 del rhodecode.BACKENDS[alias]
65
65
66 _sorted_backend = sorted(rhodecode.BACKENDS.items(),
66 _sorted_backend = sorted(rhodecode.BACKENDS.items(),
67 key=lambda item: settings['vcs.backends'].index(item[0]))
67 key=lambda item: settings['vcs.backends'].index(item[0]))
68 rhodecode.BACKENDS = collections.OrderedDict(_sorted_backend)
68 rhodecode.BACKENDS = collections.OrderedDict(_sorted_backend)
69
69
70 log.info('Enabled VCS backends: %s', rhodecode.BACKENDS.keys())
70 log.info('Enabled VCS backends: %s', list(rhodecode.BACKENDS.keys()))
71
71
72 # initialize vcs client and optionally run the server if enabled
72 # initialize vcs client and optionally run the server if enabled
73 vcs_server_uri = settings['vcs.server']
73 vcs_server_uri = settings['vcs.server']
74 vcs_server_enabled = settings['vcs.server.enable']
74 vcs_server_enabled = settings['vcs.server.enable']
75
75
76 utils.configure_vcs(settings)
76 utils.configure_vcs(settings)
77
77
78 # Store the settings to make them available to other modules.
78 # Store the settings to make them available to other modules.
79
79
80 rhodecode.PYRAMID_SETTINGS = settings_merged
80 rhodecode.PYRAMID_SETTINGS = settings_merged
81 rhodecode.CONFIG = settings_merged
81 rhodecode.CONFIG = settings_merged
82 rhodecode.CONFIG['default_user_id'] = utils.get_default_user_id()
82 rhodecode.CONFIG['default_user_id'] = utils.get_default_user_id()
83
83
84 if vcs_server_enabled:
84 if vcs_server_enabled:
85 connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings))
85 connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings))
86 else:
86 else:
87 log.warning('vcs-server not enabled, vcs connection unavailable')
87 log.warning('vcs-server not enabled, vcs connection unavailable')
General Comments 0
You need to be logged in to leave comments. Login now