Package FuzzManager :: Package FTB :: Module ConfigurationFiles
[hide private]
[frames] | no frames]

Source Code for Module FuzzManager.FTB.ConfigurationFiles

 1  #!/usr/bin/env python 
 2  # encoding: utf-8 
 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  # Ensure print() compatibility with Python 3 
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   
27 -class ConfigurationFiles():
28 - def __init__(self, configFiles):
29 self.mainConfig = {} 30 self.metadataConfig = {} 31 32 if configFiles: 33 self.parser = configparser.ConfigParser() 34 35 # Make sure keys are kept case-sensitive 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 # Produce warnings for unrecognized sections to make 43 # debugging easier. Especially main vs. Main is hard 44 # to figure out sometimes. 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
53 - def getSectionMap(self, section):
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