[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:
parent
b6b360bfab
commit
209c682ce9
@ -1,33 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
from glob import glob
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import struct
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
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
|
||||
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)
|
||||
dirname = Path(filename).parents[0]
|
||||
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
|
||||
config_h = dirname.joinpath("config.h")
|
||||
if config_h.exists() and config_h.stat().st_size < 100000:
|
||||
content = config_h.read_text()
|
||||
uid = VIAL_UID_REGEX.search(content)
|
||||
if uid:
|
||||
break
|
||||
path = os.path.dirname(path)
|
||||
if path.endswith("keyboards"):
|
||||
dirname = dirname.parents[0]
|
||||
if dirname.match("keyboards"):
|
||||
break
|
||||
|
||||
if not uid:
|
||||
@ -35,7 +35,8 @@ def main():
|
||||
error = 1
|
||||
continue
|
||||
|
||||
uid = uid[0].split(",")
|
||||
uid = uid[1].split(",")
|
||||
uid.reverse()
|
||||
uid = [int(x, 16) for x in uid]
|
||||
uid = struct.pack("BBBBBBBB", *uid).hex()
|
||||
uid_to_keyboards[uid].add(keyboard)
|
||||
|
Loading…
Reference in New Issue
Block a user