Generate y2020 pi configs from a template
This removes a bunch of obnoxious redundancy.
Change-Id: I85741b7dfa482a6e95190628eb23d07394a25ede
diff --git a/y2020/generate_pi_config.py b/y2020/generate_pi_config.py
new file mode 100644
index 0000000..afd1fca
--- /dev/null
+++ b/y2020/generate_pi_config.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python3
+
+import argparse
+from pathlib import Path
+import json
+import sys
+
+import jinja2
+
+
+def main():
+ # Note: this is a pretty transparent interface to jinja2--there's no reason
+ # this script couldn't be renamed and then used to generate any config from
+ # a template.
+ parser = argparse.ArgumentParser(
+ description="Generates the raspberry pi configs from a template.")
+ parser.add_argument("template", type=str, help="File to use for template.")
+ parser.add_argument("replacements", type=json.loads, help="Dictionary of parameters to replace in the template.")
+ parser.add_argument("output", type=str, help="Output file to create.")
+ args = parser.parse_args(sys.argv[1:])
+
+ with open(args.template, 'r') as input_file:
+ template = jinja2.Template(input_file.read())
+
+ output = template.render(args.replacements)
+ with open(args.output, 'w') as config_file:
+ config_file.write(output)
+
+if __name__ == '__main__':
+ main()