blob: e5f6fa3399bf67fd1cf198cfd96ae3be53149d88 [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():
Ravago Jones5127ccc2022-07-31 16:32:45 -070011 # 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(
18 "replacements",
19 type=json.loads,
20 help="Dictionary of parameters to replace in the template.")
21 parser.add_argument("output", type=str, help="Output file to create.")
22 args = parser.parse_args(sys.argv[1:])
James Kuszmaul55d9fc72020-05-10 18:58:08 -070023
Ravago Jones5127ccc2022-07-31 16:32:45 -070024 with open(args.template, 'r') as input_file:
25 template = jinja2.Template(input_file.read())
James Kuszmaul55d9fc72020-05-10 18:58:08 -070026
Ravago Jones5127ccc2022-07-31 16:32:45 -070027 output = template.render(args.replacements)
28 with open(args.output, 'w') as config_file:
29 config_file.write(output)
30
James Kuszmaul55d9fc72020-05-10 18:58:08 -070031
32if __name__ == '__main__':
Ravago Jones5127ccc2022-07-31 16:32:45 -070033 main()