helpers.py 文件源码

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

项目:appetite 作者: Bridgewater 项目源码 文件源码
def template_directory(app_path, templating_values):
    """Template files

    Walks through all the files a directory and templates any jinja2 values
    found.
    """

    if not check_path(app_path):
        logger.errorout("Can not copy location that does not exist",
                        path=app_path)

    tvalues = merge_templates(templating_values)

    for path, _dir, files in os.walk(app_path):
        # sort files so logs read better and easier to get status
        files.sort()
        j2_env = Environment(autoescape=True, loader=FileSystemLoader(path))
        for filename in files:
            # Should not template version file since it may have
            # regex commands that can break templating.
            if filename.startswith(consts.VERSIONS_FILENAME):
                continue

            file_path = os.path.join(path, filename)
            try:
                file_content = j2_env.get_template(filename).render(tvalues)

                with open(file_path, 'w') as f:
                    f.write(file_content)
            except Exception as e:
                logger.errorout('Error templating file', file=file_path, error=e.message)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号