|
| 1 | +from glob import glob |
| 2 | +from time import time |
| 3 | +from collections import defaultdict |
| 4 | + |
| 5 | +from avulto import DMI |
| 6 | + |
| 7 | +def check_duplicate_names(dmi: DMI) -> list[str]: |
| 8 | + states = set() |
| 9 | + failures = [] |
| 10 | + for state in dmi.states(): |
| 11 | + # Movement states have the same name as their non-movement counterparts |
| 12 | + if (state.name, state.movement) in states: |
| 13 | + duplicates.append(f"duplicate state name `{state.name}`") |
| 14 | + states.add((state.name, state.movement)) |
| 15 | + return failures |
| 16 | + |
| 17 | +def check_conflicted(dmi: DMI) -> list[str]: |
| 18 | + failures = [] |
| 19 | + for state in dmi.state_names(): |
| 20 | + if '!CONFLICT!' in state: |
| 21 | + failures.append(f"conflicted state {state}") |
| 22 | + return failures |
| 23 | + |
| 24 | +ICON_CHECKS = [ |
| 25 | + check_duplicate_names, |
| 26 | + check_conflicted, |
| 27 | +] |
| 28 | + |
| 29 | +if __name__ == "__main__": |
| 30 | + print("check_icons started") |
| 31 | + |
| 32 | + count = 0 |
| 33 | + exit_code = 0 |
| 34 | + start = time() |
| 35 | + |
| 36 | + findings = defaultdict(list) |
| 37 | + |
| 38 | + for dmi_path in glob("**/*.dmi", recursive=True): |
| 39 | + dmi = DMI.from_file(dmi_path) |
| 40 | + for check in ICON_CHECKS: |
| 41 | + if failures := check(dmi): |
| 42 | + findings[dmi_path].extend(failures) |
| 43 | + count += 1 |
| 44 | + |
| 45 | + if findings: |
| 46 | + exit_code = 1 |
| 47 | + |
| 48 | + for filename in sorted(findings.keys()): |
| 49 | + failures = findings[filename] |
| 50 | + for failure in sorted(failures): |
| 51 | + print(f"{filename}: {failure}") |
| 52 | + |
| 53 | + end = time() |
| 54 | + print(f"\ncheck_icons checked {count} files in {end - start:.2f}s") |
| 55 | + |
| 56 | + exit(exit_code) |
0 commit comments