Show More
@@ -1,59 +1,76 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2016-2018 RhodeCode GmbH |
|
3 | # Copyright (C) 2016-2018 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import os |
|
21 | import os | |
22 | from pyramid.compat import configparser |
|
22 | from pyramid.compat import configparser | |
23 | from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # noqa |
|
23 | from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # noqa | |
24 | from pyramid.scripting import prepare |
|
24 | from pyramid.scripting import prepare | |
25 |
|
25 | |||
26 | from rhodecode.lib.request import Request |
|
26 | from rhodecode.lib.request import Request | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | def get_config(ini_path, **kwargs): |
|
29 | def get_config(ini_path, **kwargs): | |
30 | parser = configparser.ConfigParser(**kwargs) |
|
30 | parser = configparser.ConfigParser(**kwargs) | |
31 | parser.read(ini_path) |
|
31 | parser.read(ini_path) | |
32 | return parser |
|
32 | return parser | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | def get_app_config(ini_path): |
|
35 | def get_app_config(ini_path): | |
36 | from paste.deploy.loadwsgi import appconfig |
|
36 | from paste.deploy.loadwsgi import appconfig | |
37 | return appconfig('config:{}'.format(ini_path), relative_to=os.getcwd()) |
|
37 | return appconfig('config:{}'.format(ini_path), relative_to=os.getcwd()) | |
38 |
|
38 | |||
39 |
|
39 | |||
|
40 | class BootstrappedRequest(Request): | |||
|
41 | """ | |||
|
42 | Special version of Request Which has some available methods like in pyramid. | |||
|
43 | Some code (used for template rendering) requires this, and we unsure it's present. | |||
|
44 | """ | |||
|
45 | ||||
|
46 | def translate(self, msg): | |||
|
47 | return msg | |||
|
48 | ||||
|
49 | def plularize(self, singular, plural, n): | |||
|
50 | return singular | |||
|
51 | ||||
|
52 | def get_partial_renderer(self, tmpl_name): | |||
|
53 | from rhodecode.lib.partial_renderer import get_partial_renderer | |||
|
54 | return get_partial_renderer(request=self, tmpl_name=tmpl_name) | |||
|
55 | ||||
|
56 | ||||
40 | def bootstrap(config_uri, request=None, options=None, env=None): |
|
57 | def bootstrap(config_uri, request=None, options=None, env=None): | |
41 | if env: |
|
58 | if env: | |
42 | os.environ.update(env) |
|
59 | os.environ.update(env) | |
43 |
|
60 | |||
44 | config = get_config(config_uri) |
|
61 | config = get_config(config_uri) | |
45 | base_url = 'http://rhodecode.local' |
|
62 | base_url = 'http://rhodecode.local' | |
46 | try: |
|
63 | try: | |
47 | base_url = config.get('app:main', 'app.base_url') |
|
64 | base_url = config.get('app:main', 'app.base_url') | |
48 | except (configparser.NoSectionError, configparser.NoOptionError): |
|
65 | except (configparser.NoSectionError, configparser.NoOptionError): | |
49 | pass |
|
66 | pass | |
50 |
|
67 | |||
51 | request = request or Request.blank('/', base_url=base_url) |
|
68 | request = request or BootstrappedRequest.blank('/', base_url=base_url) | |
52 |
|
69 | |||
53 | return pyramid_bootstrap(config_uri, request=request, options=options) |
|
70 | return pyramid_bootstrap(config_uri, request=request, options=options) | |
54 |
|
71 | |||
55 |
|
72 | |||
56 | def prepare_request(environ): |
|
73 | def prepare_request(environ): | |
57 | request = Request.blank('/', environ=environ) |
|
74 | request = Request.blank('/', environ=environ) | |
58 | prepare(request) # set pyramid threadlocal request |
|
75 | prepare(request) # set pyramid threadlocal request | |
59 | return request |
|
76 | return request |
General Comments 0
You need to be logged in to leave comments.
Login now