aboutsummaryrefslogtreecommitdiff
path: root/devtools/export_framesed_classes.py
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-10-21 20:08:53 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-10-21 20:08:53 +0200
commita1e355b8ceb12ac66c9d82e7786df4c3c40be479 (patch)
tree9d69cf196ec00e85009e1037a3a314d703466ac3 /devtools/export_framesed_classes.py
downloadframesed-a1e355b8ceb12ac66c9d82e7786df4c3c40be479.tar.gz
framesed-a1e355b8ceb12ac66c9d82e7786df4c3c40be479.zip
Diffstat (limited to '')
-rw-r--r--devtools/export_framesed_classes.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/devtools/export_framesed_classes.py b/devtools/export_framesed_classes.py
new file mode 100644
index 0000000..e02752a
--- /dev/null
+++ b/devtools/export_framesed_classes.py
@@ -0,0 +1,46 @@
+"""Generate C class metadata from the model-ordered index,mid,display_name CSV."""
+
+import argparse
+import csv
+import json
+from pathlib import Path
+
+
+def render(path: Path) -> str:
+ with path.open(newline="", encoding="utf-8") as source:
+ rows = list(csv.DictReader(source))
+ if len(rows) != 447:
+ raise ValueError("frame_mn10 requires exactly 447 classes")
+ mids = set()
+ labels = set()
+ lines = ["/* Model output order; regenerate with make regenerate-classes. */"]
+ for index, row in enumerate(rows):
+ mid, label = row["mid"], row["display_name"]
+ if int(row["index"]) != index:
+ raise ValueError("class indices must be contiguous and ordered from zero")
+ if not mid or not label or mid in mids or label in labels:
+ raise ValueError("class IDs and labels must be nonempty and unique")
+ if any(ord(c) < 32 for c in mid + label):
+ raise ValueError("class metadata must not contain control characters")
+ mids.add(mid)
+ labels.add(label)
+ lines.append(f" {{{json.dumps(mid)}, {json.dumps(label)}}},")
+ return "\n".join(lines) + "\n"
+
+
+def main() -> None:
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("labels", type=Path)
+ parser.add_argument("output", type=Path)
+ parser.add_argument("--check", action="store_true")
+ args = parser.parse_args()
+ content = render(args.labels)
+ if args.check:
+ if args.output.read_text(encoding="utf-8") != content:
+ parser.exit(1, f"{args.output}: regenerate with make regenerate-classes\n")
+ else:
+ args.output.write_text(content, encoding="utf-8")
+
+
+if __name__ == "__main__":
+ main()