ecddcef586
Record created/edited/deleted-in versions per page; add History.md and update workflow docs.
65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
"""Read 1C configuration version from dump tree."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
_VERSION_TAG = re.compile(r"<Version>([^<]+)</Version>")
|
|
_NAME_TAG = re.compile(
|
|
r"<Name>([^<]+)</Name>",
|
|
)
|
|
|
|
|
|
def config_root_from_src(src_root: Path) -> Path:
|
|
"""src/ → configuration root (parent that usually has VERSION + Configuration.xml)."""
|
|
src_root = Path(src_root).resolve()
|
|
if src_root.name == "src":
|
|
return src_root.parent
|
|
return src_root
|
|
|
|
|
|
def read_config_version(src_root: Path) -> str:
|
|
"""
|
|
Resolve configuration version.
|
|
|
|
Priority:
|
|
1. <config_root>/VERSION
|
|
2. <config_root>/src/Configuration.xml → <Version>
|
|
3. <src_root>/Configuration.xml → <Version>
|
|
"""
|
|
src_root = Path(src_root)
|
|
root = config_root_from_src(src_root)
|
|
version_file = root / "VERSION"
|
|
if version_file.is_file():
|
|
text = version_file.read_text(encoding="utf-8-sig", errors="ignore").strip()
|
|
if text:
|
|
return text.splitlines()[0].strip()
|
|
|
|
for xml_path in (
|
|
root / "src" / "Configuration.xml",
|
|
src_root / "Configuration.xml",
|
|
root / "Configuration.xml",
|
|
):
|
|
if not xml_path.is_file():
|
|
continue
|
|
raw = xml_path.read_text(encoding="utf-8-sig", errors="ignore")
|
|
m = _VERSION_TAG.search(raw)
|
|
if m:
|
|
return m.group(1).strip()
|
|
|
|
return "unknown"
|
|
|
|
|
|
def read_config_name(src_root: Path) -> str | None:
|
|
src_root = Path(src_root)
|
|
root = config_root_from_src(src_root)
|
|
xml_path = root / "src" / "Configuration.xml"
|
|
if not xml_path.is_file():
|
|
xml_path = src_root / "Configuration.xml"
|
|
if not xml_path.is_file():
|
|
return None
|
|
raw = xml_path.read_text(encoding="utf-8-sig", errors="ignore")
|
|
m = _NAME_TAG.search(raw)
|
|
return m.group(1).strip() if m else None
|