##// END OF EJS Templates
backend: add TurboGears2 DebugBar support...
Thomas De Schampheleire -
r6524:908e186a default
parent child Browse files
Show More
@@ -1,227 +1,247 b''
1 .. _contributing:
1 .. _contributing:
2
2
3 =========================
3 =========================
4 Contributing to Kallithea
4 Contributing to Kallithea
5 =========================
5 =========================
6
6
7 Kallithea is developed and maintained by its users. Please join us and scratch
7 Kallithea is developed and maintained by its users. Please join us and scratch
8 your own itch.
8 your own itch.
9
9
10
10
11 Infrastructure
11 Infrastructure
12 --------------
12 --------------
13
13
14 The main repository is hosted on Our Own Kallithea (aka OOK) at
14 The main repository is hosted on Our Own Kallithea (aka OOK) at
15 https://kallithea-scm.org/repos/kallithea/, our self-hosted instance
15 https://kallithea-scm.org/repos/kallithea/, our self-hosted instance
16 of Kallithea.
16 of Kallithea.
17
17
18 For now, we use Bitbucket_ for `pull requests`_ and `issue tracking`_. The
18 For now, we use Bitbucket_ for `pull requests`_ and `issue tracking`_. The
19 issue tracker is for tracking bugs, not for support, discussion, or ideas --
19 issue tracker is for tracking bugs, not for support, discussion, or ideas --
20 please use the `mailing list`_ or :ref:`IRC <readme>` to reach the community.
20 please use the `mailing list`_ or :ref:`IRC <readme>` to reach the community.
21
21
22 We use Weblate_ to translate the user interface messages into languages other
22 We use Weblate_ to translate the user interface messages into languages other
23 than English. Join our project on `Hosted Weblate`_ to help us.
23 than English. Join our project on `Hosted Weblate`_ to help us.
24 To register, you can use your Bitbucket or GitHub account. See :ref:`translations`
24 To register, you can use your Bitbucket or GitHub account. See :ref:`translations`
25 for more details.
25 for more details.
26
26
27
27
28 Getting started
28 Getting started
29 ---------------
29 ---------------
30
30
31 To get started with development::
31 To get started with development::
32
32
33 hg clone https://kallithea-scm.org/repos/kallithea
33 hg clone https://kallithea-scm.org/repos/kallithea
34 cd kallithea
34 cd kallithea
35 virtualenv ../kallithea-venv
35 virtualenv ../kallithea-venv
36 source ../kallithea-venv/bin/activate
36 source ../kallithea-venv/bin/activate
37 pip install --upgrade pip setuptools
37 pip install --upgrade pip setuptools
38 pip install -e .
38 pip install -e .
39 gearbox make-config my.ini
39 gearbox make-config my.ini
40 gearbox setup-db -c my.ini --user=user --email=user@example.com --password=password --repos=/tmp
40 gearbox setup-db -c my.ini --user=user --email=user@example.com --password=password --repos=/tmp
41 gearbox serve -c my.ini --reload &
41 gearbox serve -c my.ini --reload &
42 firefox http://127.0.0.1:5000/
42 firefox http://127.0.0.1:5000/
43
43
44 You can also start out by forking https://bitbucket.org/conservancy/kallithea
44 You can also start out by forking https://bitbucket.org/conservancy/kallithea
45 on Bitbucket_ and create a local clone of your own fork.
45 on Bitbucket_ and create a local clone of your own fork.
46
46
47
47
48 Running tests
48 Running tests
49 -------------
49 -------------
50
50
51 After finishing your changes make sure all tests pass cleanly. Install the test
51 After finishing your changes make sure all tests pass cleanly. Install the test
52 dependencies, then run the testsuite by invoking ``py.test`` from the
52 dependencies, then run the testsuite by invoking ``py.test`` from the
53 project root::
53 project root::
54
54
55 pip install -r dev_requirements.txt
55 pip install -r dev_requirements.txt
56 py.test
56 py.test
57
57
58 Note that testing on Python 2.6 also requires ``unittest2``.
58 Note that testing on Python 2.6 also requires ``unittest2``.
59
59
60 You can also use ``tox`` to run the tests with all supported Python versions
60 You can also use ``tox`` to run the tests with all supported Python versions
61 (currently Python 2.6--2.7).
61 (currently Python 2.6--2.7).
62
62
63 When running tests, Kallithea uses `kallithea/tests/test.ini` and populates the
63 When running tests, Kallithea uses `kallithea/tests/test.ini` and populates the
64 SQLite database specified there.
64 SQLite database specified there.
65
65
66 It is possible to avoid recreating the full test database on each invocation of
66 It is possible to avoid recreating the full test database on each invocation of
67 the tests, thus eliminating the initial delay. To achieve this, run the tests as::
67 the tests, thus eliminating the initial delay. To achieve this, run the tests as::
68
68
69 gearbox serve -c kallithea/tests/test.ini --pid-file=test.pid --daemon
69 gearbox serve -c kallithea/tests/test.ini --pid-file=test.pid --daemon
70 KALLITHEA_WHOOSH_TEST_DISABLE=1 KALLITHEA_NO_TMP_PATH=1 py.test
70 KALLITHEA_WHOOSH_TEST_DISABLE=1 KALLITHEA_NO_TMP_PATH=1 py.test
71 kill -9 $(cat test.pid)
71 kill -9 $(cat test.pid)
72
72
73 In these commands, the following variables are used::
73 In these commands, the following variables are used::
74
74
75 KALLITHEA_WHOOSH_TEST_DISABLE=1 - skip whoosh index building and tests
75 KALLITHEA_WHOOSH_TEST_DISABLE=1 - skip whoosh index building and tests
76 KALLITHEA_NO_TMP_PATH=1 - disable new temp path for tests, used mostly for testing_vcs_operations
76 KALLITHEA_NO_TMP_PATH=1 - disable new temp path for tests, used mostly for testing_vcs_operations
77
77
78 You can run individual tests by specifying their path as argument to py.test.
78 You can run individual tests by specifying their path as argument to py.test.
79 py.test also has many more options, see `py.test -h`. Some useful options
79 py.test also has many more options, see `py.test -h`. Some useful options
80 are::
80 are::
81
81
82 -k EXPRESSION only run tests which match the given substring
82 -k EXPRESSION only run tests which match the given substring
83 expression. An expression is a python evaluable
83 expression. An expression is a python evaluable
84 expression where all names are substring-matched
84 expression where all names are substring-matched
85 against test names and their parent classes. Example:
85 against test names and their parent classes. Example:
86 -x, --exitfirst exit instantly on first error or failed test.
86 -x, --exitfirst exit instantly on first error or failed test.
87 --lf rerun only the tests that failed at the last run (or
87 --lf rerun only the tests that failed at the last run (or
88 all if none failed)
88 all if none failed)
89 --ff run all tests but run the last failures first. This
89 --ff run all tests but run the last failures first. This
90 may re-order tests and thus lead to repeated fixture
90 may re-order tests and thus lead to repeated fixture
91 setup/teardown
91 setup/teardown
92 --pdb start the interactive Python debugger on errors.
92 --pdb start the interactive Python debugger on errors.
93 -s, --capture=no don't capture stdout (any stdout output will be
93 -s, --capture=no don't capture stdout (any stdout output will be
94 printed immediately)
94 printed immediately)
95
95
96
96
97 Contribution guidelines
97 Contribution guidelines
98 -----------------------
98 -----------------------
99
99
100 Kallithea is GPLv3 and we assume all contributions are made by the
100 Kallithea is GPLv3 and we assume all contributions are made by the
101 committer/contributor and under GPLv3 unless explicitly stated. We do care a
101 committer/contributor and under GPLv3 unless explicitly stated. We do care a
102 lot about preservation of copyright and license information for existing code
102 lot about preservation of copyright and license information for existing code
103 that is brought into the project.
103 that is brought into the project.
104
104
105 Contributions will be accepted in most formats -- such as pull requests on
105 Contributions will be accepted in most formats -- such as pull requests on
106 Bitbucket, something hosted on your own Kallithea instance, or patches sent by
106 Bitbucket, something hosted on your own Kallithea instance, or patches sent by
107 email to the `kallithea-general`_ mailing list.
107 email to the `kallithea-general`_ mailing list.
108
108
109 When contributing via Bitbucket, please make your fork of
109 When contributing via Bitbucket, please make your fork of
110 https://bitbucket.org/conservancy/kallithea/ `non-publishing`_ -- it is one of
110 https://bitbucket.org/conservancy/kallithea/ `non-publishing`_ -- it is one of
111 the settings on "Repository details" page. This ensures your commits are in
111 the settings on "Repository details" page. This ensures your commits are in
112 "draft" phase and makes it easier for you to address feedback and for project
112 "draft" phase and makes it easier for you to address feedback and for project
113 maintainers to integrate your changes.
113 maintainers to integrate your changes.
114
114
115 .. _non-publishing: https://www.mercurial-scm.org/wiki/Phases#Publishing_Repository
115 .. _non-publishing: https://www.mercurial-scm.org/wiki/Phases#Publishing_Repository
116
116
117 Make sure to test your changes both manually and with the automatic tests
117 Make sure to test your changes both manually and with the automatic tests
118 before posting.
118 before posting.
119
119
120 We care about quality and review and keeping a clean repository history. We
120 We care about quality and review and keeping a clean repository history. We
121 might give feedback that requests polishing contributions until they are
121 might give feedback that requests polishing contributions until they are
122 "perfect". We might also rebase and collapse and make minor adjustments to your
122 "perfect". We might also rebase and collapse and make minor adjustments to your
123 changes when we apply them.
123 changes when we apply them.
124
124
125 We try to make sure we have consensus on the direction the project is taking.
125 We try to make sure we have consensus on the direction the project is taking.
126 Everything non-sensitive should be discussed in public -- preferably on the
126 Everything non-sensitive should be discussed in public -- preferably on the
127 mailing list. We aim at having all non-trivial changes reviewed by at least
127 mailing list. We aim at having all non-trivial changes reviewed by at least
128 one other core developer before pushing. Obvious non-controversial changes will
128 one other core developer before pushing. Obvious non-controversial changes will
129 be handled more casually.
129 be handled more casually.
130
130
131 For now we just have one official branch ("default") and will keep it so stable
131 For now we just have one official branch ("default") and will keep it so stable
132 that it can be (and is) used in production. Experimental changes should live
132 that it can be (and is) used in production. Experimental changes should live
133 elsewhere (for example in a pull request) until they are ready.
133 elsewhere (for example in a pull request) until they are ready.
134
134
135
135
136 Coding guidelines
136 Coding guidelines
137 -----------------
137 -----------------
138
138
139 We don't have a formal coding/formatting standard. We are currently using a mix
139 We don't have a formal coding/formatting standard. We are currently using a mix
140 of Mercurial's (https://www.mercurial-scm.org/wiki/CodingStyle), pep8, and
140 of Mercurial's (https://www.mercurial-scm.org/wiki/CodingStyle), pep8, and
141 consistency with existing code. Run ``scripts/run-all-cleanup`` before
141 consistency with existing code. Run ``scripts/run-all-cleanup`` before
142 committing to ensure some basic code formatting consistency.
142 committing to ensure some basic code formatting consistency.
143
143
144 We support both Python 2.6.x and 2.7.x and nothing else. For now we don't care
144 We support both Python 2.6.x and 2.7.x and nothing else. For now we don't care
145 about Python 3 compatibility.
145 about Python 3 compatibility.
146
146
147 We try to support the most common modern web browsers. IE9 is still supported
147 We try to support the most common modern web browsers. IE9 is still supported
148 to the extent it is feasible, IE8 is not.
148 to the extent it is feasible, IE8 is not.
149
149
150 We primarily support Linux and OS X on the server side but Windows should also work.
150 We primarily support Linux and OS X on the server side but Windows should also work.
151
151
152 HTML templates should use 2 spaces for indentation ... but be pragmatic. We
152 HTML templates should use 2 spaces for indentation ... but be pragmatic. We
153 should use templates cleverly and avoid duplication. We should use reasonable
153 should use templates cleverly and avoid duplication. We should use reasonable
154 semantic markup with element classes and IDs that can be used for styling and testing.
154 semantic markup with element classes and IDs that can be used for styling and testing.
155 We should only use inline styles in places where it really is semantic (such as
155 We should only use inline styles in places where it really is semantic (such as
156 ``display: none``).
156 ``display: none``).
157
157
158 JavaScript must use ``;`` between/after statements. Indentation 4 spaces. Inline
158 JavaScript must use ``;`` between/after statements. Indentation 4 spaces. Inline
159 multiline functions should be indented two levels -- one for the ``()`` and one for
159 multiline functions should be indented two levels -- one for the ``()`` and one for
160 ``{}``.
160 ``{}``.
161 Variables holding jQuery objects should be named with a leading ``$``.
161 Variables holding jQuery objects should be named with a leading ``$``.
162
162
163 Commit messages should have a leading short line summarizing the changes. For
163 Commit messages should have a leading short line summarizing the changes. For
164 bug fixes, put ``(Issue #123)`` at the end of this line.
164 bug fixes, put ``(Issue #123)`` at the end of this line.
165
165
166 Use American English grammar and spelling overall. Use `English title case`_ for
166 Use American English grammar and spelling overall. Use `English title case`_ for
167 page titles, button labels, headers, and 'labels' for fields in forms.
167 page titles, button labels, headers, and 'labels' for fields in forms.
168
168
169 .. _English title case: https://en.wikipedia.org/wiki/Capitalization#Title_case
169 .. _English title case: https://en.wikipedia.org/wiki/Capitalization#Title_case
170
170
171 Template helpers (that is, everything in ``kallithea.lib.helpers``)
171 Template helpers (that is, everything in ``kallithea.lib.helpers``)
172 should only be referenced from templates. If you need to call a
172 should only be referenced from templates. If you need to call a
173 helper from the Python code, consider moving the function somewhere
173 helper from the Python code, consider moving the function somewhere
174 else (e.g. to the model).
174 else (e.g. to the model).
175
175
176 Notes on the SQLAlchemy session
176 Notes on the SQLAlchemy session
177 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
177 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
178
178
179 Each HTTP request runs inside an independent SQLAlchemy session (as well
179 Each HTTP request runs inside an independent SQLAlchemy session (as well
180 as in an independent database transaction). Database model objects
180 as in an independent database transaction). Database model objects
181 (almost) always belong to a particular SQLAlchemy session, which means
181 (almost) always belong to a particular SQLAlchemy session, which means
182 that SQLAlchemy will ensure that they're kept in sync with the database
182 that SQLAlchemy will ensure that they're kept in sync with the database
183 (but also means that they cannot be shared across requests).
183 (but also means that they cannot be shared across requests).
184
184
185 Objects can be added to the session using ``Session().add``, but this is
185 Objects can be added to the session using ``Session().add``, but this is
186 rarely needed:
186 rarely needed:
187
187
188 * When creating a database object by calling the constructor directly,
188 * When creating a database object by calling the constructor directly,
189 it must explicitly be added to the session.
189 it must explicitly be added to the session.
190
190
191 * When creating an object using a factory function (like
191 * When creating an object using a factory function (like
192 ``create_repo``), the returned object has already (by convention)
192 ``create_repo``), the returned object has already (by convention)
193 been added to the session, and should not be added again.
193 been added to the session, and should not be added again.
194
194
195 * When getting an object from the session (via ``Session().query`` or
195 * When getting an object from the session (via ``Session().query`` or
196 any of the utility functions that look up objects in the database),
196 any of the utility functions that look up objects in the database),
197 it's already part of the session, and should not be added again.
197 it's already part of the session, and should not be added again.
198 SQLAlchemy monitors attribute modifications automatically for all
198 SQLAlchemy monitors attribute modifications automatically for all
199 objects it knows about and syncs them to the database.
199 objects it knows about and syncs them to the database.
200
200
201 SQLAlchemy also flushes changes to the database automatically; manually
201 SQLAlchemy also flushes changes to the database automatically; manually
202 calling ``Session().flush`` is usually only necessary when the Python
202 calling ``Session().flush`` is usually only necessary when the Python
203 code needs the database to assign an "auto-increment" primary key ID to
203 code needs the database to assign an "auto-increment" primary key ID to
204 a freshly created model object (before flushing, the ID attribute will
204 a freshly created model object (before flushing, the ID attribute will
205 be ``None``).
205 be ``None``).
206
206
207 TurboGears2 DebugBar
208 ^^^^^^^^^^^^^^^^^^^^
209
210 It is possible to enable the TurboGears2-provided DebugBar_, a toolbar overlayed
211 over the Kallithea web interface, allowing you to see:
212
213 * timing information of the current request, including profiling information
214 * request data, including GET data, POST data, cookies, headers and environment
215 variables
216 * a list of executed database queries, including timing and result values
217
218 DebugBar is only activated when ``debug = true`` is set in the configuration
219 file. This is important, because the DebugBar toolbar will be visible for all
220 users, and allow them to see information they should not be allowed to see. Like
221 is anyway the case for ``debug = true``, do not use this in production!
222
223 To enable DebugBar, install ``tgext.debugbar`` and ``kajiki`` (typically via
224 ``pip``) and restart Kallithea (in debug mode).
225
207
226
208 "Roadmap"
227 "Roadmap"
209 ---------
228 ---------
210
229
211 We do not have a road map but are waiting for your contributions. Refer to the
230 We do not have a road map but are waiting for your contributions. Refer to the
212 wiki_ for some ideas of places we might want to go -- contributions in these
231 wiki_ for some ideas of places we might want to go -- contributions in these
213 areas are very welcome.
232 areas are very welcome.
214
233
215
234
216 Thank you for your contribution!
235 Thank you for your contribution!
217 --------------------------------
236 --------------------------------
218
237
219
238
220 .. _Weblate: http://weblate.org/
239 .. _Weblate: http://weblate.org/
221 .. _issue tracking: https://bitbucket.org/conservancy/kallithea/issues?status=new&status=open
240 .. _issue tracking: https://bitbucket.org/conservancy/kallithea/issues?status=new&status=open
222 .. _pull requests: https://bitbucket.org/conservancy/kallithea/pull-requests
241 .. _pull requests: https://bitbucket.org/conservancy/kallithea/pull-requests
223 .. _bitbucket: http://bitbucket.org/
242 .. _bitbucket: http://bitbucket.org/
224 .. _mailing list: http://lists.sfconservancy.org/mailman/listinfo/kallithea-general
243 .. _mailing list: http://lists.sfconservancy.org/mailman/listinfo/kallithea-general
225 .. _kallithea-general: http://lists.sfconservancy.org/mailman/listinfo/kallithea-general
244 .. _kallithea-general: http://lists.sfconservancy.org/mailman/listinfo/kallithea-general
226 .. _Hosted Weblate: https://hosted.weblate.org/projects/kallithea/kallithea/
245 .. _Hosted Weblate: https://hosted.weblate.org/projects/kallithea/kallithea/
227 .. _wiki: https://bitbucket.org/conservancy/kallithea/wiki/Home
246 .. _wiki: https://bitbucket.org/conservancy/kallithea/wiki/Home
247 .. _DebugBar: https://github.com/TurboGears/tgext.debugbar
@@ -1,175 +1,190 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # This program is free software: you can redistribute it and/or modify
2 # This program is free software: you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation, either version 3 of the License, or
4 # the Free Software Foundation, either version 3 of the License, or
5 # (at your option) any later version.
5 # (at your option) any later version.
6 #
6 #
7 # This program is distributed in the hope that it will be useful,
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
10 # GNU General Public License for more details.
11 #
11 #
12 # You should have received a copy of the GNU General Public License
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """
14 """
15 Global configuration file for TurboGears2 specific settings in Kallithea.
15 Global configuration file for TurboGears2 specific settings in Kallithea.
16
16
17 This file complements the .ini file.
17 This file complements the .ini file.
18 """
18 """
19
19
20 import platform
20 import platform
21 import os, sys
21 import os, sys
22
22
23 import tg
23 import tg
24 from tg import hooks
24 from tg import hooks
25 from tg.configuration import AppConfig
25 from tg.configuration import AppConfig
26 from tg.support.converters import asbool
26 from tg.support.converters import asbool
27
27
28 from kallithea.lib.middleware.https_fixup import HttpsFixup
28 from kallithea.lib.middleware.https_fixup import HttpsFixup
29 from kallithea.lib.middleware.simplegit import SimpleGit
29 from kallithea.lib.middleware.simplegit import SimpleGit
30 from kallithea.lib.middleware.simplehg import SimpleHg
30 from kallithea.lib.middleware.simplehg import SimpleHg
31 from kallithea.config.routing import make_map
31 from kallithea.config.routing import make_map
32 from kallithea.lib.auth import set_available_permissions
32 from kallithea.lib.auth import set_available_permissions
33 from kallithea.lib.db_manage import DbManage
33 from kallithea.lib.db_manage import DbManage
34 from kallithea.lib.utils import load_rcextensions, make_ui, set_app_settings, set_vcs_config, \
34 from kallithea.lib.utils import load_rcextensions, make_ui, set_app_settings, set_vcs_config, \
35 set_indexer_config, check_git_version, repo2db_mapper
35 set_indexer_config, check_git_version, repo2db_mapper
36 from kallithea.lib.utils2 import str2bool
36 from kallithea.lib.utils2 import str2bool
37 from kallithea.model.scm import ScmModel
37 from kallithea.model.scm import ScmModel
38
38
39 import formencode
39 import formencode
40 import kallithea
40 import kallithea
41
41
42
42
43 class KallitheaAppConfig(AppConfig):
43 class KallitheaAppConfig(AppConfig):
44 # Note: AppConfig has a misleading name, as it's not the application
44 # Note: AppConfig has a misleading name, as it's not the application
45 # configuration, but the application configurator. The AppConfig values are
45 # configuration, but the application configurator. The AppConfig values are
46 # used as a template to create the actual configuration, which might
46 # used as a template to create the actual configuration, which might
47 # overwrite or extend the one provided by the configurator template.
47 # overwrite or extend the one provided by the configurator template.
48
48
49 # To make it clear, AppConfig creates the config and sets into it the same
49 # To make it clear, AppConfig creates the config and sets into it the same
50 # values that AppConfig itself has. Then the values from the config file and
50 # values that AppConfig itself has. Then the values from the config file and
51 # gearbox options are loaded and merged into the configuration. Then an
51 # gearbox options are loaded and merged into the configuration. Then an
52 # after_init_config(conf) method of AppConfig is called for any change that
52 # after_init_config(conf) method of AppConfig is called for any change that
53 # might depend on options provided by configuration files.
53 # might depend on options provided by configuration files.
54
54
55 def __init__(self):
55 def __init__(self):
56 super(KallitheaAppConfig, self).__init__()
56 super(KallitheaAppConfig, self).__init__()
57
57
58 self['package'] = kallithea
58 self['package'] = kallithea
59
59
60 self['prefer_toscawidgets2'] = False
60 self['prefer_toscawidgets2'] = False
61 self['use_toscawidgets'] = False
61 self['use_toscawidgets'] = False
62
62
63 self['renderers'] = []
63 self['renderers'] = []
64
64
65 # Enable json in expose
65 # Enable json in expose
66 self['renderers'].append('json')
66 self['renderers'].append('json')
67
67
68 # Configure template rendering
68 # Configure template rendering
69 self['renderers'].append('mako')
69 self['renderers'].append('mako')
70 self['default_renderer'] = 'mako'
70 self['default_renderer'] = 'mako'
71 self['use_dotted_templatenames'] = False
71 self['use_dotted_templatenames'] = False
72
72
73 # Configure Sessions, store data as JSON to avoid pickle security issues
73 # Configure Sessions, store data as JSON to avoid pickle security issues
74 self['session.enabled'] = True
74 self['session.enabled'] = True
75 self['session.data_serializer'] = 'json'
75 self['session.data_serializer'] = 'json'
76
76
77 # Configure the base SQLALchemy Setup
77 # Configure the base SQLALchemy Setup
78 self['use_sqlalchemy'] = True
78 self['use_sqlalchemy'] = True
79 self['model'] = kallithea.model.base
79 self['model'] = kallithea.model.base
80 self['DBSession'] = kallithea.model.meta.Session
80 self['DBSession'] = kallithea.model.meta.Session
81
81
82 # Configure App without an authentication backend.
82 # Configure App without an authentication backend.
83 self['auth_backend'] = None
83 self['auth_backend'] = None
84
84
85 # Use custom error page for these errors. By default, Turbogears2 does not add
85 # Use custom error page for these errors. By default, Turbogears2 does not add
86 # 400 in this list.
86 # 400 in this list.
87 # Explicitly listing all is considered more robust than appending to defaults,
87 # Explicitly listing all is considered more robust than appending to defaults,
88 # in light of possible future framework changes.
88 # in light of possible future framework changes.
89 self['errorpage.status_codes'] = [400, 401, 403, 404]
89 self['errorpage.status_codes'] = [400, 401, 403, 404]
90
90
91 # Disable transaction manager -- currently Kallithea takes care of transactions itself
91 # Disable transaction manager -- currently Kallithea takes care of transactions itself
92 self['tm.enabled'] = False
92 self['tm.enabled'] = False
93
93
94 base_config = KallitheaAppConfig()
94 base_config = KallitheaAppConfig()
95
95
96 # TODO still needed as long as we use pylonslib
96 # TODO still needed as long as we use pylonslib
97 sys.modules['pylons'] = tg
97 sys.modules['pylons'] = tg
98
98
99 # DebugBar, a debug toolbar for TurboGears2.
100 # (https://github.com/TurboGears/tgext.debugbar)
101 # To enable it, install 'tgext.debugbar' and 'kajiki', and run Kallithea with
102 # 'debug = true' (not in production!)
103 # See the Kallithea documentation for more information.
104 try:
105 from tgext.debugbar import enable_debugbar
106 import kajiki # only to check its existence
107 except ImportError:
108 pass
109 else:
110 base_config['renderers'].append('kajiki')
111 enable_debugbar(base_config)
112
113
99 def setup_configuration(app):
114 def setup_configuration(app):
100 config = app.config
115 config = app.config
101
116
102 # store some globals into kallithea
117 # store some globals into kallithea
103 kallithea.CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
118 kallithea.CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
104 kallithea.CELERY_EAGER = str2bool(config['app_conf'].get('celery.always.eager'))
119 kallithea.CELERY_EAGER = str2bool(config['app_conf'].get('celery.always.eager'))
105 kallithea.CONFIG = config
120 kallithea.CONFIG = config
106
121
107 # Provide routes mapper to the RoutedController
122 # Provide routes mapper to the RoutedController
108 root_controller = app.find_controller('root')
123 root_controller = app.find_controller('root')
109 root_controller.mapper = config['routes.map'] = make_map(config)
124 root_controller.mapper = config['routes.map'] = make_map(config)
110
125
111 load_rcextensions(root_path=config['here'])
126 load_rcextensions(root_path=config['here'])
112
127
113 # FIXME move test setup code out of here
128 # FIXME move test setup code out of here
114 test = os.path.split(config['__file__'])[-1] == 'test.ini'
129 test = os.path.split(config['__file__'])[-1] == 'test.ini'
115 if test:
130 if test:
116 test_env = not int(os.environ.get('KALLITHEA_NO_TMP_PATH', 0))
131 test_env = not int(os.environ.get('KALLITHEA_NO_TMP_PATH', 0))
117 test_index = not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0))
132 test_index = not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0))
118 if os.environ.get('TEST_DB'):
133 if os.environ.get('TEST_DB'):
119 # swap config if we pass environment variable
134 # swap config if we pass environment variable
120 config['sqlalchemy.url'] = os.environ.get('TEST_DB')
135 config['sqlalchemy.url'] = os.environ.get('TEST_DB')
121
136
122 from kallithea.tests.fixture import create_test_env, create_test_index
137 from kallithea.tests.fixture import create_test_env, create_test_index
123 from kallithea.tests.base import TESTS_TMP_PATH
138 from kallithea.tests.base import TESTS_TMP_PATH
124 #set KALLITHEA_NO_TMP_PATH=1 to disable re-creating the database and
139 #set KALLITHEA_NO_TMP_PATH=1 to disable re-creating the database and
125 #test repos
140 #test repos
126 if test_env:
141 if test_env:
127 create_test_env(TESTS_TMP_PATH, config)
142 create_test_env(TESTS_TMP_PATH, config)
128 #set KALLITHEA_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests
143 #set KALLITHEA_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests
129 if test_index:
144 if test_index:
130 create_test_index(TESTS_TMP_PATH, config, True)
145 create_test_index(TESTS_TMP_PATH, config, True)
131
146
132 set_available_permissions(config)
147 set_available_permissions(config)
133 repos_path = make_ui('db').configitems('paths')[0][1]
148 repos_path = make_ui('db').configitems('paths')[0][1]
134 config['base_path'] = repos_path
149 config['base_path'] = repos_path
135 set_app_settings(config)
150 set_app_settings(config)
136
151
137 instance_id = kallithea.CONFIG.get('instance_id', '*')
152 instance_id = kallithea.CONFIG.get('instance_id', '*')
138 if instance_id == '*':
153 if instance_id == '*':
139 instance_id = '%s-%s' % (platform.uname()[1], os.getpid())
154 instance_id = '%s-%s' % (platform.uname()[1], os.getpid())
140 kallithea.CONFIG['instance_id'] = instance_id
155 kallithea.CONFIG['instance_id'] = instance_id
141
156
142 # update kallithea.CONFIG with the meanwhile changed 'config'
157 # update kallithea.CONFIG with the meanwhile changed 'config'
143 kallithea.CONFIG.update(config)
158 kallithea.CONFIG.update(config)
144
159
145 # configure vcs and indexer libraries (they are supposed to be independent
160 # configure vcs and indexer libraries (they are supposed to be independent
146 # as much as possible and thus avoid importing tg.config or
161 # as much as possible and thus avoid importing tg.config or
147 # kallithea.CONFIG).
162 # kallithea.CONFIG).
148 set_vcs_config(kallithea.CONFIG)
163 set_vcs_config(kallithea.CONFIG)
149 set_indexer_config(kallithea.CONFIG)
164 set_indexer_config(kallithea.CONFIG)
150
165
151 check_git_version()
166 check_git_version()
152
167
153 if str2bool(config.get('initial_repo_scan', True)):
168 if str2bool(config.get('initial_repo_scan', True)):
154 repo2db_mapper(ScmModel().repo_scan(repos_path),
169 repo2db_mapper(ScmModel().repo_scan(repos_path),
155 remove_obsolete=False, install_git_hooks=False)
170 remove_obsolete=False, install_git_hooks=False)
156
171
157 formencode.api.set_stdtranslation(languages=[config.get('lang')])
172 formencode.api.set_stdtranslation(languages=[config.get('lang')])
158
173
159 hooks.register('configure_new_app', setup_configuration)
174 hooks.register('configure_new_app', setup_configuration)
160
175
161
176
162 def setup_application(app):
177 def setup_application(app):
163 config = app.config
178 config = app.config
164
179
165 # we want our low level middleware to get to the request ASAP. We don't
180 # we want our low level middleware to get to the request ASAP. We don't
166 # need any stack middleware in them - especially no StatusCodeRedirect buffering
181 # need any stack middleware in them - especially no StatusCodeRedirect buffering
167 app = SimpleHg(app, config)
182 app = SimpleHg(app, config)
168 app = SimpleGit(app, config)
183 app = SimpleGit(app, config)
169
184
170 # Enable https redirects based on HTTP_X_URL_SCHEME set by proxy
185 # Enable https redirects based on HTTP_X_URL_SCHEME set by proxy
171 if any(asbool(config.get(x)) for x in ['https_fixup', 'force_https', 'use_htsts']):
186 if any(asbool(config.get(x)) for x in ['https_fixup', 'force_https', 'use_htsts']):
172 app = HttpsFixup(app, config)
187 app = HttpsFixup(app, config)
173 return app
188 return app
174
189
175 hooks.register('before_config', setup_application)
190 hooks.register('before_config', setup_application)
General Comments 0
You need to be logged in to leave comments. Login now