-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathbaseConfig.py
24 lines (20 loc) · 977 Bytes
/
baseConfig.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
import ConfigParser
class BaseConfig(object):
def __init__(self, configfile):
self._config = ConfigParser.SafeConfigParser()
self._config.read(configfile)
def defaulting(self, section, variable, default, quiet=False):
if quiet is False:
print('Config option ' + str(variable) + ' not set in [' +
str(section) + '] defaulting to: \'' + str(default) + '\'')
def read_config_var(self, section, variable, default, type='str', quiet=False):
try:
if type == 'str':
return self._config.get(section, variable)
elif type == 'bool':
return self._config.getboolean(section, variable)
elif type == 'int':
return self._config.getint(section, variable)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
self.defaulting(section, variable, default, quiet)
return default