sync_config_yaml.py 文件源码

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

项目:builds 作者: open-power-host-os 项目源码 文件源码
def sync_config_yaml(config_metadata_file_path, config_file_path):
    """
    Create configuration file from configuration metadata file.

    Args:
        config_metadata_file_path (str): configuration metadata file path
        config_file_path (str): configuration file path
    """

    with open(config_metadata_file_path) as config_metadata_file:
        config_metadata = yaml.safe_load(config_metadata_file)

    config = {}
    for command_name, command_dict in config_metadata["commands"].items():
        config[command_name] = {}
        for option_name in command_dict["options"]:
            option_default = config_metadata["options"][option_name]["default"]
            config[command_name][option_name] = option_default

    # Do not use aliases in the YAML to make it simpler
    class NoAliasDumper(yaml.Dumper):
        def ignore_aliases(self, _data):
            return True

    with open(config_file_path, "w") as config_file:
        config_file.write(yaml.dump(config, default_flow_style=False,
        Dumper=NoAliasDumper))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号