forked from vial-kb/vial-qmk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ci_vial_verify_uid.py
executable file
·53 lines (43 loc) · 1.46 KB
/
ci_vial_verify_uid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
from glob import glob
import os
import re
import sys
import struct
from collections import defaultdict
def main():
error = 0
uid_to_keyboards = defaultdict(set)
for filename in glob("keyboards/**/vial.json", recursive=True):
keyboard = filename[10:-10].split("/keymaps/")[0]
path = os.path.dirname(filename)
uid = None
while True:
config_h = os.path.join(path, "config.h")
if os.path.exists(config_h):
with open(config_h, "r") as inf:
for line in inf:
uid = re.findall(r"#define.*VIAL_KEYBOARD_UID.*{(.*)}", line)
if uid:
break
if uid:
break
path = os.path.dirname(path)
if path.endswith("keyboards"):
break
if not uid:
print("Keyboard {} does not define a VIAL_KEYBOARD_UID".format(keyboard))
error = 1
continue
uid = uid[0].split(",")
uid = [int(x, 16) for x in uid]
uid = struct.pack("BBBBBBBB", *uid).hex()
uid_to_keyboards[uid].add(keyboard)
print("{} uses UID {}".format(keyboard, uid))
for uid, keyboards in uid_to_keyboards.items():
if len(keyboards) > 1:
print("UID {} duplicated: {}".format(uid, keyboards))
error = 1
return error
if __name__ == "__main__":
sys.exit(main())