forked from AG_QGIS/Plugin_SN_Basis
Wrappe modular aufgebaut, Tests erfolgreich, Menüleiste und Werzeugleiste werden eingetragen (QT6 und QT5)- (Es fehlen noch Fachplugins, um zu prüfen, ob es auch wirklich in QGIS geht)
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
"""
|
||||
sn_basis/modules/linkpruefer.py – Prüfung von URLs und lokalen Links.
|
||||
Verwendet syswrapper und qgisqt_wrapper.
|
||||
Gibt pruef_ergebnis an den Pruefmanager zurück.
|
||||
Verwendet Wrapper und gibt pruef_ergebnis an den Pruefmanager zurück.
|
||||
"""
|
||||
|
||||
from sn_basis.functions.syswrapper import (
|
||||
file_exists,
|
||||
is_file,
|
||||
join_path,
|
||||
)
|
||||
from pathlib import Path
|
||||
|
||||
from sn_basis.functions.qgisqt_wrapper import (
|
||||
from sn_basis.functions import (
|
||||
file_exists,
|
||||
join_path,
|
||||
network_head,
|
||||
)
|
||||
|
||||
from sn_basis.modules.Pruefmanager import pruef_ergebnis
|
||||
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis, PruefAktion
|
||||
|
||||
|
||||
class Linkpruefer:
|
||||
@@ -33,14 +30,18 @@ class Linkpruefer:
|
||||
# Hilfsfunktionen
|
||||
# ---------------------------------------------------------
|
||||
|
||||
def _pfad(self, relativer_pfad: str) -> str:
|
||||
"""Erzeugt einen OS-unabhängigen Pfad relativ zum Basisverzeichnis."""
|
||||
def _pfad(self, relativer_pfad: str) -> Path:
|
||||
"""
|
||||
Erzeugt einen OS‑unabhängigen Pfad relativ zum Basisverzeichnis.
|
||||
"""
|
||||
if not self.basis:
|
||||
return relativer_pfad
|
||||
return Path(relativer_pfad)
|
||||
return join_path(self.basis, relativer_pfad)
|
||||
|
||||
def _ist_url(self, text: str) -> bool:
|
||||
"""Einfache URL-Erkennung."""
|
||||
"""
|
||||
Einfache URL-Erkennung.
|
||||
"""
|
||||
return text.startswith("http://") or text.startswith("https://")
|
||||
|
||||
# ---------------------------------------------------------
|
||||
@@ -58,7 +59,7 @@ class Linkpruefer:
|
||||
ok=False,
|
||||
meldung="Es wurde kein Link angegeben.",
|
||||
aktion="leer",
|
||||
pfad=None,
|
||||
kontext=None,
|
||||
)
|
||||
|
||||
# -----------------------------------------------------
|
||||
@@ -88,7 +89,7 @@ class Linkpruefer:
|
||||
ok=False,
|
||||
meldung=f"Die URL '{url}' konnte nicht geprüft werden.",
|
||||
aktion="netzwerkfehler",
|
||||
pfad=url,
|
||||
kontext=url,
|
||||
)
|
||||
|
||||
if reply.error != 0:
|
||||
@@ -96,14 +97,14 @@ class Linkpruefer:
|
||||
ok=False,
|
||||
meldung=f"Die URL '{url}' ist nicht erreichbar.",
|
||||
aktion="url_nicht_erreichbar",
|
||||
pfad=url,
|
||||
kontext=url,
|
||||
)
|
||||
|
||||
return pruef_ergebnis(
|
||||
ok=True,
|
||||
meldung="URL ist erreichbar.",
|
||||
aktion="ok",
|
||||
pfad=url,
|
||||
kontext=url,
|
||||
)
|
||||
|
||||
# ---------------------------------------------------------
|
||||
@@ -122,20 +123,12 @@ class Linkpruefer:
|
||||
ok=False,
|
||||
meldung=f"Der Pfad '{eingabe}' wurde nicht gefunden.",
|
||||
aktion="pfad_nicht_gefunden",
|
||||
pfad=pfad,
|
||||
)
|
||||
|
||||
if not is_file(pfad):
|
||||
return pruef_ergebnis(
|
||||
ok=False,
|
||||
meldung=f"Der Pfad '{eingabe}' ist keine Datei.",
|
||||
aktion="kein_dateipfad",
|
||||
pfad=pfad,
|
||||
kontext=pfad,
|
||||
)
|
||||
|
||||
return pruef_ergebnis(
|
||||
ok=True,
|
||||
meldung="Dateipfad ist gültig.",
|
||||
aktion="ok",
|
||||
pfad=pfad,
|
||||
kontext=pfad,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user