-
Notifications
You must be signed in to change notification settings - Fork 25
/
config.py
24 lines (21 loc) · 880 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from configparser import ConfigParser
class Config(ConfigParser):
def __init__(self, config_file):
raw_config = ConfigParser()
raw_config.read(config_file)
self.cast_values(raw_config)
def cast_values(self, raw_config):
for section in raw_config.sections():
for key, value in raw_config.items(section):
val = None
if type(value) is str and value.startswith("[") and value.endswith("]"):
val = eval(value)
setattr(self, key, val)
continue
for attr in ["getint", "getfloat", "getboolean"]:
try:
val = getattr(raw_config[section], attr)(key)
break
except:
val = value
setattr(self, key, val)