Files
md_to_gost/md2gost/office/uno_profile.py
T
Igor20264 daa84f8bce
Example document / build (push) Has been cancelled
Python application / build (push) Has been cancelled
v0.5.6
2026-09-22 18:49:09 +03:00

42 lines
1.5 KiB
Python

"""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 = """<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Setup" oor:package="org.openoffice.Office">
<node oor:name="Office">
<prop oor:name="ooSetupCompleted" oor:type="xs:boolean">
<value>true</value>
</prop>
<prop oor:name="FirstStartWizardCompleted" oor:type="xs:boolean">
<value>true</value>
</prop>
</node>
</oor:component-data>
"""
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")