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
|
import yaml
from typing import Set
from fingerprints.types.common import TYPES_PATH, TypesList
def check_types_file() -> None:
with open(TYPES_PATH, "r") as fh:
data: TypesList = yaml.safe_load(fh)
mains: Set[str] = set()
forms: Set[str] = set()
for type in data["types"]:
main = type["main"].lower()
type["main"] = type["main"]
if main in mains:
print("DUPLICATE MAIN", repr(main))
elif main in forms:
print("MAIN IS FORM ELSEHWERE", main)
mains.add(main)
forms.add(main)
cur_forms: Set[str] = set()
for form in type["forms"]:
form = form.lower()
if form == main:
continue
cur_forms.add(form)
if form in forms:
print("DUPLICATE FORM", form)
forms.add(form)
type["forms"] = sorted(cur_forms)
# print(type)
data["types"] = sorted(data["types"], key=lambda t: t["main"])
with open(TYPES_PATH, "wb") as fh:
fh.write(
yaml.dump(
data,
allow_unicode=True,
encoding="utf-8",
sort_keys=False,
)
)
if __name__ == "__main__":
check_types_file()
|