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