##// END OF EJS Templates
config: Fix settings for celery tasks.
Martin Bornhold -
r626:1a043684 default
parent child Browse files
Show More
@@ -1,58 +1,62 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-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 """
22 22
23 23 RhodeCode, a web based repository management software
24 24 versioning implementation: http://www.python.org/dev/peps/pep-0386/
25 25 """
26 26
27 27 import os
28 28 import sys
29 29 import platform
30 30
31 31 VERSION = tuple(open(os.path.join(
32 32 os.path.dirname(__file__), 'VERSION')).read().split('.'))
33 33
34 34 BACKENDS = {
35 35 'hg': 'Mercurial repository',
36 36 'git': 'Git repository',
37 37 'svn': 'Subversion repository',
38 38 }
39 39
40 40 CELERY_ENABLED = False
41 41 CELERY_EAGER = False
42 42
43 43 # link to config for pylons
44 44 CONFIG = {}
45 45
46 # Populated with the settings dictionary from application init in
47 # rhodecode.conf.environment.load_pyramid_environment
48 PYRAMID_SETTINGS = {}
49
46 50 # Linked module for extensions
47 51 EXTENSIONS = {}
48 52
49 53 __version__ = ('.'.join((str(each) for each in VERSION[:3])))
50 54 __dbversion__ = 55 # defines current db version for migrations
51 55 __platform__ = platform.system()
52 56 __license__ = 'AGPLv3, and Commercial License'
53 57 __author__ = 'RhodeCode GmbH'
54 58 __url__ = 'http://rhodecode.com'
55 59
56 60 is_windows = __platform__ in ['Windows']
57 61 is_unix = not is_windows
58 62 is_test = False
@@ -1,180 +1,183 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-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 """
22 22 Pylons environment configuration
23 23 """
24 24
25 25 import os
26 26 import logging
27 27 import rhodecode
28 28 import platform
29 29 import re
30 30 import io
31 31
32 32 from mako.lookup import TemplateLookup
33 33 from pylons.configuration import PylonsConfig
34 34 from pylons.error import handle_mako_error
35 35 from pyramid.settings import asbool
36 36
37 37 # don't remove this import it does magic for celery
38 38 from rhodecode.lib import celerypylons # noqa
39 39
40 40 import rhodecode.lib.app_globals as app_globals
41 41
42 42 from rhodecode.config import utils
43 43 from rhodecode.config.routing import make_map
44 44 from rhodecode.config.jsroutes import generate_jsroutes_content
45 45
46 46 from rhodecode.lib import helpers
47 47 from rhodecode.lib.auth import set_available_permissions
48 48 from rhodecode.lib.utils import (
49 49 repo2db_mapper, make_db_config, set_rhodecode_config,
50 50 load_rcextensions)
51 51 from rhodecode.lib.utils2 import str2bool, aslist
52 52 from rhodecode.lib.vcs import connect_vcs, start_vcs_server
53 53 from rhodecode.model.scm import ScmModel
54 54
55 55 log = logging.getLogger(__name__)
56 56
57 57 def load_environment(global_conf, app_conf, initial=False,
58 58 test_env=None, test_index=None):
59 59 """
60 60 Configure the Pylons environment via the ``pylons.config``
61 61 object
62 62 """
63 63 config = PylonsConfig()
64 64
65 65
66 66 # Pylons paths
67 67 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
68 68 paths = {
69 69 'root': root,
70 70 'controllers': os.path.join(root, 'controllers'),
71 71 'static_files': os.path.join(root, 'public'),
72 72 'templates': [os.path.join(root, 'templates')],
73 73 }
74 74
75 75 # Initialize config with the basic options
76 76 config.init_app(global_conf, app_conf, package='rhodecode', paths=paths)
77 77
78 78 # store some globals into rhodecode
79 79 rhodecode.CELERY_ENABLED = str2bool(config['app_conf'].get('use_celery'))
80 80 rhodecode.CELERY_EAGER = str2bool(
81 81 config['app_conf'].get('celery.always.eager'))
82 82
83 83 config['routes.map'] = make_map(config)
84 84
85 85 if asbool(config.get('generate_js_files', 'false')):
86 86 jsroutes = config['routes.map'].jsroutes()
87 87 jsroutes_file_content = generate_jsroutes_content(jsroutes)
88 88 jsroutes_file_path = os.path.join(
89 89 paths['static_files'], 'js', 'rhodecode', 'routes.js')
90 90
91 91 with io.open(jsroutes_file_path, 'w', encoding='utf-8') as f:
92 92 f.write(jsroutes_file_content)
93 93
94 94 config['pylons.app_globals'] = app_globals.Globals(config)
95 95 config['pylons.h'] = helpers
96 96 rhodecode.CONFIG = config
97 97
98 98 load_rcextensions(root_path=config['here'])
99 99
100 100 # Setup cache object as early as possible
101 101 import pylons
102 102 pylons.cache._push_object(config['pylons.app_globals'].cache)
103 103
104 104 # Create the Mako TemplateLookup, with the default auto-escaping
105 105 config['pylons.app_globals'].mako_lookup = TemplateLookup(
106 106 directories=paths['templates'],
107 107 error_handler=handle_mako_error,
108 108 module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
109 109 input_encoding='utf-8', default_filters=['escape'],
110 110 imports=['from webhelpers.html import escape'])
111 111
112 112 # sets the c attribute access when don't existing attribute are accessed
113 113 config['pylons.strict_tmpl_context'] = True
114 114
115 115 # configure channelstream
116 116 config['channelstream_config'] = {
117 117 'enabled': asbool(config.get('channelstream.enabled', False)),
118 118 'server': config.get('channelstream.server'),
119 119 'secret': config.get('channelstream.secret')
120 120 }
121 121
122 122 set_available_permissions(config)
123 123 db_cfg = make_db_config(clear_session=True)
124 124
125 125 repos_path = list(db_cfg.items('paths'))[0][1]
126 126 config['base_path'] = repos_path
127 127
128 128 # store db config also in main global CONFIG
129 129 set_rhodecode_config(config)
130 130
131 131 # configure instance id
132 132 utils.set_instance_id(config)
133 133
134 134 # CONFIGURATION OPTIONS HERE (note: all config options will override
135 135 # any Pylons config options)
136 136
137 137 # store config reference into our module to skip import magic of pylons
138 138 rhodecode.CONFIG.update(config)
139 139
140 140 return config
141 141
142 142
143 143 def load_pyramid_environment(global_config, settings):
144 144 # Some parts of the code expect a merge of global and app settings.
145 145 settings_merged = global_config.copy()
146 146 settings_merged.update(settings)
147 147
148 # Store the settings to make them available to other modules.
149 rhodecode.PYRAMID_SETTINGS = settings_merged
150
148 151 # If this is a test run we prepare the test environment like
149 152 # creating a test database, test search index and test repositories.
150 153 # This has to be done before the database connection is initialized.
151 154 if settings['is_test']:
152 155 rhodecode.is_test = True
153 156 utils.initialize_test_environment(settings_merged)
154 157
155 158 # Initialize the database connection.
156 159 utils.initialize_database(settings_merged)
157 160
158 161 # Limit backends to `vcs.backends` from configuration
159 162 for alias in rhodecode.BACKENDS.keys():
160 163 if alias not in settings['vcs.backends']:
161 164 del rhodecode.BACKENDS[alias]
162 165 log.info('Enabled VCS backends: %s', rhodecode.BACKENDS.keys())
163 166
164 167 # initialize vcs client and optionally run the server if enabled
165 168 vcs_server_uri = settings['vcs.server']
166 169 vcs_server_enabled = settings['vcs.server.enable']
167 170 start_server = (
168 171 settings['vcs.start_server'] and
169 172 not int(os.environ.get('RC_VCSSERVER_TEST_DISABLE', '0')))
170 173
171 174 if vcs_server_enabled and start_server:
172 175 log.info("Starting vcsserver")
173 176 start_vcs_server(server_and_port=vcs_server_uri,
174 177 protocol=utils.get_vcs_server_protocol(settings),
175 178 log_level=settings['vcs.server.log_level'])
176 179
177 180 utils.configure_pyro4(settings)
178 181 utils.configure_vcs(settings)
179 182 if vcs_server_enabled:
180 183 connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings))
General Comments 0
You need to be logged in to leave comments. Login now