42 lines
1.5 KiB
Python
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")
|