1
2
3
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
13 """Configuration file parser."""
14
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