##// END OF EJS Templates
pyramid-utils: add helper to fetch application config....
marcink -
r2340:79804d6e default
parent child
Show More
@@ -1,43 +1,49
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2017 RhodeCode GmbH
3 # Copyright (C) 2016-2017 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 ConfigParser
22 import ConfigParser
22 from pyramid.paster import bootstrap as pyramid_bootstrap
23 from pyramid.paster import bootstrap as pyramid_bootstrap
23 from pyramid.request import Request
24 from pyramid.request import Request
24
25
25
26
26 def get_config(ini_path):
27 def get_config(ini_path, **kwargs):
27 parser = ConfigParser.ConfigParser()
28 parser = ConfigParser.ConfigParser(**kwargs)
28 parser.read(ini_path)
29 parser.read(ini_path)
29 return parser
30 return parser
30
31
31
32
33 def get_app_config(ini_path):
34 from paste.deploy.loadwsgi import appconfig
35 return appconfig('config:{}'.format(ini_path), relative_to=os.getcwd())
36
37
32 def bootstrap(config_uri, request=None, options=None):
38 def bootstrap(config_uri, request=None, options=None):
33
39
34 config = get_config(config_uri)
40 config = get_config(config_uri)
35 base_url = 'http://rhodecode.local'
41 base_url = 'http://rhodecode.local'
36 try:
42 try:
37 base_url = config.get('app:main', 'app.base_url')
43 base_url = config.get('app:main', 'app.base_url')
38 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
44 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
39 pass
45 pass
40
46
41 request = request or Request.blank('/', base_url=base_url)
47 request = request or Request.blank('/', base_url=base_url)
42
48
43 return pyramid_bootstrap(config_uri, request=request, options=options)
49 return pyramid_bootstrap(config_uri, request=request, options=options)
General Comments 0
You need to be logged in to leave comments. Login now