def yaml_save(filename, data):
"""
Save contents of an OrderedDict structure to a yaml file
:param filename: name of the yaml file to save to
:type filename: str
:param data: configuration data to to save
:type filename: str
:type data: OrderedDict
:returns: Nothing
"""
ordered = (type(data).__name__ == 'OrderedDict')
dict_type = 'dict'
if ordered:
dict_type = 'OrderedDict'
logger.info("Saving '{}' to '{}'".format(dict_type, filename))
if ordered:
sdata = _ordered_dump(data, Dumper=yaml.SafeDumper, indent=4, width=768, allow_unicode=True, default_flow_style=False)
else:
sdata = yaml.dump(data, Dumper=yaml.SafeDumper, indent=4, width=768, allow_unicode=True, default_flow_style=False)
sdata = _format_yaml_dump( sdata )
with open(filename, 'w') as outfile:
outfile.write( sdata )
# ==================================================================================
评论列表
文章目录