Files
FreeCADWasmDev/tools/generate_capability_runtime_index.py
wangdequan 9a7c4f0335 Save FreeCAD Web workspace sources and user validation evidence
IFC native binding remains incomplete; preserve accurate test results.
2026-09-15 22:01:58 +08:00

33 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Merge API, object, format and module dispositions into one capability index."""
from __future__ import annotations
import hashlib
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
api_path = ROOT / "docs/p6/python-api-manifest.json"
object_path = ROOT / "docs/p6/object-contract-matrix.json"
format_path = ROOT / "docs/format-api-inventory.json"
module_path = ROOT / "docs/web-parity-matrix.json"
api = json.loads(api_path.read_text(encoding="utf-8"))
objects = json.loads(object_path.read_text(encoding="utf-8"))["records"]
formats = json.loads(format_path.read_text(encoding="utf-8"))["formats"]
modules = json.loads(module_path.read_text(encoding="utf-8"))["rows"]
records = []
for row in api["records"]:
records.append(["api:" + row["id"], "api", row["module"], row["disposition"], row["tier"], row["family"]])
for row in objects:
records.append(["object:" + row["id"], "object", row["module"], row["status"], row["adapterFamily"], ",".join(row["capabilities"])])
for index, row in enumerate(formats):
extension = str(row.get("extension") or row.get("class") or "").lower()
records.append([f"format:{row['module']}:{extension}:{row['direction']}:{index}", "format", row["module"], "indexed", extension, row["direction"]])
for row in modules:
records.append(["module:" + row["module"], "module", row["module"], row["web_status"], str(row["gui_dependency"]), str(row["python_api_count"])])
output = {"schema": "freecad-web-capability-runtime-index/v1", "sources": {"api": {"path": "docs/p6/python-api-manifest.json", "sha256": hashlib.sha256(api_path.read_bytes()).hexdigest()}, "objects": {"path": "docs/p6/object-contract-matrix.json", "sha256": hashlib.sha256(object_path.read_bytes()).hexdigest()}, "formats": {"path": "docs/format-api-inventory.json", "sha256": hashlib.sha256(format_path.read_bytes()).hexdigest()}, "modules": {"path": "docs/web-parity-matrix.json", "sha256": hashlib.sha256(module_path.read_bytes()).hexdigest()}}, "counts": {"api": len(api["records"]), "object": len(objects), "format": len(formats), "module": len(modules), "total": len(records)}, "records": records, "boundaries": ["capability state is not native completion evidence", "GUI/external/restricted state must be enforced by command adapters"]}
out = ROOT / "web/public/api/capability-runtime-index.json"
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(output, ensure_ascii=False, separators=(",", ":")) + "\n", encoding="utf-8")
print(json.dumps({"output": str(out.relative_to(ROOT)), "counts": output["counts"], "bytes": out.stat().st_size, "sha256": hashlib.sha256(out.read_bytes()).hexdigest()}, ensure_ascii=False))