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

Source Code for Module lib.cuckoo.common.config

 1  # Copyright (C) 2010-2014 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 os 
 6  import ConfigParser 
 7   
 8  from lib.cuckoo.common.constants import CUCKOO_ROOT 
 9  from lib.cuckoo.common.exceptions import CuckooOperationalError 
10  from lib.cuckoo.common.objects import Dictionary 
11   
12 -class Config:
13 """Configuration file parser.""" 14
15 - def __init__(self, cfg=os.path.join(CUCKOO_ROOT, "conf", "cuckoo.conf")):
16 """@param cfg: configuration file path.""" 17 config = ConfigParser.ConfigParser() 18 config.read(cfg) 19 20 for section in config.sections(): 21 setattr(self, section, Dictionary()) 22 for name, raw_value in config.items(section): 23 try: 24 value = config.getboolean(section, name) 25 except ValueError: 26 try: 27 value = config.getint(section, name) 28 except ValueError: 29 value = config.get(section, name) 30 31 setattr(getattr(self, section), name, value)
32
33 - def get(self, section):
34 """Get option. 35 @param section: section to fetch. 36 @raise CuckooOperationalError: if section not found. 37 @return: option value. 38 """ 39 try: 40 return getattr(self, section) 41 except AttributeError as e: 42 raise CuckooOperationalError("Option %s is not found in " 43 "configuration, error: %s" % 44 (section, e))
45