Package lib :: Package core :: Module config
[hide private]
[frames] | no frames]

Source Code for Module lib.core.config

 1  # Copyright (C) 2010-2015 Cuckoo Foundation. 
 2  # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org 
 3  # See the file 'docs/LICENSE' for copying permission. 
 4   
 5  import ConfigParser 
 6   
7 -class Config:
8 - def __init__(self, cfg):
9 """@param cfg: configuration file.""" 10 config = ConfigParser.ConfigParser(allow_no_value=True) 11 config.read(cfg) 12 13 for section in config.sections(): 14 for name, raw_value in config.items(section): 15 if name == "file_name": 16 value = config.get(section, name) 17 else: 18 try: 19 value = config.getboolean(section, name) 20 except ValueError: 21 try: 22 value = config.getint(section, name) 23 except ValueError: 24 value = config.get(section, name) 25 setattr(self, name, value)
26
27 - def get_options(self):
28 """Get analysis options. 29 @return: options dict. 30 """ 31 # The analysis package can be provided with some options in the 32 # following format: 33 # option1=value1,option2=value2,option3=value3 34 # 35 # Here we parse such options and provide a dictionary that will be made 36 # accessible to the analysis package. 37 options = {} 38 if hasattr(self, "options"): 39 try: 40 # Split the options by comma. 41 fields = self.options.split(",") 42 except ValueError as e: 43 pass 44 else: 45 for field in fields: 46 # Split the name and the value of the option. 47 try: 48 key, value = field.split("=", 1) 49 except ValueError as e: 50 pass 51 else: 52 # If the parsing went good, we add the option to the 53 # dictionary. 54 options[key.strip()] = value.strip() 55 56 return options
57