Added script to check for RPi/AVR variable consistency
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 15 Jan 2017 05:11:49 +0000 (21:11 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Sun, 15 Jan 2017 05:11:49 +0000 (21:11 -0800)
scripts/check-config-vars.py [new file with mode: 0755]

diff --git a/scripts/check-config-vars.py b/scripts/check-config-vars.py
new file mode 100755 (executable)
index 0000000..5b9c484
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+
+'''Check that the configuration variable template used on the RPi matches the
+variables used in the AVR'''
+
+import sys
+import json
+
+templ = json.load(open('src/resources/config-template.json', 'r'))
+vars = json.load(open('avr/build/vars.json', 'r'))
+
+
+def check(section):
+    errors = 0
+
+    for name, entry in section.items():
+        if 'type' in entry:
+            ok = False
+
+            if 'code' in entry and not entry['code'] in vars:
+                print('"%s" with code "%s" not found' % (name, entry['code']))
+
+            else: ok = True
+
+            if not ok: errors += 1
+
+        else: errors += check(entry)
+
+    return errors
+
+
+errors = check(templ)
+print('\n%d errors' % errors)
+sys.exit(errors != 0)