Show More
@@ -1,97 +1,100 | |||
|
1 | 1 | """Pylons environment configuration""" |
|
2 | 2 | |
|
3 | 3 | import os |
|
4 | 4 | import logging |
|
5 | 5 | import rhodecode |
|
6 | 6 | |
|
7 | 7 | from mako.lookup import TemplateLookup |
|
8 | 8 | from pylons.configuration import PylonsConfig |
|
9 | 9 | from pylons.error import handle_mako_error |
|
10 | 10 | |
|
11 | 11 | # don't remove this import it does magic for celery |
|
12 | 12 | from rhodecode.lib import celerypylons |
|
13 | 13 | |
|
14 | 14 | import rhodecode.lib.app_globals as app_globals |
|
15 | 15 | |
|
16 | 16 | from rhodecode.config.routing import make_map |
|
17 | 17 | |
|
18 | 18 | from rhodecode.lib import helpers |
|
19 | 19 | from rhodecode.lib.auth import set_available_permissions |
|
20 | 20 | from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config,\ |
|
21 | 21 | load_rcextensions |
|
22 | 22 | from rhodecode.lib.utils2 import engine_from_config, str2bool |
|
23 | 23 | from rhodecode.model import init_model |
|
24 | 24 | from rhodecode.model.scm import ScmModel |
|
25 | 25 | |
|
26 | 26 | log = logging.getLogger(__name__) |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | def load_environment(global_conf, app_conf, initial=False): |
|
30 | 30 | """ |
|
31 | 31 | Configure the Pylons environment via the ``pylons.config`` |
|
32 | 32 | object |
|
33 | 33 | """ |
|
34 | 34 | config = PylonsConfig() |
|
35 | 35 | |
|
36 | 36 | # Pylons paths |
|
37 | 37 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
38 | 38 | paths = dict( |
|
39 | 39 | root=root, |
|
40 | 40 | controllers=os.path.join(root, 'controllers'), |
|
41 | 41 | static_files=os.path.join(root, 'public'), |
|
42 | 42 | templates=[os.path.join(root, 'templates')] |
|
43 | 43 | ) |
|
44 | 44 | |
|
45 | 45 | # Initialize config with the basic options |
|
46 | 46 | config.init_app(global_conf, app_conf, package='rhodecode', paths=paths) |
|
47 | 47 | |
|
48 | 48 | # store some globals into rhodecode |
|
49 | 49 | rhodecode.CELERY_ON = str2bool(config['app_conf'].get('use_celery')) |
|
50 | 50 | rhodecode.CELERY_EAGER = str2bool(config['app_conf'].get('celery.always.eager')) |
|
51 | 51 | |
|
52 | 52 | config['routes.map'] = make_map(config) |
|
53 | 53 | config['pylons.app_globals'] = app_globals.Globals(config) |
|
54 | 54 | config['pylons.h'] = helpers |
|
55 | 55 | rhodecode.CONFIG = config |
|
56 | 56 | |
|
57 | 57 | load_rcextensions(root_path=config['here']) |
|
58 | 58 | |
|
59 | 59 | # Setup cache object as early as possible |
|
60 | 60 | import pylons |
|
61 | 61 | pylons.cache._push_object(config['pylons.app_globals'].cache) |
|
62 | 62 | |
|
63 | 63 | # Create the Mako TemplateLookup, with the default auto-escaping |
|
64 | 64 | config['pylons.app_globals'].mako_lookup = TemplateLookup( |
|
65 | 65 | directories=paths['templates'], |
|
66 | 66 | error_handler=handle_mako_error, |
|
67 | 67 | module_directory=os.path.join(app_conf['cache_dir'], 'templates'), |
|
68 | 68 | input_encoding='utf-8', default_filters=['escape'], |
|
69 | 69 | imports=['from webhelpers.html import escape']) |
|
70 | 70 | |
|
71 | 71 | # sets the c attribute access when don't existing attribute are accessed |
|
72 | 72 | config['pylons.strict_tmpl_context'] = True |
|
73 | 73 | test = os.path.split(config['__file__'])[-1] == 'test.ini' |
|
74 | 74 | if test: |
|
75 | if os.environ.get('TEST_DB'): | |
|
76 | # swap config if we pass enviroment variable | |
|
77 | config['sqlalchemy.db1.url'] = os.environ.get('TEST_DB') | |
|
78 | ||
|
75 | 79 | from rhodecode.lib.utils import create_test_env, create_test_index |
|
76 | 80 | from rhodecode.tests import TESTS_TMP_PATH |
|
77 | 81 | create_test_env(TESTS_TMP_PATH, config) |
|
78 | 82 | create_test_index(TESTS_TMP_PATH, config, True) |
|
79 | 83 | |
|
80 | 84 | # MULTIPLE DB configs |
|
81 | 85 | # Setup the SQLAlchemy database engine |
|
82 | 86 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') |
|
83 | ||
|
84 | 87 | init_model(sa_engine_db1) |
|
85 | 88 | |
|
86 | 89 | repos_path = make_ui('db').configitems('paths')[0][1] |
|
87 | 90 | repo2db_mapper(ScmModel().repo_scan(repos_path)) |
|
88 | 91 | set_available_permissions(config) |
|
89 | 92 | config['base_path'] = repos_path |
|
90 | 93 | set_rhodecode_config(config) |
|
91 | 94 | # CONFIGURATION OPTIONS HERE (note: all config options will override |
|
92 | 95 | # any Pylons config options) |
|
93 | 96 | |
|
94 | 97 | # store config reference into our module to skip import magic of |
|
95 | 98 | # pylons |
|
96 | 99 | rhodecode.CONFIG.update(config) |
|
97 | 100 | return config |
General Comments 0
You need to be logged in to leave comments.
Login now