helpers.py 文件源码

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

项目:appetite 作者: Bridgewater 项目源码 文件源码
def get_template_content(path):
    """Read either yml or json files and store them as dict"""
    template_dict = {}

    _filename, file_extension = os.path.splitext(path)
    file_extension = file_extension.replace('.', '')
    if file_extension in consts.TEMPLATING_EXTS:
        try:
            template_content = {}
            abs_path = os.path.abspath(os.path.expandvars(path))
            with open(abs_path, 'r') as stream:
                if file_extension in consts.JSON_EXTS:
                    template_content = json.load(stream) #nosec
                elif file_extension in consts.YMAL_EXTS:
                    template_content = yaml.safe_load(stream) #nosec
            template_dict.update(template_content)
        except Exception as e:
            logger.errorout("Error reading templating file",
                            file=path, error=e.message)
    else:
        logger.errorout("No templating file found",
                        file=path)

    return template_dict
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号