Mercurial > kallithea
annotate rhodecode/config/environment.py @ 2105:926f55b038bc beta
added initial rc-extension module
- possible to store additional mappings for stats
- possible to overwrite and add to whoosh index extensions
issue #322
- post create repo hook callback
- post push/pull hooks callback
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 06 Mar 2012 23:03:10 +0200 |
parents | 6020e3884a58 |
children | 3ed6b94030ae |
rev | line source |
---|---|
0 | 1 """Pylons environment configuration""" |
1006
02246101c846
moved out celerypylons import to enviromnet to prevent celery from displaying celeryconfig.py warning
Marcin Kuzminski <marcin@python-works.com>
parents:
760
diff
changeset
|
2 |
02246101c846
moved out celerypylons import to enviromnet to prevent celery from displaying celeryconfig.py warning
Marcin Kuzminski <marcin@python-works.com>
parents:
760
diff
changeset
|
3 import os |
02246101c846
moved out celerypylons import to enviromnet to prevent celery from displaying celeryconfig.py warning
Marcin Kuzminski <marcin@python-works.com>
parents:
760
diff
changeset
|
4 import logging |
02246101c846
moved out celerypylons import to enviromnet to prevent celery from displaying celeryconfig.py warning
Marcin Kuzminski <marcin@python-works.com>
parents:
760
diff
changeset
|
5 |
0 | 6 from mako.lookup import TemplateLookup |
43 | 7 from pylons.configuration import PylonsConfig |
0 | 8 from pylons.error import handle_mako_error |
1006
02246101c846
moved out celerypylons import to enviromnet to prevent celery from displaying celeryconfig.py warning
Marcin Kuzminski <marcin@python-works.com>
parents:
760
diff
changeset
|
9 |
1723
64e91067b996
- refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
10 import rhodecode |
1006
02246101c846
moved out celerypylons import to enviromnet to prevent celery from displaying celeryconfig.py warning
Marcin Kuzminski <marcin@python-works.com>
parents:
760
diff
changeset
|
11 import rhodecode.lib.app_globals as app_globals |
02246101c846
moved out celerypylons import to enviromnet to prevent celery from displaying celeryconfig.py warning
Marcin Kuzminski <marcin@python-works.com>
parents:
760
diff
changeset
|
12 import rhodecode.lib.helpers |
02246101c846
moved out celerypylons import to enviromnet to prevent celery from displaying celeryconfig.py warning
Marcin Kuzminski <marcin@python-works.com>
parents:
760
diff
changeset
|
13 |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
491
diff
changeset
|
14 from rhodecode.config.routing import make_map |
1723
64e91067b996
- refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
15 # don't remove this import it does magic for celery |
64e91067b996
- refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
16 from rhodecode.lib import celerypylons, str2bool |
1300
882ac77dc709
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
Marcin Kuzminski <marcin@python-works.com>
parents:
1205
diff
changeset
|
17 from rhodecode.lib import engine_from_config |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1018
diff
changeset
|
18 from rhodecode.lib.auth import set_available_permissions |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
19 from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
491
diff
changeset
|
20 from rhodecode.model import init_model |
691
7486da5f0628
Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
21 from rhodecode.model.scm import ScmModel |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
2016
diff
changeset
|
22 from rhodecode.lib.vcs.utils.fakemod import create_module |
239
b18f89d6d17f
Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents:
107
diff
changeset
|
23 |
0 | 24 log = logging.getLogger(__name__) |
25 | |
1205
f4807acf643d
added __license__ into main of rhodecode, PEP8ify
Marcin Kuzminski <marcin@python-works.com>
parents:
1036
diff
changeset
|
26 |
365
ec7b76d4bda4
Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
27 def load_environment(global_conf, app_conf, initial=False): |
0 | 28 """Configure the Pylons environment via the ``pylons.config`` |
29 object | |
30 """ | |
43 | 31 config = PylonsConfig() |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
32 |
0 | 33 # Pylons paths |
34 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
35 paths = dict(root=root, |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
36 controllers=os.path.join(root, 'controllers'), |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
37 static_files=os.path.join(root, 'public'), |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
38 templates=[os.path.join(root, 'templates')]) |
0 | 39 |
40 # Initialize config with the basic options | |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
491
diff
changeset
|
41 config.init_app(global_conf, app_conf, package='rhodecode', paths=paths) |
0 | 42 |
1726
fe8c2e881403
moved pylons config out of global scope for celerypylons
Marcin Kuzminski <marcin@python-works.com>
parents:
1725
diff
changeset
|
43 # store some globals into rhodecode |
1723
64e91067b996
- refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
44 rhodecode.CELERY_ON = str2bool(config['app_conf'].get('use_celery')) |
64e91067b996
- refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
45 |
43 | 46 config['routes.map'] = make_map(config) |
47 config['pylons.app_globals'] = app_globals.Globals(config) | |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
491
diff
changeset
|
48 config['pylons.h'] = rhodecode.lib.helpers |
2016
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
1726
diff
changeset
|
49 rhodecode.CONFIG = config |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
2016
diff
changeset
|
50 |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
2016
diff
changeset
|
51 path = os.path.join(config['here'], 'rcextensions', '__init__.py') |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
2016
diff
changeset
|
52 if os.path.isfile(path): |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
2016
diff
changeset
|
53 rcext = create_module('rc', path) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
2016
diff
changeset
|
54 rhodecode.EXTENSIONS = rcext |
43 | 55 # Setup cache object as early as possible |
56 import pylons | |
57 pylons.cache._push_object(config['pylons.app_globals'].cache) | |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
58 |
0 | 59 # Create the Mako TemplateLookup, with the default auto-escaping |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
32
diff
changeset
|
60 config['pylons.app_globals'].mako_lookup = TemplateLookup( |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
61 directories=paths['templates'], |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
62 error_handler=handle_mako_error, |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
63 module_directory=os.path.join(app_conf['cache_dir'], 'templates'), |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
32
diff
changeset
|
64 input_encoding='utf-8', default_filters=['escape'], |
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
32
diff
changeset
|
65 imports=['from webhelpers.html import escape']) |
0 | 66 |
2016
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
1726
diff
changeset
|
67 # sets the c attribute access when don't existing attribute are accessed |
107
5e2470ebdbc6
Added repo switcher, in base and long term caching for this.
Marcin Kuzminski <marcin@python-works.com>
parents:
49
diff
changeset
|
68 config['pylons.strict_tmpl_context'] = True |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
69 test = os.path.split(config['__file__'])[-1] == 'test.ini' |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
469
diff
changeset
|
70 if test: |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
491
diff
changeset
|
71 from rhodecode.lib.utils import create_test_env, create_test_index |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
72 from rhodecode.tests import TESTS_TMP_PATH |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
73 create_test_env(TESTS_TMP_PATH, config) |
1725
2370fc2a04f2
reverted whoosh for tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1723
diff
changeset
|
74 create_test_index(TESTS_TMP_PATH, config, True) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
75 |
2016
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
1726
diff
changeset
|
76 # MULTIPLE DB configs |
43 | 77 # Setup the SQLAlchemy database engine |
1360
1f47adeb67c2
Bumped sqlalchemy version to 0.7, replaced timerproxy with new event system for sqlalchemy.
Marcin Kuzminski <marcin@python-works.com>
parents:
1300
diff
changeset
|
78 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') |
43 | 79 |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
80 init_model(sa_engine_db1) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
81 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1018
diff
changeset
|
82 repos_path = make_ui('db').configitems('paths')[0][1] |
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1018
diff
changeset
|
83 repo2db_mapper(ScmModel().repo_scan(repos_path)) |
239
b18f89d6d17f
Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents:
107
diff
changeset
|
84 set_available_permissions(config) |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1018
diff
changeset
|
85 config['base_path'] = repos_path |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
86 set_rhodecode_config(config) |
0 | 87 # CONFIGURATION OPTIONS HERE (note: all config options will override |
88 # any Pylons config options) | |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
89 |
2016
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
1726
diff
changeset
|
90 # store config reference into our module to skip import magic of |
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
1726
diff
changeset
|
91 # pylons |
6020e3884a58
implements #212 moved default encoding variable into rhodecode-config. It's now possible to change
Marcin Kuzminski <marcin@python-works.com>
parents:
1726
diff
changeset
|
92 rhodecode.CONFIG.update(config) |
43 | 93 return config |