##// END OF EJS Templates
reverted whoosh for tests
marcink -
r1725:2370fc2a 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 our main isntance
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
General Comments 0
You need to be logged in to leave comments. Login now