Отличное форматирование

This commit is contained in:
2026-05-26 14:59:25 +03:00
parent 2b139a18b3
commit e3a615cb50
49 changed files with 1294 additions and 501 deletions

72
Report/scripts/check_images.py Normal file → Executable file
View File

@@ -1,51 +1,61 @@
#!/usr/bin/env python3
"""Verify IMAGES_REGISTRY.md entries exist on disk and match .typ references."""
"""Verify Report/images files exist; fail on missing diagram PNGs."""
from __future__ import annotations
import re
import sys
from pathlib import Path
REQUIRED_READY = {
f"fig_{i:02d}_" for i in range(1, 5)
} | {f"fig_11_"} | {f"fig_{i:02d}_" for i in range(14, 24)}
WARN_PLACEHOLDER = {f"fig_{i:02d}_" for i in range(5, 11)} | {f"fig_12_"} | {f"fig_13_"}
def main() -> int:
report = Path(__file__).resolve().parent.parent
repo = report.parent
report = Path(__file__).resolve().parents[1]
images = report / "images"
registry = images / "IMAGES_REGISTRY.md"
typ = report / "Пояснительная_записка_ПытковРЕ.typ"
errors = 0
text = registry.read_text(encoding="utf-8")
errors: list[str] = []
warns: list[str] = []
if not registry.exists():
print("Missing IMAGES_REGISTRY.md", file=sys.stderr)
return 1
for line in text.splitlines():
if "|" not in line or "fig_" not in line:
continue
cols = [c.strip() for c in line.split("|")]
if len(cols) < 4:
continue
fname, status = cols[2], cols[3]
if not fname.startswith("fig_"):
continue
path = images / fname
if not path.is_file():
errors.append(f"missing file: {fname}")
continue
if status == "placeholder":
for prefix in WARN_PLACEHOLDER:
if fname.startswith(prefix):
warns.append(f"placeholder: {fname}")
break
elif status == "ready":
for prefix in REQUIRED_READY:
if fname.startswith(prefix):
if path.stat().st_size < 500:
errors.append(f"too small (placeholder?): {fname}")
break
rows = re.findall(
r"\|\s*\d+\s*\|\s*([^\|]+?)\s*\|\s*(\w+)\s*\|",
registry.read_text(encoding="utf-8"),
)
rows = [(f.strip(), s.strip()) for f, s in rows if f.startswith("fig_")]
for fname, status in rows:
p = images / fname
if not p.exists():
print(f"MISSING file: {fname} (status {status})", file=sys.stderr)
errors += 1
elif status == "ready" and p.stat().st_size < 1000:
print(f"WARN small file: {fname}", file=sys.stderr)
if typ.exists():
text = typ.read_text(encoding="utf-8")
for m in re.finditer(r'image\("(?:Report/)?images/([^"]+)"', text):
f = images / m.group(1)
if not f.exists():
print(f"MISSING in typ: images/{m.group(1)}", file=sys.stderr)
errors += 1
for w in warns:
print(f"WARN {w}", file=sys.stderr)
for e in errors:
print(f"ERROR {e}", file=sys.stderr)
if errors:
print(f"check_images: {errors} error(s)", file=sys.stderr)
return 1
print("check_images: OK", file=sys.stderr)
print(f"OK: images check passed ({len(list(images.glob('fig_*')))} files)")
return 0
if __name__ == "__main__":
raise SystemExit(main())
sys.exit(main())