[CI] detect clang-formatted VIAL_KEYBOARD_UID (#428)

* fix: detect clang-formatted VIAL_KEYBOARD_UIDs

* style: match UID output to "About..." in Vial GUI
This commit is contained in:
Less/Rikki 2023-03-28 21:51:14 -04:00 committed by GitHub
parent b6b360bfab
commit 209c682ce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,33 +1,33 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from glob import glob from glob import glob
import os from pathlib import Path
import re import re
import sys import sys
import struct import struct
from collections import defaultdict from collections import defaultdict
def main(): def main():
VIAL_UID_REGEX = re.compile(r"#\s*define\s+VIAL_KEYBOARD_UID\s+(?:\\(?:\n|\r)\s*)*{\s*((?:0(?:x|X)(?:[0-9a-fA-F]){2}\s*,\s*){7}(?:0(?:x|X)(?:[0-9a-fA-F]){2}))\s*}")
error = 0 error = 0
uid_to_keyboards = defaultdict(set) uid_to_keyboards = defaultdict(set)
for filename in glob("keyboards/**/vial.json", recursive=True): for filename in glob("keyboards/**/vial.json", recursive=True):
keyboard = filename[10:-10].split("/keymaps/")[0] keyboard = filename[10:-10].split("/keymaps/")[0]
path = os.path.dirname(filename) dirname = Path(filename).parents[0]
uid = None uid = None
while True: while True:
config_h = os.path.join(path, "config.h") config_h = dirname.joinpath("config.h")
if os.path.exists(config_h): if config_h.exists() and config_h.stat().st_size < 100000:
with open(config_h, "r") as inf: content = config_h.read_text()
for line in inf: uid = VIAL_UID_REGEX.search(content)
uid = re.findall(r"#define.*VIAL_KEYBOARD_UID.*{(.*)}", line)
if uid:
break
if uid: if uid:
break break
path = os.path.dirname(path) dirname = dirname.parents[0]
if path.endswith("keyboards"): if dirname.match("keyboards"):
break break
if not uid: if not uid:
@ -35,7 +35,8 @@ def main():
error = 1 error = 1
continue continue
uid = uid[0].split(",") uid = uid[1].split(",")
uid.reverse()
uid = [int(x, 16) for x in uid] uid = [int(x, 16) for x in uid]
uid = struct.pack("BBBBBBBB", *uid).hex() uid = struct.pack("BBBBBBBB", *uid).hex()
uid_to_keyboards[uid].add(keyboard) uid_to_keyboards[uid].add(keyboard)