compile_template.py 文件源码

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

项目:guest-images 作者: S2E 项目源码 文件源码
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-t', '--template', help='Template file', required=True)
    parser.add_argument('-o', '--output', help='Output file', required=True)
    parser.add_argument('-n', '--image-name', help='Image name', required=True)
    parser.add_argument('-d', '--image-descriptors', help='Image descriptors', required=True)

    args = parser.parse_args()

    # Get the image descriptors json file
    with open(args.image_descriptors, 'r') as f:
        images = json.loads(f.read())['images']

    if args.image_name not in images.keys():
        print('%s does not exist in %s' % (args.image_name, args.image_descriptors))
        sys.exit(-1)

    with open(args.template) as fp:
        template = jinja2.Template(fp.read())

    context = images[args.image_name]
    output = template.render(**context)

    with open(args.output, 'w') as f:
        f.write(output)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号