返回 ppt-master
import_diagnostics.py
根目录 / skills / ppt-master / scripts / pptx_to_svg / import_diagnostics.py
1 """Structured diagnostics for tolerant PPTX-to-SVG import."""
2
3 from __future__ import annotations
4
5 from dataclasses import asdict, dataclass
6
7
8 @dataclass(frozen=True)
9 class ImportDiagnostic:
10 """Describe one source-owned construct that required import recovery."""
11
12 code: str
13 message: str
14 fallback: str
15 part_path: str = ""
16 slide_index: int | None = None
17 shape_id: str = ""
18 shape_name: str = ""
19 shape_kind: str = ""
20 severity: str = "warning"
21
22 def to_dict(self) -> dict[str, object]:
23 """Return the stable JSON representation."""
24 return {
25 key: value
26 for key, value in asdict(self).items()
27 if value not in {"", None}
28 }
29
30
31 def append_diagnostic(
32 diagnostics: list[ImportDiagnostic],
33 diagnostic: ImportDiagnostic,
34 ) -> None:
35 """Append one diagnostic while suppressing duplicate layered/flat reports."""
36 if diagnostic not in diagnostics:
37 diagnostics.append(diagnostic)
38
38 lines PYTHON