Support for include directive in config.yaml, #32

This commit is contained in:
Fabio Manganiello 2018-01-08 10:08:55 +01:00
parent d6807bd85b
commit 7963b5e11f

View file

@ -46,13 +46,8 @@ class Config(object):
raise RuntimeError('No config file specified and nothing found in {}'
.format(self._cfgfile_locations))
with open(cfgfile, 'r') as fp:
self._config = yaml.load(fp)
for section in self._config:
if 'disabled' in self._config[section] \
and self._config[section]['disabled']:
del self._config[section]
self._cfgfile = cfgfile
self._config = self._read_config_file(self._cfgfile)
if 'logging' not in self._config:
self._config['logging'] = logging.INFO
@ -69,6 +64,27 @@ class Config(object):
self._init_components()
def _read_config_file(self, cfgfile):
if not os.path.isabs(cfgfile):
cfgfile = os.path.join(os.path.dirname(self._cfgfile), cfgfile)
config = {}
with open(cfgfile, 'r') as fp:
file_config = yaml.load(fp)
for section in file_config:
if section == 'include':
included_config = self._read_config_file(file_config[section])
for incl_section in included_config.keys():
config[incl_section] = included_config[incl_section]
elif 'disabled' not in file_config[section] \
or file_config[section]['disabled'] is False:
config[section] = file_config[section]
return config
def _init_components(self):
for key in self._config.keys():
if key.startswith('backend.'):