def config_file_as_dict(**kwargs):
cfgfile = kwargs["cfgfile"]
cfgfile_contents = templated_file_contents(kwargs, kwargs["cfgfile"])
# print (cfgfile_contents)
cfg_data = {}
if cfgfile.endswith(".json"):
cfgdata = json.loads(cfgfile_contents)
elif cfgfile.endswith(".toml"):
cfgdata = toml.loads(cfgfile_contents)
elif cfgfile.endswith(".yaml"):
yaml.add_constructor('!join', join) # http://stackoverflow.com/questions/5484016/how-can-i-do-string-concatenation-or-string-replacement-in-yaml
cfgdata = yaml.load(cfgfile_contents)
else:
raise ValueError("Invalid config file format")
return merge_two_dicts(kwargs, cfgdata)
评论列表
文章目录