blob: 3575e99ecac66b87d2a1575890e42d470e745c02 [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:
James Kuszmaulfe650202023-02-05 17:31:19 -080025 template = jinja2.Environment(
26 loader=jinja2.FileSystemLoader(".")).from_string(input_file.read())
James Kuszmaul55d9fc72020-05-10 18:58:08 -070027
Ravago Jones5127ccc2022-07-31 16:32:45 -070028 output = template.render(args.replacements)
29 with open(args.output, 'w') as config_file:
30 config_file.write(output)
31
James Kuszmaul55d9fc72020-05-10 18:58:08 -070032
33if __name__ == '__main__':
Ravago Jones5127ccc2022-07-31 16:32:45 -070034 main()