362e089be0
Der Nutzer hat recht: Der Ordner war voller Entwicklungs-Muell. Jetzt ist sauber getrennt: ROOT (was der Nutzer sieht und braucht): - run.py = das Programm - hms_app/ = der Anwendungscode - HMS MediaEngine.app = macOS Doppelklick-Starter - HMS-Start.vbs = Windows Doppelklick-Starter - HMS-Install.vbs = Windows Erst-Installation - HMS-Mac-Install.command = macOS Homebrew-Installation - HMS-Portable-Install.command = macOS Portable-Installation (16GB-Fix) - installer_gui.py = grafischer Installer - launcher.pyw + launcher_core.py = interne Start-Logik - LIESMICH.txt = 10-Zeilen-Kurzanleitung - .gitignore _entwicklung/ (alles andere, NICHT benoetigt): - packages/ apps/ native/ plugins/ tools/ schemas/ tests/ docs/ build/ fixture_profiles/ - PLAN.md STATUS.md ERRORS.md TEST_REPORT.md CHANGELOG.md README.md - pyproject.toml uv.lock setup_*.sh/ps1 make_mac_app.py Diese Trennung gilt ab sofort fuer alle Commits. Der Nutzer kann _entwicklung/ loeschen wenn er Platz braucht - die App laeuft ohne. Verifiziert: App startet nach Aufraeumen unveraendert (Health 200).
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""Stabile IDs (PLAN.md §3.6, §10.1).
|
|
|
|
- UUIDs für alle Show-Objekte.
|
|
- Persistente node_id: einmal erzeugt, dauerhaft gespeichert; unabhängig
|
|
von IP-Adresse und Hostname (§6.3).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import uuid
|
|
from pathlib import Path
|
|
|
|
|
|
def new_uuid() -> str:
|
|
"""Stabile UUID für Show-Objekte (Layer, Effekte, Outputs, ...)."""
|
|
return str(uuid.uuid4())
|
|
|
|
|
|
def _machine_independent_seed() -> bytes:
|
|
"""Einstreu ohne IP/Hostname: OS-Urandom hat Priorität (§6.3)."""
|
|
return os.urandom(16)
|
|
|
|
|
|
def new_node_id() -> str:
|
|
"""Erzeugt eine neue, netzwerkunabhängige node_id (UUIDv4)."""
|
|
return str(uuid.UUID(bytes=_machine_independent_seed(), version=4))
|
|
|
|
|
|
def persistent_node_id(identity_file: Path) -> str:
|
|
"""Lädt die node_id aus identity_file oder erzeugt sie genau einmal.
|
|
|
|
IP-Wechsel ändern die node_id nicht; doppelte Vergabe über die Datei
|
|
wird durch exklusives Erzeugen (O_EXCL) verhindert.
|
|
"""
|
|
identity_file = Path(identity_file)
|
|
if identity_file.exists():
|
|
existing = identity_file.read_text(encoding="utf-8").strip()
|
|
if existing:
|
|
uuid.UUID(existing) # Validierung: muss UUID sein
|
|
return existing
|
|
identity_file.parent.mkdir(parents=True, exist_ok=True)
|
|
candidate = new_node_id()
|
|
try:
|
|
fd = os.open(identity_file, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600)
|
|
with os.fdopen(fd, "w", encoding="utf-8") as fh:
|
|
fh.write(candidate)
|
|
return candidate
|
|
except FileExistsError:
|
|
existing = identity_file.read_text(encoding="utf-8").strip()
|
|
if not existing:
|
|
raise
|
|
return existing
|