Package FuzzManager ::
Package FTB ::
Module ConfigurationFiles
|
|
1
2
3 '''
4 ConfigurationFiles -- Generic class used in FuzzManager to read one or more configuration files
5
6 @author: Christian Holler (:decoder)
7
8 @license:
9
10 This Source Code Form is subject to the terms of the Mozilla Public
11 License, v. 2.0. If a copy of the MPL was not distributed with this
12 file, You can obtain one at http://mozilla.org/MPL/2.0/.
13
14 @contact: choller@mozilla.com
15 '''
16
17
18 from __future__ import print_function
19
20 try:
21 import configparser
22 except ImportError:
23 import ConfigParser as configparser
24
25 import sys
26
29 self.mainConfig = {}
30 self.metadataConfig = {}
31
32 if configFiles:
33 self.parser = configparser.ConfigParser()
34
35
36 self.parser.optionxform = str
37
38 self.parser.read(configFiles)
39 self.mainConfig = self.getSectionMap("Main")
40 self.metadataConfig = self.getSectionMap("Metadata")
41
42
43
44
45 sections = self.parser.sections()
46 for section in ["Main", "Metadata"]:
47 if section in sections:
48 sections.remove(section)
49 if sections:
50 print("Warning: Ignoring the following config file sections: %s" % " ".join(sections), file=sys.stderr)
51
52
54 ret = {}
55 try:
56 options = self.parser.options(section)
57 except configparser.NoSectionError:
58 return {}
59 for o in options:
60 ret[o] = self.parser.get(section, o)
61 return ret
62