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