"""Persistent LibreOffice/OpenOffice user profiles for headless UNO runs.""" from __future__ import annotations import os import tempfile from pathlib import Path # Marks first-start / registration wizard as done (OpenOffice + LibreOffice). _REGISTRY_SEED = """ true true """ def profile_dir(engine: str) -> Path: """Writable profile reused across conversions (avoids OO registration every run).""" root = os.environ.get("LOCALAPPDATA") or os.environ.get("APPDATA") or tempfile.gettempdir() path = Path(root) / "md2gost" / "office-profiles" / engine path.mkdir(parents=True, exist_ok=True) return path def ensure_profile_seeded(profile_root: Path) -> None: """Pre-seed registry so OpenOffice does not show the registration wizard.""" marker = profile_root / ".md2gost-seeded" user_dir = profile_root / "user" user_dir.mkdir(parents=True, exist_ok=True) xcu = user_dir / "registrymodifications.xcu" if not xcu.is_file(): xcu.write_text(_REGISTRY_SEED, encoding="utf-8") if not marker.is_file(): marker.write_text("1", encoding="utf-8")