##// END OF EJS Templates
moved pylons config out of global scope for celerypylons
marcink -
r1726:fe8c2e88 beta
parent child Browse files
Show More
@@ -1,85 +1,85
1 1 """Pylons environment configuration"""
2 2
3 3 import os
4 4 import logging
5 5
6 6 from mako.lookup import TemplateLookup
7 7 from pylons.configuration import PylonsConfig
8 8 from pylons.error import handle_mako_error
9 9
10 10 import rhodecode
11 11 import rhodecode.lib.app_globals as app_globals
12 12 import rhodecode.lib.helpers
13 13
14 14 from rhodecode.config.routing import make_map
15 15 # don't remove this import it does magic for celery
16 16 from rhodecode.lib import celerypylons, str2bool
17 17 from rhodecode.lib import engine_from_config
18 18 from rhodecode.lib.auth import set_available_permissions
19 19 from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config
20 20 from rhodecode.model import init_model
21 21 from rhodecode.model.scm import ScmModel
22 22
23 23 log = logging.getLogger(__name__)
24 24
25 25
26 26 def load_environment(global_conf, app_conf, initial=False):
27 27 """Configure the Pylons environment via the ``pylons.config``
28 28 object
29 29 """
30 30 config = PylonsConfig()
31 31
32 32 # Pylons paths
33 33 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
34 34 paths = dict(root=root,
35 35 controllers=os.path.join(root, 'controllers'),
36 36 static_files=os.path.join(root, 'public'),
37 37 templates=[os.path.join(root, 'templates')])
38 38
39 39 # Initialize config with the basic options
40 40 config.init_app(global_conf, app_conf, package='rhodecode', paths=paths)
41 41
42 # store some globals into our main isntance
42 # store some globals into rhodecode
43 43 rhodecode.CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
44 44 rhodecode.CONFIG = config
45 45
46 46 config['routes.map'] = make_map(config)
47 47 config['pylons.app_globals'] = app_globals.Globals(config)
48 48 config['pylons.h'] = rhodecode.lib.helpers
49 49
50 50 # Setup cache object as early as possible
51 51 import pylons
52 52 pylons.cache._push_object(config['pylons.app_globals'].cache)
53 53
54 54 # Create the Mako TemplateLookup, with the default auto-escaping
55 55 config['pylons.app_globals'].mako_lookup = TemplateLookup(
56 56 directories=paths['templates'],
57 57 error_handler=handle_mako_error,
58 58 module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
59 59 input_encoding='utf-8', default_filters=['escape'],
60 60 imports=['from webhelpers.html import escape'])
61 61
62 62 #sets the c attribute access when don't existing attribute are accessed
63 63 config['pylons.strict_tmpl_context'] = True
64 64 test = os.path.split(config['__file__'])[-1] == 'test.ini'
65 65 if test:
66 66 from rhodecode.lib.utils import create_test_env, create_test_index
67 67 from rhodecode.tests import TESTS_TMP_PATH
68 68 create_test_env(TESTS_TMP_PATH, config)
69 69 create_test_index(TESTS_TMP_PATH, config, True)
70 70
71 71 #MULTIPLE DB configs
72 72 # Setup the SQLAlchemy database engine
73 73 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
74 74
75 75 init_model(sa_engine_db1)
76 76
77 77 repos_path = make_ui('db').configitems('paths')[0][1]
78 78 repo2db_mapper(ScmModel().repo_scan(repos_path))
79 79 set_available_permissions(config)
80 80 config['base_path'] = repos_path
81 81 set_rhodecode_config(config)
82 82 # CONFIGURATION OPTIONS HERE (note: all config options will override
83 83 # any Pylons config options)
84 84
85 85 return config
@@ -1,93 +1,94
1 1 from rhodecode.lib.utils import BasePasterCommand, Command
2 2 from celery.app import app_or_default
3 3 from celery.bin import camqadm, celerybeat, celeryd, celeryev
4 from pylons import config
4
5 5 from rhodecode.lib import str2bool
6 6
7 7 __all__ = ['CeleryDaemonCommand', 'CeleryBeatCommand',
8 8 'CAMQPAdminCommand', 'CeleryEventCommand']
9 9
10 10
11 11 class CeleryCommand(BasePasterCommand):
12 12 """Abstract class implements run methods needed for celery
13 13
14 14 Starts the celery worker that uses a paste.deploy configuration
15 15 file.
16 16 """
17 17
18 18 def update_parser(self):
19 19 """
20 20 Abstract method. Allows for the class's parser to be updated
21 21 before the superclass's `run` method is called. Necessary to
22 22 allow options/arguments to be passed through to the underlying
23 23 celery command.
24 24 """
25 25
26 26 cmd = self.celery_command(app_or_default())
27 27 for x in cmd.get_options():
28 28 self.parser.add_option(x)
29 29
30 30 def command(self):
31 from pylons import config
31 32 try:
32 33 CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
33 34 except KeyError:
34 35 CELERY_ON = False
35 36
36 37 if CELERY_ON == False:
37 38 raise Exception('Please enable celery_on in .ini config '
38 39 'file before running celeryd')
39 40
40 41 cmd = self.celery_command(app_or_default())
41 42 return cmd.run(**vars(self.options))
42 43
43 44 class CeleryDaemonCommand(CeleryCommand):
44 45 """Start the celery worker
45 46
46 47 Starts the celery worker that uses a paste.deploy configuration
47 48 file.
48 49 """
49 50 usage = 'CONFIG_FILE [celeryd options...]'
50 51 summary = __doc__.splitlines()[0]
51 52 description = "".join(__doc__.splitlines()[2:])
52 53
53 54 parser = Command.standard_parser(quiet=True)
54 55 celery_command = celeryd.WorkerCommand
55 56
56 57
57 58 class CeleryBeatCommand(CeleryCommand):
58 59 """Start the celery beat server
59 60
60 61 Starts the celery beat server using a paste.deploy configuration
61 62 file.
62 63 """
63 64 usage = 'CONFIG_FILE [celerybeat options...]'
64 65 summary = __doc__.splitlines()[0]
65 66 description = "".join(__doc__.splitlines()[2:])
66 67
67 68 parser = Command.standard_parser(quiet=True)
68 69 celery_command = celerybeat.BeatCommand
69 70
70 71
71 72 class CAMQPAdminCommand(CeleryCommand):
72 73 """CAMQP Admin
73 74
74 75 CAMQP celery admin tool.
75 76 """
76 77 usage = 'CONFIG_FILE [camqadm options...]'
77 78 summary = __doc__.splitlines()[0]
78 79 description = "".join(__doc__.splitlines()[2:])
79 80
80 81 parser = Command.standard_parser(quiet=True)
81 82 celery_command = camqadm.AMQPAdminCommand
82 83
83 84 class CeleryEventCommand(CeleryCommand):
84 85 """Celery event command.
85 86
86 87 Capture celery events.
87 88 """
88 89 usage = 'CONFIG_FILE [celeryev options...]'
89 90 summary = __doc__.splitlines()[0]
90 91 description = "".join(__doc__.splitlines()[2:])
91 92
92 93 parser = Command.standard_parser(quiet=True)
93 94 celery_command = celeryev.EvCommand
General Comments 0
You need to be logged in to leave comments. Login now