1
2
3
4
5
6 import ConfigParser
7
10 """@param cfg: configuration file."""
11 config = ConfigParser.ConfigParser(allow_no_value=True)
12 config.read(cfg)
13
14 for section in config.sections():
15 for name, raw_value in config.items(section):
16 if name == "file_name":
17 value = config.get(section, name).decode("utf8")
18 elif name == "options":
19 value = self.parse_options(config.get(section, name))
20 else:
21 try:
22 value = config.getboolean(section, name)
23 except ValueError:
24 try:
25 value = config.getint(section, name)
26 except ValueError:
27 value = config.get(section, name)
28 setattr(self, name, value)
29
30
31 if not hasattr(self, "options"):
32 self.options = {}
33
35 """Get analysis options.
36 @return: options dict.
37 """
38
39
40
41 ret = {}
42 for field in options.split(","):
43 if "=" not in field:
44 continue
45
46 key, value = field.split("=", 1)
47 ret[key.strip()] = value.strip()
48 return ret
49