def update_write_config(config_file, update_dict):
"""Update a given configuration file with updated values.
If the configuration file does not exist, a new one is created.
Args:
config_file (str): the location of the config file to update
update_dict (dict): the items to update in the config file
"""
if not os.path.exists(config_file):
with open(config_file, 'a'):
pass
with open(config_file, 'r') as f:
config_dict = yaml.safe_load(f.read()) or {}
for key, value in update_dict.items():
loader = get_section_loader(key)
loader.update(config_dict, value)
with open(config_file, 'w') as f:
yaml.safe_dump(config_dict, f)
评论列表
文章目录