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