shyaml.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:smarthome 作者: smarthomeNG 项目源码 文件源码
def yaml_save_roundtrip(filename, data, create_backup=False):
    """
    Dump yaml using the RoundtripDumper and correct linespacing in output file

    :param filename: name of the yaml file to save to
    :param data: data structure to save
    """

    if not EDITING_ENABLED:
        return
    sdata = yaml.dump(data, Dumper=yaml.RoundTripDumper, version=yaml_version, indent=indent_spaces, block_seq_indent=block_seq_indent, width=12288, allow_unicode=True)

#    with open(filename+'_raw'+YAML_FILE, 'w') as outfile:
#        outfile.write( sdata )

    if create_backup:
        if os.path.isfile(filename+YAML_FILE):
            shutil.copy2(filename+YAML_FILE, filename+'.bak')

    sdata = _format_yaml_dump2( sdata )
    with open(filename+YAML_FILE, 'w') as outfile:
        outfile.write( sdata )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号