Factor out jinja2 template to be generic

This lets us reuse it for many more config setups to avoid duplication.

Change-Id: I9e77e55d460edb3f8037ce164818e45b6ab7a56e
diff --git a/y2020/BUILD b/y2020/BUILD
index ba2f3a6..38832b8 100644
--- a/y2020/BUILD
+++ b/y2020/BUILD
@@ -2,7 +2,7 @@
 load("//aos:config.bzl", "aos_config")
 load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library")
 load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
-load("//y2020:config_gen.bzl", "generate_pi_config")
+load("//tools/build_rules:template.bzl", "jinja2_template")
 
 robot_downloader(
     binaries = [
@@ -182,11 +182,30 @@
         "pi2",
         "pi3",
         "pi4",
-        "laptop",
     ]
 ]
 
 aos_config(
+    name = "config_laptop",
+    src = "y2020_laptop.json",
+    flatbuffers = [
+        "//aos/network:message_bridge_client_fbs",
+        "//aos/network:message_bridge_server_fbs",
+        "//aos/network:timestamp_fbs",
+        "//y2020/vision/sift:sift_fbs",
+        "//y2020/vision/sift:sift_training_fbs",
+        "//y2020/vision:vision_fbs",
+        "//aos/events/logging:logger_fbs",
+    ],
+    visibility = ["//visibility:public"],
+    deps = [
+        "//aos/events:config",
+        "//aos/robot_state:config",
+        "//frc971/control_loops/drivetrain:config",
+    ],
+)
+
+aos_config(
     name = "config_roborio",
     src = "y2020_roborio.json",
     flatbuffers = [
@@ -248,10 +267,11 @@
     ],
 )
 
-py_binary(
-    name = "generate_pi_config",
-    srcs = ["generate_pi_config.py"],
-    deps = ["@python_jinja2"],
-)
-
-[generate_pi_config(num) for num in range(1, 5)]
+[
+    jinja2_template(
+        name = "y2020_pi" + str(num) + ".json",
+        src = "y2020_pi_template.json",
+        parameters = {"NUM": str(num)},
+    )
+    for num in range(1, 5)
+]
diff --git a/y2020/generate_pi_config.py b/y2020/generate_pi_config.py
deleted file mode 100644
index afd1fca..0000000
--- a/y2020/generate_pi_config.py
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/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()