Mercurial > kallithea
comparison rhodecode/config/environment.py @ 547:1e757ac98988
renamed project to rhodecode
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 06 Oct 2010 03:18:16 +0200 |
parents | pylons_app/config/environment.py@fefffd6fd5f4 |
children | b75b77ef649d |
comparison
equal
deleted
inserted
replaced
546:7c2f5e4d7bbf | 547:1e757ac98988 |
---|---|
1 """Pylons environment configuration""" | |
2 from mako.lookup import TemplateLookup | |
3 from pylons.configuration import PylonsConfig | |
4 from pylons.error import handle_mako_error | |
5 from rhodecode.config.routing import make_map | |
6 from rhodecode.lib.auth import set_available_permissions, set_base_path | |
7 from rhodecode.lib.utils import repo2db_mapper, make_ui, set_hg_app_config | |
8 from rhodecode.model import init_model | |
9 from rhodecode.model.hg_model import _get_repos_cached_initial | |
10 from sqlalchemy import engine_from_config | |
11 import logging | |
12 import os | |
13 import rhodecode.lib.app_globals as app_globals | |
14 import rhodecode.lib.helpers | |
15 | |
16 log = logging.getLogger(__name__) | |
17 | |
18 def load_environment(global_conf, app_conf, initial=False): | |
19 """Configure the Pylons environment via the ``pylons.config`` | |
20 object | |
21 """ | |
22 config = PylonsConfig() | |
23 | |
24 # Pylons paths | |
25 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
26 paths = dict(root=root, | |
27 controllers=os.path.join(root, 'controllers'), | |
28 static_files=os.path.join(root, 'public'), | |
29 templates=[os.path.join(root, 'templates')]) | |
30 | |
31 # Initialize config with the basic options | |
32 config.init_app(global_conf, app_conf, package='rhodecode', paths=paths) | |
33 | |
34 config['routes.map'] = make_map(config) | |
35 config['pylons.app_globals'] = app_globals.Globals(config) | |
36 config['pylons.h'] = rhodecode.lib.helpers | |
37 | |
38 # Setup cache object as early as possible | |
39 import pylons | |
40 pylons.cache._push_object(config['pylons.app_globals'].cache) | |
41 | |
42 # Create the Mako TemplateLookup, with the default auto-escaping | |
43 config['pylons.app_globals'].mako_lookup = TemplateLookup( | |
44 directories=paths['templates'], | |
45 error_handler=handle_mako_error, | |
46 module_directory=os.path.join(app_conf['cache_dir'], 'templates'), | |
47 input_encoding='utf-8', default_filters=['escape'], | |
48 imports=['from webhelpers.html import escape']) | |
49 | |
50 #sets the c attribute access when don't existing attribute are accessed | |
51 config['pylons.strict_tmpl_context'] = True | |
52 test = os.path.split(config['__file__'])[-1] == 'test.ini' | |
53 if test: | |
54 from rhodecode.lib.utils import create_test_env, create_test_index | |
55 create_test_env('/tmp', config) | |
56 create_test_index('/tmp/*', True) | |
57 | |
58 #MULTIPLE DB configs | |
59 # Setup the SQLAlchemy database engine | |
60 if config['debug'] and not test: | |
61 #use query time debugging. | |
62 from rhodecode.lib.timerproxy import TimerProxy | |
63 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.', | |
64 proxy=TimerProxy()) | |
65 else: | |
66 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') | |
67 | |
68 init_model(sa_engine_db1) | |
69 #init baseui | |
70 config['pylons.app_globals'].baseui = make_ui('db') | |
71 | |
72 repo2db_mapper(_get_repos_cached_initial(config['pylons.app_globals'], initial)) | |
73 set_available_permissions(config) | |
74 set_base_path(config) | |
75 set_hg_app_config(config) | |
76 # CONFIGURATION OPTIONS HERE (note: all config options will override | |
77 # any Pylons config options) | |
78 | |
79 return config |