blob: afd1fca88ed8ea97ff8ef2347cdeac4f3a5a8d82 [file] [log] [blame]
James Kuszmaul55d9fc72020-05-10 18:58:08 -07001#!/usr/bin/python3
2
3import argparse
4from pathlib import Path
5import json
6import sys
7
8import jinja2
9
10
11def main():
12 # Note: this is a pretty transparent interface to jinja2--there's no reason
13 # this script couldn't be renamed and then used to generate any config from
14 # a template.
15 parser = argparse.ArgumentParser(
16 description="Generates the raspberry pi configs from a template.")
17 parser.add_argument("template", type=str, help="File to use for template.")
18 parser.add_argument("replacements", type=json.loads, help="Dictionary of parameters to replace in the template.")
19 parser.add_argument("output", type=str, help="Output file to create.")
20 args = parser.parse_args(sys.argv[1:])
21
22 with open(args.template, 'r') as input_file:
23 template = jinja2.Template(input_file.read())
24
25 output = template.render(args.replacements)
26 with open(args.output, 'w') as config_file:
27 config_file.write(output)
28
29if __name__ == '__main__':
30 main()