1 ##############################################################################
2 # Copyright (c) 2015 Orange
3 # guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 # feng.xiaowei@zte.com.cn remove prepare_put_request 5-30-2016
9 ##############################################################################
18 self.file = self.CONFIG if self.CONFIG else self._default_config()
20 self._parse_per_page()
21 self.static_path = os.path.join(
22 os.path.dirname(os.path.normpath(__file__)),
27 if not os.path.exists(self.file):
28 raise Exception("%s not found" % self.file)
30 config = ConfigParser.RawConfigParser()
31 config.read(self.file)
32 self._parse_section(config)
34 def _parse_section(self, config):
35 [self._parse_item(config, section) for section in (config.sections())]
37 def _parse_item(self, config, section):
38 [setattr(self, '{}_{}'.format(section, k), self._parse_value(v))
39 for k, v in config.items(section)]
41 def _parse_per_page(self):
42 if not hasattr(self, 'api_results_per_page'):
43 self.api_results_per_page = 20
46 def _parse_value(value):
50 if str(value).lower() == 'true':
52 elif str(value).lower() == 'false':
57 def _default_config():
58 is_venv = os.getenv('VIRTUAL_ENV')
59 return os.path.join('/' if not is_venv else is_venv,
60 'etc/opnfv_testapi/config.ini')