Show More
@@ -1,54 +1,58 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2020 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import os |
|
22 | 22 | from pyramid.compat import configparser |
|
23 | 23 | from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # pragma: no cover |
|
24 | from pyramid.scripting import prepare | |
|
25 | 24 | |
|
26 | 25 | from rhodecode.lib.request import Request |
|
27 | 26 | |
|
28 | 27 | |
|
29 | 28 | def get_config(ini_path, **kwargs): |
|
30 | 29 | parser = configparser.ConfigParser(**kwargs) |
|
31 | 30 | parser.read(ini_path) |
|
32 | 31 | return parser |
|
33 | 32 | |
|
34 | 33 | |
|
35 | 34 | def get_app_config(ini_path): |
|
36 | 35 | from paste.deploy.loadwsgi import appconfig |
|
37 | 36 | return appconfig('config:{}'.format(ini_path), relative_to=os.getcwd()) |
|
38 | 37 | |
|
39 | 38 | |
|
40 | 39 | def bootstrap(config_uri, options=None, env=None): |
|
40 | from rhodecode.lib.utils2 import AttributeDict | |
|
41 | ||
|
41 | 42 | if env: |
|
42 | 43 | os.environ.update(env) |
|
43 | 44 | |
|
44 | 45 | config = get_config(config_uri) |
|
45 | 46 | base_url = 'http://rhodecode.local' |
|
46 | 47 | try: |
|
47 | 48 | base_url = config.get('app:main', 'app.base_url') |
|
48 | 49 | except (configparser.NoSectionError, configparser.NoOptionError): |
|
49 | 50 | pass |
|
50 | 51 | |
|
51 | 52 | request = Request.blank('/', base_url=base_url) |
|
52 | ||
|
53 | # fake inject a running user for bootstrap request ! | |
|
54 | request.user = AttributeDict({'username': 'bootstrap-user', | |
|
55 | 'user_id': 1, | |
|
56 | 'ip_addr': '127.0.0.1'}) | |
|
53 | 57 | return pyramid_bootstrap(config_uri, request=request, options=options) |
|
54 | 58 |
General Comments 0
You need to be logged in to leave comments.
Login now