##// END OF EJS Templates
added logging info about loaded rcext
marcink -
r2107:3ed6b940 beta
parent child Browse files
Show More
@@ -1,93 +1,94
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 from rhodecode.lib.vcs.utils.fakemod import create_module
22 from rhodecode.lib.vcs.utils.fakemod import create_module
23
23
24 log = logging.getLogger(__name__)
24 log = logging.getLogger(__name__)
25
25
26
26
27 def load_environment(global_conf, app_conf, initial=False):
27 def load_environment(global_conf, app_conf, initial=False):
28 """Configure the Pylons environment via the ``pylons.config``
28 """Configure the Pylons environment via the ``pylons.config``
29 object
29 object
30 """
30 """
31 config = PylonsConfig()
31 config = PylonsConfig()
32
32
33 # Pylons paths
33 # Pylons paths
34 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
34 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
35 paths = dict(root=root,
35 paths = dict(root=root,
36 controllers=os.path.join(root, 'controllers'),
36 controllers=os.path.join(root, 'controllers'),
37 static_files=os.path.join(root, 'public'),
37 static_files=os.path.join(root, 'public'),
38 templates=[os.path.join(root, 'templates')])
38 templates=[os.path.join(root, 'templates')])
39
39
40 # Initialize config with the basic options
40 # Initialize config with the basic options
41 config.init_app(global_conf, app_conf, package='rhodecode', paths=paths)
41 config.init_app(global_conf, app_conf, package='rhodecode', paths=paths)
42
42
43 # store some globals into rhodecode
43 # store some globals into rhodecode
44 rhodecode.CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
44 rhodecode.CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
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 rhodecode.CONFIG = config
49 rhodecode.CONFIG = config
50
50
51 path = os.path.join(config['here'], 'rcextensions', '__init__.py')
51 path = os.path.join(config['here'], 'rcextensions', '__init__.py')
52 if os.path.isfile(path):
52 if os.path.isfile(path):
53 rcext = create_module('rc', path)
53 rcext = create_module('rc', path)
54 rhodecode.EXTENSIONS = rcext
54 rhodecode.EXTENSIONS = rcext
55 log.debug('Found rcextensions now loading %s...' % rcext)
55 # Setup cache object as early as possible
56 # Setup cache object as early as possible
56 import pylons
57 import pylons
57 pylons.cache._push_object(config['pylons.app_globals'].cache)
58 pylons.cache._push_object(config['pylons.app_globals'].cache)
58
59
59 # Create the Mako TemplateLookup, with the default auto-escaping
60 # Create the Mako TemplateLookup, with the default auto-escaping
60 config['pylons.app_globals'].mako_lookup = TemplateLookup(
61 config['pylons.app_globals'].mako_lookup = TemplateLookup(
61 directories=paths['templates'],
62 directories=paths['templates'],
62 error_handler=handle_mako_error,
63 error_handler=handle_mako_error,
63 module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
64 module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
64 input_encoding='utf-8', default_filters=['escape'],
65 input_encoding='utf-8', default_filters=['escape'],
65 imports=['from webhelpers.html import escape'])
66 imports=['from webhelpers.html import escape'])
66
67
67 # sets the c attribute access when don't existing attribute are accessed
68 # sets the c attribute access when don't existing attribute are accessed
68 config['pylons.strict_tmpl_context'] = True
69 config['pylons.strict_tmpl_context'] = True
69 test = os.path.split(config['__file__'])[-1] == 'test.ini'
70 test = os.path.split(config['__file__'])[-1] == 'test.ini'
70 if test:
71 if test:
71 from rhodecode.lib.utils import create_test_env, create_test_index
72 from rhodecode.lib.utils import create_test_env, create_test_index
72 from rhodecode.tests import TESTS_TMP_PATH
73 from rhodecode.tests import TESTS_TMP_PATH
73 create_test_env(TESTS_TMP_PATH, config)
74 create_test_env(TESTS_TMP_PATH, config)
74 create_test_index(TESTS_TMP_PATH, config, True)
75 create_test_index(TESTS_TMP_PATH, config, True)
75
76
76 # MULTIPLE DB configs
77 # MULTIPLE DB configs
77 # Setup the SQLAlchemy database engine
78 # Setup the SQLAlchemy database engine
78 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
79 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
79
80
80 init_model(sa_engine_db1)
81 init_model(sa_engine_db1)
81
82
82 repos_path = make_ui('db').configitems('paths')[0][1]
83 repos_path = make_ui('db').configitems('paths')[0][1]
83 repo2db_mapper(ScmModel().repo_scan(repos_path))
84 repo2db_mapper(ScmModel().repo_scan(repos_path))
84 set_available_permissions(config)
85 set_available_permissions(config)
85 config['base_path'] = repos_path
86 config['base_path'] = repos_path
86 set_rhodecode_config(config)
87 set_rhodecode_config(config)
87 # CONFIGURATION OPTIONS HERE (note: all config options will override
88 # CONFIGURATION OPTIONS HERE (note: all config options will override
88 # any Pylons config options)
89 # any Pylons config options)
89
90
90 # store config reference into our module to skip import magic of
91 # store config reference into our module to skip import magic of
91 # pylons
92 # pylons
92 rhodecode.CONFIG.update(config)
93 rhodecode.CONFIG.update(config)
93 return config
94 return config
General Comments 0
You need to be logged in to leave comments. Login now