Mercurial > kallithea
annotate rhodecode/config/environment.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl
old style: show the full link box on summary page - no overlap or truncation
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 02 Jul 2014 19:03:23 -0400 |
parents | ffd45b185016 |
children | 7e5f8c12a3fc |
rev | line source |
---|---|
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
1 # -*- coding: utf-8 -*- |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
5 # (at your option) any later version. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
6 # |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
10 # GNU General Public License for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
11 # |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
14 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
15 Pylons environment configuration |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
16 """ |
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
|
17 |
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
|
18 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
|
19 import logging |
2109 | 20 import rhodecode |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
21 import platform |
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
|
22 |
0 | 23 from mako.lookup import TemplateLookup |
43 | 24 from pylons.configuration import PylonsConfig |
0 | 25 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
|
26 |
2109 | 27 # don't remove this import it does magic for celery |
28 from rhodecode.lib import celerypylons | |
29 | |
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
|
30 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
|
31 |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
491
diff
changeset
|
32 from rhodecode.config.routing import make_map |
2109 | 33 |
34 from rhodecode.lib import helpers | |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1018
diff
changeset
|
35 from rhodecode.lib.auth import set_available_permissions |
2109 | 36 from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config,\ |
3797
d7488551578e
synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents:
3778
diff
changeset
|
37 load_rcextensions, check_git_version, set_vcs_config |
2109 | 38 from rhodecode.lib.utils2 import engine_from_config, str2bool |
3232
99c093d1a142
run waitress check on startup
Marcin Kuzminski <marcin@python-works.com>
parents:
2890
diff
changeset
|
39 from rhodecode.lib.db_manage import DbManage |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
491
diff
changeset
|
40 from rhodecode.model import init_model |
691
7486da5f0628
Refactor codes for scm model
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
41 from rhodecode.model.scm import ScmModel |
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
|
42 |
0 | 43 log = logging.getLogger(__name__) |
44 | |
1205
f4807acf643d
added __license__ into main of rhodecode, PEP8ify
Marcin Kuzminski <marcin@python-works.com>
parents:
1036
diff
changeset
|
45 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
46 def load_environment(global_conf, app_conf, initial=False, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
47 test_env=None, test_index=None): |
2109 | 48 """ |
49 Configure the Pylons environment via the ``pylons.config`` | |
0 | 50 object |
51 """ | |
43 | 52 config = PylonsConfig() |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
53 |
0 | 54 # Pylons paths |
55 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
2109 | 56 paths = dict( |
57 root=root, | |
58 controllers=os.path.join(root, 'controllers'), | |
59 static_files=os.path.join(root, 'public'), | |
60 templates=[os.path.join(root, 'templates')] | |
61 ) | |
0 | 62 |
63 # Initialize config with the basic options | |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
491
diff
changeset
|
64 config.init_app(global_conf, app_conf, package='rhodecode', paths=paths) |
0 | 65 |
1726
fe8c2e881403
moved pylons config out of global scope for celerypylons
Marcin Kuzminski <marcin@python-works.com>
parents:
1725
diff
changeset
|
66 # 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
|
67 rhodecode.CELERY_ON = str2bool(config['app_conf'].get('use_celery')) |
2299
e2dbdaf13562
Don't clear dbsessions when celery_eager is turned on
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
68 rhodecode.CELERY_EAGER = str2bool(config['app_conf'].get('celery.always.eager')) |
1723
64e91067b996
- refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
69 |
43 | 70 config['routes.map'] = make_map(config) |
71 config['pylons.app_globals'] = app_globals.Globals(config) | |
2109 | 72 config['pylons.h'] = 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
|
73 rhodecode.CONFIG = config |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
2016
diff
changeset
|
74 |
2109 | 75 load_rcextensions(root_path=config['here']) |
76 | |
43 | 77 # Setup cache object as early as possible |
78 import pylons | |
79 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
|
80 |
0 | 81 # 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
|
82 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
|
83 directories=paths['templates'], |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
84 error_handler=handle_mako_error, |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
85 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
|
86 input_encoding='utf-8', default_filters=['escape'], |
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
32
diff
changeset
|
87 imports=['from webhelpers.html import escape']) |
0 | 88 |
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
|
89 # 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
|
90 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
|
91 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
|
92 if test: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
93 if test_env is None: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
94 test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
95 if test_index is None: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
96 test_index = not int(os.environ.get('RC_WHOOSH_TEST_DISABLE', 0)) |
2560
380d6d86da1f
Added option to swap the db connection uri based on ENV TEST_DB string
Marcin Kuzminski <marcin@python-works.com>
parents:
2299
diff
changeset
|
97 if os.environ.get('TEST_DB'): |
380d6d86da1f
Added option to swap the db connection uri based on ENV TEST_DB string
Marcin Kuzminski <marcin@python-works.com>
parents:
2299
diff
changeset
|
98 # swap config if we pass enviroment variable |
380d6d86da1f
Added option to swap the db connection uri based on ENV TEST_DB string
Marcin Kuzminski <marcin@python-works.com>
parents:
2299
diff
changeset
|
99 config['sqlalchemy.db1.url'] = os.environ.get('TEST_DB') |
380d6d86da1f
Added option to swap the db connection uri based on ENV TEST_DB string
Marcin Kuzminski <marcin@python-works.com>
parents:
2299
diff
changeset
|
100 |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
491
diff
changeset
|
101 from rhodecode.lib.utils import create_test_env, create_test_index |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
102 from rhodecode.tests import TESTS_TMP_PATH |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
103 #set RC_NO_TMP_PATH=1 to disable re-creating the database and |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
104 #test repos |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
105 if test_env: |
2752
6d904a0cd48d
added new suite of tests for VCS operations
Marcin Kuzminski <marcin@python-works.com>
parents:
2683
diff
changeset
|
106 create_test_env(TESTS_TMP_PATH, config) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
107 #set RC_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
108 if test_index: |
2683
eaf1782bee64
add option to disable whoosh index in tests via an enviroment variable.
Marcin Kuzminski <marcin@python-works.com>
parents:
2637
diff
changeset
|
109 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
|
110 |
3232
99c093d1a142
run waitress check on startup
Marcin Kuzminski <marcin@python-works.com>
parents:
2890
diff
changeset
|
111 DbManage.check_waitress() |
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
|
112 # MULTIPLE DB configs |
43 | 113 # 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
|
114 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') |
49
3ada2f409c1c
Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents:
43
diff
changeset
|
115 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
|
116 |
3832
07f8039ef090
Use repo-scann at latest possible state.
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
117 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
|
118 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
|
119 config['base_path'] = repos_path |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
120 set_rhodecode_config(config) |
3650
76ae40e514eb
config: automatically assign instance_id for host and process if it has been set to *
Mads Kiilerich <madski@unity3d.com>
parents:
3232
diff
changeset
|
121 |
76ae40e514eb
config: automatically assign instance_id for host and process if it has been set to *
Mads Kiilerich <madski@unity3d.com>
parents:
3232
diff
changeset
|
122 instance_id = rhodecode.CONFIG.get('instance_id') |
76ae40e514eb
config: automatically assign instance_id for host and process if it has been set to *
Mads Kiilerich <madski@unity3d.com>
parents:
3232
diff
changeset
|
123 if instance_id == '*': |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3960
diff
changeset
|
124 instance_id = '%s-%s' % (platform.uname()[1], os.getpid()) |
3650
76ae40e514eb
config: automatically assign instance_id for host and process if it has been set to *
Mads Kiilerich <madski@unity3d.com>
parents:
3232
diff
changeset
|
125 rhodecode.CONFIG['instance_id'] = instance_id |
76ae40e514eb
config: automatically assign instance_id for host and process if it has been set to *
Mads Kiilerich <madski@unity3d.com>
parents:
3232
diff
changeset
|
126 |
0 | 127 # CONFIGURATION OPTIONS HERE (note: all config options will override |
128 # 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
|
129 |
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
|
130 # 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
|
131 # 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
|
132 rhodecode.CONFIG.update(config) |
3832
07f8039ef090
Use repo-scann at latest possible state.
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
133 set_vcs_config(rhodecode.CONFIG) |
3797
d7488551578e
synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents:
3778
diff
changeset
|
134 |
3832
07f8039ef090
Use repo-scann at latest possible state.
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
135 #check git version |
07f8039ef090
Use repo-scann at latest possible state.
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
136 check_git_version() |
07f8039ef090
Use repo-scann at latest possible state.
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
137 |
07f8039ef090
Use repo-scann at latest possible state.
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
138 if str2bool(config.get('initial_repo_scan', True)): |
07f8039ef090
Use repo-scann at latest possible state.
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
139 repo2db_mapper(ScmModel().repo_scan(repos_path), |
07f8039ef090
Use repo-scann at latest possible state.
Marcin Kuzminski <marcin@python-works.com>
parents:
3797
diff
changeset
|
140 remove_obsolete=False, install_git_hook=False) |
43 | 141 return config |