66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
"""Route table/listing continuation post-processing to Word or UNO backends."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from ..word_fix import FixResult, fix_continuations
|
|
from .detect import DEFAULT_OFFICE_ENGINE, OfficeInstall, resolve_office_engine
|
|
from .uno_fix import fix_continuations_uno
|
|
|
|
|
|
def fix_continuations_with_engine(
|
|
path: str,
|
|
*,
|
|
engine: str = DEFAULT_OFFICE_ENGINE,
|
|
install: OfficeInstall | None = None,
|
|
tables: bool = True,
|
|
listings: bool = True,
|
|
repeat_header: bool = False,
|
|
) -> FixResult:
|
|
"""
|
|
Split cross-page tables/listings using the selected office engine.
|
|
|
|
``engine`` is ``auto|word|libre|openoffice``. Pass a concrete ``engine`` plus
|
|
``install`` from ``resolve_office_engine`` to skip a second resolve. On
|
|
missing backend returns ``ok=False`` with a reason; conversion should
|
|
continue.
|
|
"""
|
|
if install is not None and engine in ("word", "libre", "openoffice"):
|
|
resolved = engine
|
|
else:
|
|
resolved, install = resolve_office_engine(engine)
|
|
if resolved is None or install is None:
|
|
if engine == "auto":
|
|
return FixResult(
|
|
False,
|
|
message=(
|
|
"Пост-разрыв таблиц пропущен: не найден Word, LibreOffice "
|
|
"или OpenOffice."
|
|
),
|
|
)
|
|
labels = {
|
|
"word": "Microsoft Word (Windows + pywin32)",
|
|
"libre": "LibreOffice (soffice + program/python)",
|
|
"openoffice": "OpenOffice (soffice + program/python)",
|
|
}
|
|
return FixResult(
|
|
False,
|
|
message=f"Пост-разрыв таблиц пропущен: нужен {labels.get(engine, engine)}.",
|
|
)
|
|
|
|
if resolved == "word":
|
|
return fix_continuations(
|
|
path,
|
|
tables=tables,
|
|
listings=listings,
|
|
repeat_header=repeat_header,
|
|
)
|
|
|
|
assert install.soffice_path and install.python_path
|
|
return fix_continuations_uno(
|
|
path,
|
|
install=install,
|
|
tables=tables,
|
|
listings=listings,
|
|
repeat_header=repeat_header,
|
|
)
|