"""Prüft auf neuere Programmversionen im zentralen SMB-Verzeichnis.""" import re from pathlib import Path UPDATE_DIR = Path(r"j:\Fachbereiche\BO\Produktionsschule\Maßnahmeunterlagen\20_Personal\05_Tätigkeitsnachweise ESF\Nachweise-automatisiert-generieren") VERSION_PATTERN = re.compile(r"Tätigkeitsnachweis-Generator v(\d+)\.(\d+)\.(\d+)(?:\.\d+)?\.(zip|exe)$", re.IGNORECASE) CHANGELOG_PATTERN = re.compile(r"^## \[(\d+)\.(\d+)(?:\.(\d+))?\]", re.MULTILINE) def get_latest_version(): match = CHANGELOG_PATTERN.search(Path(__file__).with_name("CHANGELOG.md").read_text(encoding="utf-8")) current = tuple(int(part or 0) for part in match.groups()) if match else (0, 0, 0) try: available = UPDATE_DIR.exists() except OSError: available = False if not available: return current, None newer = [] try: paths = UPDATE_DIR.iterdir() for path in paths: found = VERSION_PATTERN.fullmatch(path.name) if found: version = tuple(int(found.group(i)) for i in range(1, 4)) if version > current: newer.append((version, path)) except OSError: return current, None if newer: return current, max(newer) return current, None def main() -> int: current, latest = get_latest_version() print(f"[INFO] Lokale Version: v{'.'.join(map(str, current))}") if latest: version, path = latest print(f"[HINWEIS] Neuere Version verfügbar: v{'.'.join(map(str, version))}") print(f"[HINWEIS] Datei: {path}") else: print("[INFO] Keine neuere Version gefunden oder Update-Verzeichnis nicht erreichbar.") return 0 if __name__ == "__main__": raise SystemExit(main())