##// END OF EJS Templates
i18n: make sure 'en' in Accept-Language is recognized as having 100% coverage...
Mads Kiilerich -
r8766:84b4fc9d stable
parent child Browse files
Show More
@@ -1,165 +1,169 b''
1 1 # -*- coding: utf-8 -*-
2 2 # This program is free software: you can redistribute it and/or modify
3 3 # it under the terms of the GNU General Public License as published by
4 4 # the Free Software Foundation, either version 3 of the License, or
5 5 # (at your option) any later version.
6 6 #
7 7 # This program is distributed in the hope that it will be useful,
8 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 # GNU General Public License for more details.
11 11 #
12 12 # You should have received a copy of the GNU General Public License
13 13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 14 """
15 15 Global configuration file for TurboGears2 specific settings in Kallithea.
16 16
17 17 This file complements the .ini file.
18 18 """
19 19
20 20 import logging
21 21 import os
22 22 import platform
23 23 import sys
24 24
25 25 import alembic.config
26 26 import mercurial
27 27 import tg
28 28 from alembic.migration import MigrationContext
29 29 from alembic.script.base import ScriptDirectory
30 30 from sqlalchemy import create_engine
31 31 from tg import FullStackApplicationConfigurator
32 32
33 33 import kallithea.lib.locales
34 34 import kallithea.model.base
35 35 import kallithea.model.meta
36 36 from kallithea.lib import celery_app
37 37 from kallithea.lib.utils import load_extensions, set_app_settings, set_indexer_config, set_vcs_config
38 38 from kallithea.lib.utils2 import asbool, check_git_version
39 39 from kallithea.model import db
40 40
41 41
42 42 log = logging.getLogger(__name__)
43 43
44 44
45 45 base_config = FullStackApplicationConfigurator()
46 46
47 47 base_config.update_blueprint({
48 48 'package': kallithea,
49 49
50 50 # Rendering Engines Configuration
51 51 'renderers': [
52 52 'json',
53 53 'mako',
54 54 ],
55 55 'default_renderer': 'mako',
56 56 'use_dotted_templatenames': False,
57 57
58 58 # Configure Sessions, store data as JSON to avoid pickle security issues
59 59 'session.enabled': True,
60 60 'session.data_serializer': 'json',
61 61
62 62 # Configure the base SQLALchemy Setup
63 63 'use_sqlalchemy': True,
64 64 'model': kallithea.model.base,
65 65 'DBSession': kallithea.model.meta.Session,
66 66
67 67 # Configure App without an authentication backend.
68 68 'auth_backend': None,
69 69
70 70 # Use custom error page for these errors. By default, Turbogears2 does not add
71 71 # 400 in this list.
72 72 # Explicitly listing all is considered more robust than appending to defaults,
73 73 # in light of possible future framework changes.
74 74 'errorpage.status_codes': [400, 401, 403, 404],
75 75
76 76 # Disable transaction manager -- currently Kallithea takes care of transactions itself
77 77 'tm.enabled': False,
78 78
79 79 # Set the default i18n source language so TG doesn't search beyond 'en' in Accept-Language.
80 80 'i18n.lang': 'en',
81
82 # For TurboGears 2.4.3, define the native language for translations to
83 # prevent fall-through to languages requested with lower priority.
84 'i18n.native': ['en', 'en_US', 'en_GB'],
81 85 })
82 86
83 87 # DebugBar, a debug toolbar for TurboGears2.
84 88 # (https://github.com/TurboGears/tgext.debugbar)
85 89 # To enable it, install 'tgext.debugbar' and 'kajiki', and run Kallithea with
86 90 # 'debug = true' (not in production!)
87 91 # See the Kallithea documentation for more information.
88 92 try:
89 93 import kajiki # only to check its existence
90 94 from tgext.debugbar import enable_debugbar
91 95 assert kajiki
92 96 except ImportError:
93 97 pass
94 98 else:
95 99 base_config.get_blueprint_value('renderers').append('kajiki')
96 100 enable_debugbar(base_config)
97 101
98 102
99 103 def setup_configuration(app):
100 104 config = app.config
101 105
102 106 if not kallithea.lib.locales.current_locale_is_valid():
103 107 log.error("Terminating ...")
104 108 sys.exit(1)
105 109
106 110 # Mercurial sets encoding at module import time, so we have to monkey patch it
107 111 hgencoding = config.get('hgencoding')
108 112 if hgencoding:
109 113 mercurial.encoding.encoding = hgencoding
110 114
111 115 if config.get('ignore_alembic_revision', False):
112 116 log.warning('database alembic revision checking is disabled')
113 117 else:
114 118 dbconf = config['sqlalchemy.url']
115 119 alembic_cfg = alembic.config.Config()
116 120 alembic_cfg.set_main_option('script_location', 'kallithea:alembic')
117 121 alembic_cfg.set_main_option('sqlalchemy.url', dbconf)
118 122 script_dir = ScriptDirectory.from_config(alembic_cfg)
119 123 available_heads = sorted(script_dir.get_heads())
120 124
121 125 engine = create_engine(dbconf)
122 126 with engine.connect() as conn:
123 127 context = MigrationContext.configure(conn)
124 128 current_heads = sorted(str(s) for s in context.get_current_heads())
125 129 if current_heads != available_heads:
126 130 log.error('Failed to run Kallithea:\n\n'
127 131 'The database version does not match the Kallithea version.\n'
128 132 'Please read the documentation on how to upgrade or downgrade the database.\n'
129 133 'Current database version id(s): %s\n'
130 134 'Expected database version id(s): %s\n'
131 135 'If you are a developer and you know what you are doing, you can add `ignore_alembic_revision = True` '
132 136 'to your .ini file to skip the check.\n' % (' '.join(current_heads), ' '.join(available_heads)))
133 137 sys.exit(1)
134 138
135 139 # store some globals into kallithea
136 140 kallithea.DEFAULT_USER_ID = db.User.get_default_user().user_id
137 141
138 142 if asbool(config.get('use_celery')) and not kallithea.CELERY_APP.finalized:
139 143 kallithea.CELERY_APP.config_from_object(celery_app.make_celery_config(config))
140 144 kallithea.CONFIG = config
141 145
142 146 load_extensions(root_path=config['here'])
143 147
144 148 set_app_settings(config)
145 149
146 150 instance_id = kallithea.CONFIG.get('instance_id', '*')
147 151 if instance_id == '*':
148 152 instance_id = '%s-%s' % (platform.uname()[1], os.getpid())
149 153 kallithea.CONFIG['instance_id'] = instance_id
150 154
151 155 # update kallithea.CONFIG with the meanwhile changed 'config'
152 156 kallithea.CONFIG.update(config)
153 157
154 158 # configure vcs and indexer libraries (they are supposed to be independent
155 159 # as much as possible and thus avoid importing tg.config or
156 160 # kallithea.CONFIG).
157 161 set_vcs_config(kallithea.CONFIG)
158 162 set_indexer_config(kallithea.CONFIG)
159 163
160 164 check_git_version()
161 165
162 166 kallithea.model.meta.Session.remove()
163 167
164 168
165 169 tg.hooks.register('configure_new_app', setup_configuration)
General Comments 0
You need to be logged in to leave comments. Login now