Files
Plugin_SN_Basis/modules/stilpruefer.py

81 lines
2.6 KiB
Python
Raw Normal View History

"""
sn_basis/modules/stilpruefer.py Prüfung von Layerstilen.
Prüft ausschließlich, ob ein Stilpfad gültig ist.
Die Anwendung erfolgt später über eine Aktion.
"""
2026-03-12 16:14:02 +01:00
import os
2026-03-12 16:14:02 +01:00
from sn_basis.functions.os_wrapper import is_absolute_path
from sn_basis.functions.sys_wrapper import get_plugin_root, file_exists, join_path
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis
class Stilpruefer:
"""
Prüft, ob ein Stilpfad gültig ist und angewendet werden kann.
Keine Seiteneffekte, keine QGIS-Aufrufe.
"""
def __init__(self):
pass
# ---------------------------------------------------------
# Hauptfunktion
# ---------------------------------------------------------
def pruefe(self, stil_pfad: str) -> pruef_ergebnis:
"""
Prüft einen Stilpfad.
Rückgabe: pruef_ergebnis
"""
# -----------------------------------------------------
# 1. Kein Stil angegeben → OK
# -----------------------------------------------------
if not stil_pfad:
return pruef_ergebnis(
ok=True,
meldung="Kein Stil angegeben.",
aktion="ok",
kontext=None,
)
2026-03-12 16:14:02 +01:00
pfad = str(stil_pfad)
if not is_absolute_path(pfad):
plugin_root = get_plugin_root()
pfad = str(join_path(plugin_root, "sn_plan41", "assets", pfad))
# -----------------------------------------------------
# 2. Datei existiert nicht
# -----------------------------------------------------
if not file_exists(pfad):
return pruef_ergebnis(
ok=False,
meldung=f"Die Stil-Datei '{stil_pfad}' wurde nicht gefunden.",
aktion="datei_nicht_gefunden",
kontext=pfad,
)
# -----------------------------------------------------
# 3. Falsche Endung
# -----------------------------------------------------
2026-03-12 16:14:02 +01:00
if os.path.splitext(pfad)[1].lower() != ".qml":
return pruef_ergebnis(
ok=False,
meldung="Die Stil-Datei muss die Endung '.qml' haben.",
aktion="falsche_endung",
kontext=pfad,
)
# -----------------------------------------------------
# 4. Stil ist gültig → Anwendung später
# -----------------------------------------------------
return pruef_ergebnis(
ok=True,
meldung="Stil-Datei ist gültig.",
aktion="stil_anwendbar",
kontext=pfad,
)