Гостовый puml

This commit is contained in:
2026-05-30 18:25:54 +03:00
parent 7bb62d0152
commit ee2c3a198c
41 changed files with 16484 additions and 18317 deletions

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""Приводит fig_*.puml к оформлению под ГОСТ: !include темы, без title и локальных skinparam."""
from __future__ import annotations
import re
from pathlib import Path
PUML_DIR = Path(__file__).resolve().parents[1] / "puml"
INCLUDE_LINE = "!include _gost-theme.inc.puml\n"
def strip_title_and_skinparam(text: str) -> str:
lines = text.splitlines(keepends=True)
out: list[str] = []
i = 0
while i < len(lines):
line = lines[i]
stripped = line.strip()
if stripped.startswith("skinparam"):
if "{" in stripped and "}" not in stripped:
i += 1
while i < len(lines) and "}" not in lines[i]:
i += 1
if i < len(lines):
i += 1
else:
i += 1
continue
if stripped.startswith("title"):
if stripped == "title":
i += 1
while i < len(lines) and lines[i].strip() != "end title":
i += 1
if i < len(lines):
i += 1
continue
i += 1
continue
if stripped in ("BackgroundColor", "BorderColor", "FontColor") or stripped.endswith(
("#F8F8F8", "#333333", "#E8F4FF", "#FFFDE7", "#F9A825")
):
i += 1
continue
if stripped == "}" and out and out[-1].strip().startswith("!include"):
i += 1
continue
out.append(line)
i += 1
return "".join(out)
def normalize_file(path: Path) -> bool:
text = path.read_text(encoding="utf-8")
original = text
text = strip_title_and_skinparam(text)
if INCLUDE_LINE.strip() not in text:
m = re.match(r"(@startuml\s+\S+\s*\n)", text)
if m:
text = text[: m.end()] + INCLUDE_LINE + text[m.end() :]
text = re.sub(r"\n{3,}", "\n\n", text)
if text != original:
path.write_text(text, encoding="utf-8")
return True
return False
def main() -> int:
changed = 0
for path in sorted(PUML_DIR.glob("fig_*.puml")):
if normalize_file(path):
changed += 1
print(f"updated: {path.name}")
print(f"Done. {changed} file(s) changed.")
return 0
if __name__ == "__main__":
raise SystemExit(main())

View File

@@ -6,6 +6,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPORT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PUML_DIR="$REPORT_DIR/puml"
IMG_DIR="$REPORT_DIR/images"
GOST_CFG="$PUML_DIR/plantuml-gost.cfg"
mkdir -p "$IMG_DIR"
@@ -26,6 +27,10 @@ if [[ ! -f "$JAR" ]]; then
exit 1
fi
if [[ -f "$GOST_CFG" ]]; then
python3 "$SCRIPT_DIR/normalize_puml_gost.py" >/dev/null
fi
shopt -s nullglob
PUML_FILES=("$PUML_DIR"/fig_*.puml)
if ((${#PUML_FILES[@]} == 0)); then
@@ -39,6 +44,8 @@ export PLANTUML_LIMIT_SIZE="${PLANTUML_LIMIT_SIZE:-16384}"
-DPLANTUML_LIMIT_SIZE="$PLANTUML_LIMIT_SIZE" \
-Xmx3g \
-jar "$JAR" \
-charset UTF-8 -tpng -o "$IMG_DIR" "${PUML_FILES[@]}"
-charset UTF-8 -tpng \
${GOST_CFG:+-config "$GOST_CFG"} \
-o "$IMG_DIR" "${PUML_FILES[@]}"
echo "Done. $(ls -1 "$IMG_DIR"/fig_*.png 2>/dev/null | wc -l) PNG in images/"