Compare commits
1 Commits
oldstable
...
439de5527a
| Author | SHA1 | Date | |
|---|---|---|---|
| 439de5527a |
@@ -1,289 +0,0 @@
|
|||||||
name: Release Plugin
|
|
||||||
run-name: "Release | ${{ github.ref_name }}"
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
runs-on: alpine-latest
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Notwendige Abhängigkeiten installieren
|
|
||||||
shell: sh
|
|
||||||
run: |
|
|
||||||
apk add --no-cache git zip curl jq rsync bash
|
|
||||||
git config --global http.sslVerify false
|
|
||||||
|
|
||||||
- name: Code holen
|
|
||||||
run: |
|
|
||||||
# Tag aus GitHub Actions Kontext extrahieren
|
|
||||||
TAG="${GITHUB_REF#refs/tags/}"
|
|
||||||
|
|
||||||
# Repo-URL dynamisch aus vars und github.repository bauen
|
|
||||||
REPO_URL="https://${RELEASE_TOKEN}:x-oauth-basic@${{ vars.RELEASE_URL }}/${GITHUB_REPOSITORY}.git"
|
|
||||||
|
|
||||||
# Repository klonen
|
|
||||||
git clone "$REPO_URL" repo
|
|
||||||
cd repo
|
|
||||||
|
|
||||||
git checkout "$TAG"
|
|
||||||
env:
|
|
||||||
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
||||||
|
|
||||||
- name: Version und Kanal bestimmen
|
|
||||||
id: releaseinfo
|
|
||||||
run: |
|
|
||||||
TAG="${{ github.ref_name }}"
|
|
||||||
VERSION="${TAG#v}"
|
|
||||||
|
|
||||||
case "$TAG" in
|
|
||||||
*-unstable*)
|
|
||||||
CHANNEL="unstable"
|
|
||||||
DRAFT="false"
|
|
||||||
PRERELEASE="true"
|
|
||||||
;;
|
|
||||||
*-testing*)
|
|
||||||
CHANNEL="testing"
|
|
||||||
DRAFT="false"
|
|
||||||
PRERELEASE="true"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
CHANNEL="stable"
|
|
||||||
DRAFT="false"
|
|
||||||
PRERELEASE="false"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "channel=$CHANNEL" >> $GITHUB_OUTPUT
|
|
||||||
echo "draft=$DRAFT" >> $GITHUB_OUTPUT
|
|
||||||
echo "prerelease=$PRERELEASE" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: plugin.info einlesen
|
|
||||||
id: info
|
|
||||||
run: |
|
|
||||||
cd repo
|
|
||||||
while IFS='=' read -r key value; do
|
|
||||||
echo "$key=$value" >> $GITHUB_OUTPUT
|
|
||||||
done < plugin.info
|
|
||||||
|
|
||||||
- name: Changelog einlesen
|
|
||||||
id: changelog
|
|
||||||
run: |
|
|
||||||
cd repo
|
|
||||||
|
|
||||||
# Aktueller Block = alles vor dem ersten ---
|
|
||||||
CURRENT=$(awk '/^---/{exit} {print}' changelog.txt)
|
|
||||||
|
|
||||||
# Vollständige Historie = alles nach dem ersten ---
|
|
||||||
HISTORY=$(awk 'found{print} /^---/{found=1}' changelog.txt)
|
|
||||||
|
|
||||||
# Gitea Release Body zusammenbauen
|
|
||||||
VERSION="${{ steps.releaseinfo.outputs.version }}"
|
|
||||||
FULL=$(printf "## %s\n%s\n\n%s" "$VERSION" "$CURRENT" "$HISTORY")
|
|
||||||
|
|
||||||
echo "DEBUG | Aktueller Changelog:"
|
|
||||||
echo "$CURRENT"
|
|
||||||
|
|
||||||
# Für GITHUB_OUTPUT: Multiline via EOF-Marker
|
|
||||||
echo "current<<EOF" >> $GITHUB_OUTPUT
|
|
||||||
echo "$CURRENT" >> $GITHUB_OUTPUT
|
|
||||||
echo "EOF" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
echo "full<<EOF" >> $GITHUB_OUTPUT
|
|
||||||
echo "$FULL" >> $GITHUB_OUTPUT
|
|
||||||
echo "EOF" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: metadata.txt erzeugen
|
|
||||||
run: |
|
|
||||||
cd repo
|
|
||||||
|
|
||||||
# ------------------------ GEÄNDERT ------------------------
|
|
||||||
# Temporär die Vorlage aus dem hidden/templates Branch holen
|
|
||||||
git fetch origin hidden/templates
|
|
||||||
git checkout origin/hidden/templates -- metadata.template
|
|
||||||
TEMPLATE="metadata.template"
|
|
||||||
# -----------------------------------------------------------
|
|
||||||
|
|
||||||
# TEMPLATE="templates/metadata.template"
|
|
||||||
OUT="metadata.txt"
|
|
||||||
|
|
||||||
CONTENT=$(cat "$TEMPLATE")
|
|
||||||
|
|
||||||
CONTENT="${CONTENT//\{\{NAME\}\}/${{ steps.info.outputs.name }}}"
|
|
||||||
CONTENT="${CONTENT//\{\{QGIS_MIN\}\}/${{ steps.info.outputs.qgisMinimumVersion }}}"
|
|
||||||
CONTENT="${CONTENT//\{\{QGIS_MAX\}\}/${{ steps.info.outputs.qgisMaximumVersion }}}"
|
|
||||||
CONTENT="${CONTENT//\{\{DESCRIPTION\}\}/${{ steps.info.outputs.description }}}"
|
|
||||||
CONTENT="${CONTENT//\{\{VERSION\}\}/${{ steps.releaseinfo.outputs.version }}}"
|
|
||||||
CONTENT="${CONTENT//\{\{AUTHOR\}\}/${{ steps.info.outputs.author }}}"
|
|
||||||
CONTENT="${CONTENT//\{\{EMAIL\}\}/${{ steps.info.outputs.email }}}"
|
|
||||||
CONTENT="${CONTENT//\{\{HOMEPAGE\}\}/${{ vars.RELEASE_URL }}/${GITHUB_REPOSITORY}}"
|
|
||||||
CONTENT="${CONTENT//\{\{TRACKER\}\}/${{ vars.RELEASE_URL }}/${GITHUB_REPOSITORY}}"
|
|
||||||
CONTENT="${CONTENT//\{\{REPOSITORY\}\}/${{ vars.RELEASE_URL }}/${GITHUB_REPOSITORY}}"
|
|
||||||
CONTENT="${CONTENT//\{\{EXPERIMENTAL\}\}/${{ steps.info.outputs.experimental }}}"
|
|
||||||
CONTENT="${CONTENT//\{\{DEPRECATED\}\}/${{ steps.info.outputs.deprecated }}}"
|
|
||||||
CONTENT="${CONTENT//\{\{QT6\}\}/${{ steps.info.outputs.supportsQt6 }}}"
|
|
||||||
|
|
||||||
printf "%s\n" "$CONTENT" > "$OUT"
|
|
||||||
rm $TEMPLATE
|
|
||||||
|
|
||||||
- name: ZIP-Datei erstellen
|
|
||||||
id: zip
|
|
||||||
run: |
|
|
||||||
cd repo
|
|
||||||
|
|
||||||
ZIP_FOLDER="${{ steps.info.outputs.zip_folder }}"
|
|
||||||
ZIP_FILE="${ZIP_FOLDER}.zip"
|
|
||||||
|
|
||||||
VERSION="${{ steps.releaseinfo.outputs.version }}"
|
|
||||||
REPO_NAME="${GITHUB_REPOSITORY##*/}"
|
|
||||||
#ZIP_NAME="${REPO_NAME}-${VERSION}.zip"
|
|
||||||
|
|
||||||
|
|
||||||
mkdir -p dist/${ZIP_FOLDER}
|
|
||||||
|
|
||||||
rsync -a \
|
|
||||||
--exclude='.git' \
|
|
||||||
--exclude='.gitea' \
|
|
||||||
--exclude='.plugin' \
|
|
||||||
--exclude='dist' \
|
|
||||||
./ dist/${ZIP_FOLDER}/
|
|
||||||
|
|
||||||
cd dist
|
|
||||||
zip -r "${ZIP_FILE}" "${ZIP_FOLDER}/" \
|
|
||||||
-x "*.pyc" -x "*/__pycache__/*"
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
echo "zip_file=${ZIP_FILE}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Gitea-Release erstellen
|
|
||||||
id: create_release
|
|
||||||
run: |
|
|
||||||
TAG="${{ github.ref_name }}"
|
|
||||||
VERSION="${{ steps.releaseinfo.outputs.version }}"
|
|
||||||
CHANNEL="${{ steps.releaseinfo.outputs.channel }}"
|
|
||||||
|
|
||||||
API_URL="https://${{ vars.RELEASE_URL }}/api/v1/repos/${GITHUB_REPOSITORY}/releases"
|
|
||||||
|
|
||||||
JSON=$(jq -n \
|
|
||||||
--arg tag "$TAG" \
|
|
||||||
--arg name "Version $VERSION" \
|
|
||||||
--arg body "${{ steps.changelog.outputs.current }}" \
|
|
||||||
--argjson draft "${{ steps.releaseinfo.outputs.draft }}" \
|
|
||||||
--argjson prerelease "${{ steps.releaseinfo.outputs.prerelease }}" \
|
|
||||||
'{tag_name: $tag, name: $name, body: $body, draft: $draft, prerelease: $prerelease}')
|
|
||||||
|
|
||||||
API_RESPONSE=$(curl -s -X POST "$API_URL" \
|
|
||||||
-H "accept: application/json" \
|
|
||||||
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "$JSON")
|
|
||||||
|
|
||||||
RELEASE_ID=$(echo "$API_RESPONSE" | jq -r '.id')
|
|
||||||
|
|
||||||
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
|
||||||
echo "Fehler beim Erstellen des Releases!"
|
|
||||||
echo "$API_RESPONSE"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: ZIP-Datei hochladen
|
|
||||||
run: |
|
|
||||||
RELEASE_ID="${{ steps.create_release.outputs.release_id }}"
|
|
||||||
ZIP_FILE="${{ steps.zip.outputs.zip_file }}"
|
|
||||||
|
|
||||||
API_URL="https://${{ vars.RELEASE_URL }}/api/v1/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${ZIP_FILE}"
|
|
||||||
|
|
||||||
curl -s -X POST "$API_URL" \
|
|
||||||
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/zip" \
|
|
||||||
--data-binary "@repo/dist/${ZIP_FILE}" \
|
|
||||||
-o upload_response.json
|
|
||||||
|
|
||||||
# Optional: Fehlerprüfung
|
|
||||||
if jq -e '.id' upload_response.json >/dev/null 2>&1; then
|
|
||||||
echo "ZIP erfolgreich hochgeladen."
|
|
||||||
else
|
|
||||||
echo "Fehler beim Hochladen der ZIP!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Payload erzeugen
|
|
||||||
run: |
|
|
||||||
cd repo
|
|
||||||
|
|
||||||
VERSION="${{ steps.releaseinfo.outputs.version }}"
|
|
||||||
CHANNEL="${{ steps.releaseinfo.outputs.channel }}"
|
|
||||||
ZIP_FILE="${{ steps.zip.outputs.zip_file }}"
|
|
||||||
|
|
||||||
DOWNLOAD_URL="https://${{ vars.RELEASE_URL }}/${GITHUB_REPOSITORY}/releases/download/${{ github.ref_name }}/${ZIP_FILE}"
|
|
||||||
|
|
||||||
jq -n \
|
|
||||||
--arg name "${{ steps.info.outputs.name }}" \
|
|
||||||
--arg version "$VERSION" \
|
|
||||||
--arg channel "$CHANNEL" \
|
|
||||||
--arg description "${{ steps.info.outputs.description }}" \
|
|
||||||
--arg author "${{ steps.info.outputs.author }}" \
|
|
||||||
--arg email "${{ steps.info.outputs.email }}" \
|
|
||||||
--arg qgis_min "${{ steps.info.outputs.qgisMinimumVersion }}" \
|
|
||||||
--arg qgis_max "${{ steps.info.outputs.qgisMaximumVersion }}" \
|
|
||||||
--arg homepage "${{ vars.RELEASE_URL }}/${GITHUB_REPOSITORY}" \
|
|
||||||
--arg tracker "${{ vars.RELEASE_URL }}/${GITHUB_REPOSITORY}" \
|
|
||||||
--arg repository "${{ vars.RELEASE_URL }}/${GITHUB_REPOSITORY}" \
|
|
||||||
--arg experimental "${{ steps.info.outputs.experimental }}" \
|
|
||||||
--arg deprecated "${{ steps.info.outputs.deprecated }}" \
|
|
||||||
--arg qt6 "${{ steps.info.outputs.supportsQt6 }}" \
|
|
||||||
--arg id "${{ steps.info.outputs.zip_folder }}" \
|
|
||||||
--arg url "$DOWNLOAD_URL" \
|
|
||||||
--arg changelog "${{ steps.changelog.outputs.current }}" \
|
|
||||||
'{
|
|
||||||
name: $name,
|
|
||||||
version: $version,
|
|
||||||
channel: $channel,
|
|
||||||
description: $description,
|
|
||||||
author: $author,
|
|
||||||
email: $email,
|
|
||||||
qgis_min: $qgis_min,
|
|
||||||
qgis_max: $qgis_max,
|
|
||||||
homepage: $homepage,
|
|
||||||
tracker: $tracker,
|
|
||||||
repository: $repository,
|
|
||||||
experimental: $experimental,
|
|
||||||
deprecated: $deprecated,
|
|
||||||
qt6: $qt6,
|
|
||||||
id: $id,
|
|
||||||
url: $url,
|
|
||||||
changelog: $changelog
|
|
||||||
}' > payload.json
|
|
||||||
|
|
||||||
- name: Repository aktualisieren
|
|
||||||
run: |
|
|
||||||
OWNER="AG_QGIS"
|
|
||||||
WORKFLOW="update.yml"
|
|
||||||
|
|
||||||
PAYLOAD_B64=$(base64 -w0 repo/payload.json)
|
|
||||||
|
|
||||||
FULL_NAME="${{ steps.info.outputs.name }}"
|
|
||||||
NAME=$(echo "$FULL_NAME" | awk -F'|' '{gsub(/^ +| +$/,"",$2); print $2}')
|
|
||||||
TAG="${{ steps.releaseinfo.outputs.version }}"
|
|
||||||
|
|
||||||
JSON="{\"ref\":\"hidden/workflows\",\"inputs\":{\"payload\":\"$PAYLOAD_B64\",\"name\":\"$NAME\",\"tag\":\"$TAG\"}}"
|
|
||||||
|
|
||||||
#JSON="{\"ref\":\"hidden/workflows\",\"inputs\":{\"payload\":\"$PAYLOAD_B64\"}}"
|
|
||||||
|
|
||||||
echo "DEBUG | Sende JSON:"
|
|
||||||
echo "$JSON"
|
|
||||||
|
|
||||||
curl -X POST \
|
|
||||||
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "$JSON" \
|
|
||||||
"https://${{ vars.RELEASE_URL }}/api/v1/repos/${OWNER}/Repository/actions/workflows/${WORKFLOW}/dispatches"
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
__pdoc__ = {
|
|
||||||
"main": False,
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,7 @@ from .ly_metadata_wrapper import (
|
|||||||
is_layer_editable,
|
is_layer_editable,
|
||||||
)
|
)
|
||||||
from .ly_style_wrapper import apply_style
|
from .ly_style_wrapper import apply_style
|
||||||
from .dialog_wrapper import ask_yes_no, ask_overwrite_append_cancel_custom
|
from .dialog_wrapper import ask_yes_no
|
||||||
|
|
||||||
from .message_wrapper import (
|
from .message_wrapper import (
|
||||||
_get_message_bar,
|
_get_message_bar,
|
||||||
|
|||||||
@@ -1,84 +1,62 @@
|
|||||||
"""
|
"""
|
||||||
sn_basis/functions/dialog_wrapper.py – Benutzer-Dialoge (Qt5/6/Mock-kompatibel)
|
sn_basis/functions/dialog_wrapper.py – Benutzer-Dialoge
|
||||||
"""
|
|
||||||
from typing import Any
|
|
||||||
from typing import Literal, Optional
|
|
||||||
from sn_basis.functions.qt_wrapper import (
|
|
||||||
QMessageBox, YES, NO, CANCEL, QT_VERSION, exec_dialog, ICON_QUESTION,
|
|
||||||
|
|
||||||
|
Dieser Wrapper kapselt alle Benutzer-Dialoge (z. B. Ja/Nein-Abfragen)
|
||||||
|
und sorgt dafür, dass sie sowohl in QGIS als auch im Mock-/Testmodus
|
||||||
|
einheitlich funktionieren.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
# Import der abstrahierten Qt-Klassen aus dem qt_wrapper.
|
||||||
|
# QMessageBox, YES und NO sind bereits kompatibel zu Qt5/Qt6
|
||||||
|
# und im Mock-Modus durch Dummy-Objekte ersetzt.
|
||||||
|
from sn_basis.functions.qt_wrapper import (
|
||||||
|
QMessageBox,
|
||||||
|
YES,
|
||||||
|
NO,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# Öffentliche API
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
def ask_yes_no(
|
def ask_yes_no(
|
||||||
title: str,
|
title: str,
|
||||||
message: str,
|
message: str,
|
||||||
default: bool = True,
|
default: bool = False,
|
||||||
parent: Any = None,
|
parent: Any = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
Stellt Ja/Nein-Frage. Funktioniert in PyQt5/6 UND Mock-Modus.
|
Stellt dem Benutzer eine Ja/Nein-Frage.
|
||||||
|
|
||||||
|
- In einer echten QGIS-Umgebung wird ein QMessageBox-Dialog angezeigt.
|
||||||
|
- Im Mock-/Testmodus wird kein Dialog geöffnet, sondern der Default-Wert
|
||||||
|
zurückgegeben, damit Tests ohne UI laufen können.
|
||||||
|
|
||||||
|
:param title: Titel des Dialogs
|
||||||
|
:param message: Nachrichtentext
|
||||||
|
:param default: Rückgabewert im Fehler- oder Mock-Fall
|
||||||
|
:param parent: Optionales Parent-Widget
|
||||||
|
:return: True bei "Ja", False bei "Nein"
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if QT_VERSION == 0: # Mock-Modus
|
# Definiert die beiden Buttons, die angezeigt werden sollen.
|
||||||
print(f"🔍 Mock-Modus: ask_yes_no('{title}') → {default}")
|
buttons = QMessageBox.Yes | QMessageBox.No
|
||||||
return default
|
|
||||||
|
|
||||||
# ✅ KORREKT: Verwende YES/NO-Aliase aus qt_wrapper!
|
|
||||||
buttons = YES | NO
|
|
||||||
default_button = YES if default else NO
|
|
||||||
|
|
||||||
|
# Öffnet den Dialog (oder im Mock-Modus: simuliert ihn).
|
||||||
result = QMessageBox.question(
|
result = QMessageBox.question(
|
||||||
parent, title, message, buttons, default_button
|
parent,
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
buttons,
|
||||||
|
YES if default else NO, # Vorauswahl abhängig vom Default
|
||||||
)
|
)
|
||||||
|
|
||||||
# ✅ int(result) == int(YES) funktioniert Qt5/6/Mock
|
# Gibt True zurück, wenn der Benutzer "Ja" gewählt hat.
|
||||||
print(f"DEBUG ask_yes_no: result={result}, YES={YES}, match={int(result) == int(YES)}")
|
return result == YES
|
||||||
return int(result) == int(YES)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"⚠️ ask_yes_no Fehler: {e}")
|
# Falls Qt nicht verfügbar ist (Mock/CI), wird der Default-Wert genutzt.
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
OverwriteDecision = Optional[Literal["overwrite", "append", "cancel"]]
|
|
||||||
|
|
||||||
|
|
||||||
def ask_overwrite_append_cancel_custom(
|
|
||||||
parent,
|
|
||||||
title: str,
|
|
||||||
message: str,
|
|
||||||
) -> Literal["overwrite", "append", "cancel"]:
|
|
||||||
"""Zeigt Dialog mit benutzerdefinierten Buttons: Überschreiben/Anhängen/Abbrechen.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
parent :
|
|
||||||
Eltern-Widget oder None.
|
|
||||||
title : str
|
|
||||||
Dialog-Titel.
|
|
||||||
message : str
|
|
||||||
Hauptmeldung mit Erklärung.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Literal["overwrite", "append", "cancel"]
|
|
||||||
Genaue Entscheidung des Nutzers.
|
|
||||||
"""
|
|
||||||
msg = QMessageBox(parent)
|
|
||||||
msg.setIcon(ICON_QUESTION)
|
|
||||||
msg.setWindowTitle(title)
|
|
||||||
msg.setText(message)
|
|
||||||
|
|
||||||
# Eigene Buttons mit exakten Texten
|
|
||||||
overwrite_btn = msg.addButton("Überschreiben", QMessageBox.ButtonRole.AcceptRole)
|
|
||||||
append_btn = msg.addButton("Anhängen", QMessageBox.ButtonRole.ActionRole)
|
|
||||||
cancel_btn = msg.addButton("Abbrechen", QMessageBox.ButtonRole.RejectRole)
|
|
||||||
|
|
||||||
exec_dialog(msg)
|
|
||||||
|
|
||||||
clicked = msg.clickedButton()
|
|
||||||
if clicked == overwrite_btn:
|
|
||||||
return "overwrite"
|
|
||||||
elif clicked == append_btn:
|
|
||||||
return "append"
|
|
||||||
else: # cancel_btn
|
|
||||||
return "cancel"
|
|
||||||
|
|||||||
@@ -1,44 +1,23 @@
|
|||||||
# sn_basis/functions/ly_style_wrapper.py
|
# sn_basis/functions/ly_style_wrapper.py
|
||||||
|
|
||||||
from sn_basis.functions.ly_existence_wrapper import layer_exists
|
from sn_basis.functions.ly_existence_wrapper import layer_exists
|
||||||
from sn_basis.functions.sys_wrapper import get_plugin_root, join_path
|
from sn_basis.functions.sys_wrapper import (
|
||||||
from sn_basis.modules.stilpruefer import Stilpruefer
|
get_plugin_root,
|
||||||
from typing import Optional
|
join_path,
|
||||||
|
file_exists,
|
||||||
def apply_style(layer, style_name: str) -> bool:
|
|
||||||
"""
|
|
||||||
Wendet einen Layerstil an, sofern er gültig ist.
|
|
||||||
|
|
||||||
- Validierung erfolgt ausschließlich über Stilpruefer
|
|
||||||
- Keine eigenen Dateisystem- oder Endungsprüfungen
|
|
||||||
- Keine Seiteneffekte bei ungültigem Stil
|
|
||||||
"""
|
|
||||||
print(">>> apply_style() START")
|
|
||||||
|
|
||||||
if not layer_exists(layer):
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Stilpfad zusammensetzen
|
|
||||||
style_path = join_path(get_plugin_root(), "sn_verfahrensgebiet","styles", style_name)
|
|
||||||
|
|
||||||
# Stil prüfen
|
|
||||||
pruefer = Stilpruefer()
|
|
||||||
ergebnis = pruefer.pruefe(style_path)
|
|
||||||
print(">>> Stilprüfung:", ergebnis)
|
|
||||||
|
|
||||||
print(
|
|
||||||
f"[Stilprüfung] ok={ergebnis.ok} | "
|
|
||||||
f"aktion={ergebnis.aktion} | "
|
|
||||||
f"meldung={ergebnis.meldung}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if not ergebnis.ok:
|
def apply_style(layer, style_name: str) -> bool:
|
||||||
|
if not layer_exists(layer):
|
||||||
|
return False
|
||||||
|
|
||||||
|
style_path = join_path(get_plugin_root(), "styles", style_name)
|
||||||
|
if not file_exists(style_path):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Stil anwenden
|
|
||||||
try:
|
try:
|
||||||
ok, _ = layer.loadNamedStyle(str(ergebnis.kontext))
|
ok, _ = layer.loadNamedStyle(style_path)
|
||||||
if ok:
|
if ok:
|
||||||
getattr(layer, "triggerRepaint", lambda: None)()
|
getattr(layer, "triggerRepaint", lambda: None)()
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -36,9 +36,6 @@ try:
|
|||||||
Qgis as _Qgis,
|
Qgis as _Qgis,
|
||||||
QgsMapLayerProxyModel as _QgsMaplLayerProxyModel,
|
QgsMapLayerProxyModel as _QgsMaplLayerProxyModel,
|
||||||
QgsVectorFileWriter as _QgsVectorFileWriter,
|
QgsVectorFileWriter as _QgsVectorFileWriter,
|
||||||
QgsFeature as _QgsFeature,
|
|
||||||
QgsField as _QgsField,
|
|
||||||
QgsGeometry as _QgsGeometry,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
QgsProject = _QgsProject
|
QgsProject = _QgsProject
|
||||||
@@ -48,9 +45,6 @@ try:
|
|||||||
Qgis = _Qgis
|
Qgis = _Qgis
|
||||||
QgsMapLayerProxyModel = _QgsMaplLayerProxyModel
|
QgsMapLayerProxyModel = _QgsMaplLayerProxyModel
|
||||||
QgsVectorFileWriter = _QgsVectorFileWriter
|
QgsVectorFileWriter = _QgsVectorFileWriter
|
||||||
QgsFeature = _QgsFeature
|
|
||||||
QgsField = _QgsField
|
|
||||||
QgsGeometry = _QgsGeometry
|
|
||||||
|
|
||||||
QGIS_AVAILABLE = True
|
QGIS_AVAILABLE = True
|
||||||
|
|
||||||
|
|||||||
@@ -1,100 +1,90 @@
|
|||||||
"""
|
"""
|
||||||
sn_basis/functions/qt_wrapper.py – zentrale Qt-Abstraktion (PyQt6 primär / PyQt5 Fallback / Mock)
|
sn_basis/functions/qt_wrapper.py – zentrale Qt-Abstraktion (PyQt5 / PyQt6 / Mock)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Optional, Type, Any, Callable
|
from typing import Optional, Type, Any
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# Qt-Symbole (werden dynamisch gesetzt)
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
|
QDockWidget: Type[Any]
|
||||||
|
QMessageBox: Type[Any]
|
||||||
|
QFileDialog: Type[Any]
|
||||||
|
QEventLoop: Type[Any]
|
||||||
|
QUrl: Type[Any]
|
||||||
|
QNetworkRequest: Type[Any]
|
||||||
|
QNetworkReply: Type[Any]
|
||||||
|
QCoreApplication: Type[Any]
|
||||||
|
|
||||||
|
QWidget: Type[Any]
|
||||||
|
QGridLayout: Type[Any]
|
||||||
|
QLabel: Type[Any]
|
||||||
|
QLineEdit: Type[Any]
|
||||||
|
QGroupBox: Type[Any]
|
||||||
|
QVBoxLayout: Type[Any]
|
||||||
|
QPushButton: Type[Any]
|
||||||
|
QAction: Type[Any]
|
||||||
|
QMenu: Type[Any]
|
||||||
|
QToolBar: Type[Any]
|
||||||
|
QActionGroup: Type[Any]
|
||||||
|
QTabWidget: type
|
||||||
|
QToolButton: Type[Any]
|
||||||
|
QSizePolicy: Type[Any]
|
||||||
|
Qt: Type[Any]
|
||||||
|
QComboBox: Type[Any]
|
||||||
|
|
||||||
# Globale Qt-Symbole (werden dynamisch gesetzt)
|
|
||||||
QT_VERSION = 0 # 0 = Mock, 5 = PyQt5, 6 = PyQt6
|
|
||||||
YES: Optional[Any] = None
|
YES: Optional[Any] = None
|
||||||
NO: Optional[Any] = None
|
NO: Optional[Any] = None
|
||||||
CANCEL: Optional[Any] = None
|
CANCEL: Optional[Any] = None
|
||||||
ICON_QUESTION: Optional[Any] = None
|
ICON_QUESTION: Optional[Any] = None
|
||||||
|
|
||||||
|
QT_VERSION = 0 # 0 = Mock, 5 = PyQt5, 6 = PyQt6
|
||||||
# Qt-Klassen (werden dynamisch gesetzt)
|
|
||||||
QDockWidget: Type[Any] = object
|
|
||||||
QMessageBox: Type[Any] = object
|
|
||||||
QFileDialog: Type[Any] = object
|
|
||||||
QEventLoop: Type[Any] = object
|
|
||||||
QUrl: Type[Any] = object
|
|
||||||
QNetworkRequest: Type[Any] = object
|
|
||||||
QNetworkReply: Type[Any] = object
|
|
||||||
QCoreApplication: Type[Any] = object
|
|
||||||
QWidget: Type[Any] = object
|
|
||||||
QGridLayout: Type[Any] = object
|
|
||||||
QLabel: Type[Any] = object
|
|
||||||
QLineEdit: Type[Any] = object
|
|
||||||
QGroupBox: Type[Any] = object
|
|
||||||
QVBoxLayout: Type[Any] = object
|
|
||||||
QPushButton: Type[Any] = object
|
|
||||||
QAction: Type[Any] = object
|
|
||||||
QMenu: Type[Any] = object
|
|
||||||
QToolBar: Type[Any] = object
|
|
||||||
QActionGroup: Type[Any] = object
|
|
||||||
QTabWidget: Type[Any] = object
|
|
||||||
QToolButton: Type[Any] = object
|
|
||||||
QSizePolicy: Type[Any] = object
|
|
||||||
Qt: Type[Any] = object
|
|
||||||
QComboBox: Type[Any] = object
|
|
||||||
QHBoxLayout: Type[Any] = object
|
|
||||||
|
|
||||||
|
|
||||||
def exec_dialog(dialog: Any) -> Any:
|
def exec_dialog(dialog: Any) -> Any:
|
||||||
"""Führt Dialog modal aus (Qt6: exec(), Qt5: exec_(), Mock: YES)"""
|
raise NotImplementedError
|
||||||
raise NotImplementedError("Qt nicht initialisiert")
|
|
||||||
|
|
||||||
def debug_qt_status() -> None:
|
|
||||||
"""Debug: Zeigt Qt-Status für Troubleshooting."""
|
|
||||||
print(f"🔍 QT_VERSION: {QT_VERSION}")
|
|
||||||
print(f"🔍 QMessageBox Typ: {getattr(QMessageBox, '__name__', type(QMessageBox).__name__)}")
|
|
||||||
print(f"🔍 YES Wert: {YES} (Typ: {type(YES) if YES is not None else 'None'})")
|
|
||||||
|
|
||||||
if QT_VERSION == 0:
|
# ---------------------------------------------------------
|
||||||
print("❌ MOCK-MODUS AKTIV! Keine Dialoge möglich!")
|
# Versuch: PyQt6
|
||||||
elif QT_VERSION == 5:
|
# ---------------------------------------------------------
|
||||||
print("✅ PyQt5 geladen (Fallback) – Dialoge sollten funktionieren!")
|
|
||||||
elif QT_VERSION == 6:
|
|
||||||
print("✅ PyQt6 geladen (primär) – Dialoge sollten funktionieren!")
|
|
||||||
else:
|
|
||||||
print("❓ Unbekannte Qt-Version!")
|
|
||||||
|
|
||||||
# --------------------------- PYQT6 PRIMÄR ---------------------------
|
|
||||||
try:
|
try:
|
||||||
from qgis.PyQt.QtWidgets import (
|
from qgis.PyQt.QtWidgets import ( # type: ignore
|
||||||
QMessageBox as _QMessageBox,
|
QMessageBox as _QMessageBox,# type: ignore
|
||||||
QFileDialog as _QFileDialog,
|
QFileDialog as _QFileDialog,# type: ignore
|
||||||
QWidget as _QWidget,
|
QWidget as _QWidget,# type: ignore
|
||||||
QGridLayout as _QGridLayout,
|
QGridLayout as _QGridLayout,# type: ignore
|
||||||
QLabel as _QLabel,
|
QLabel as _QLabel,# type: ignore
|
||||||
QLineEdit as _QLineEdit,
|
QLineEdit as _QLineEdit,# type: ignore
|
||||||
QGroupBox as _QGroupBox,
|
QGroupBox as _QGroupBox,# type: ignore
|
||||||
QVBoxLayout as _QVBoxLayout,
|
QVBoxLayout as _QVBoxLayout,# type: ignore
|
||||||
QPushButton as _QPushButton,
|
QPushButton as _QPushButton,# type: ignore
|
||||||
QAction as _QAction,
|
QAction as _QAction,
|
||||||
QMenu as _QMenu,
|
QMenu as _QMenu,# type: ignore
|
||||||
QToolBar as _QToolBar,
|
QToolBar as _QToolBar,# type: ignore
|
||||||
QActionGroup as _QActionGroup,
|
QActionGroup as _QActionGroup,# type: ignore
|
||||||
QDockWidget as _QDockWidget,
|
QDockWidget as _QDockWidget,# type: ignore
|
||||||
QTabWidget as _QTabWidget,
|
QTabWidget as _QTabWidget,# type: ignore
|
||||||
QToolButton as _QToolButton,
|
QToolButton as _QToolButton,#type:ignore
|
||||||
QSizePolicy as _QSizePolicy,
|
QSizePolicy as _QSizePolicy,#type:ignore
|
||||||
QComboBox as _QComboBox,
|
QComboBox as _QComboBox,
|
||||||
QHBoxLayout as _QHBoxLayout,
|
|
||||||
)
|
|
||||||
from qgis.PyQt.QtCore import (
|
|
||||||
QEventLoop as _QEventLoop,
|
|
||||||
QUrl as _QUrl,
|
|
||||||
QCoreApplication as _QCoreApplication,
|
|
||||||
Qt as _Qt,
|
|
||||||
QVariant as _QVariant
|
|
||||||
)
|
|
||||||
from qgis.PyQt.QtNetwork import (
|
|
||||||
QNetworkRequest as _QNetworkRequest,
|
|
||||||
QNetworkReply as _QNetworkReply,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# ✅ ALLE GLOBALS ZUWEISEN
|
|
||||||
|
|
||||||
|
from qgis.PyQt.QtCore import ( # type: ignore
|
||||||
|
QEventLoop as _QEventLoop,# type: ignore
|
||||||
|
QUrl as _QUrl,# type: ignore
|
||||||
|
QCoreApplication as _QCoreApplication,# type: ignore
|
||||||
|
Qt as _Qt#type:ignore
|
||||||
|
)
|
||||||
|
from qgis.PyQt.QtNetwork import ( # type: ignore
|
||||||
|
QNetworkRequest as _QNetworkRequest,# type: ignore
|
||||||
|
QNetworkReply as _QNetworkReply,# type: ignore
|
||||||
|
)
|
||||||
QT_VERSION = 6
|
QT_VERSION = 6
|
||||||
QMessageBox = _QMessageBox
|
QMessageBox = _QMessageBox
|
||||||
QFileDialog = _QFileDialog
|
QFileDialog = _QFileDialog
|
||||||
@@ -120,38 +110,48 @@ try:
|
|||||||
QToolButton=_QToolButton
|
QToolButton=_QToolButton
|
||||||
QSizePolicy=_QSizePolicy
|
QSizePolicy=_QSizePolicy
|
||||||
QComboBox=_QComboBox
|
QComboBox=_QComboBox
|
||||||
QVariant = _QVariant
|
|
||||||
QHBoxLayout= _QHBoxLayout
|
|
||||||
# ✅ QT6 ENUMS
|
|
||||||
YES = QMessageBox.StandardButton.Yes
|
YES = QMessageBox.StandardButton.Yes
|
||||||
NO = QMessageBox.StandardButton.No
|
NO = QMessageBox.StandardButton.No
|
||||||
CANCEL = QMessageBox.StandardButton.Cancel
|
CANCEL = QMessageBox.StandardButton.Cancel
|
||||||
ICON_QUESTION = QMessageBox.Icon.Question
|
ICON_QUESTION = QMessageBox.Icon.Question
|
||||||
AcceptRole = QMessageBox.ButtonRole.AcceptRole
|
# ---------------------------------------------------------
|
||||||
ActionRole = QMessageBox.ButtonRole.ActionRole
|
# Qt6 Enum-Aliase (vereinheitlicht)
|
||||||
RejectRole = QMessageBox.ButtonRole.RejectRole
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
# Qt6 Enum-Aliase
|
|
||||||
ToolButtonTextBesideIcon = Qt.ToolButtonStyle.ToolButtonTextBesideIcon
|
ToolButtonTextBesideIcon = Qt.ToolButtonStyle.ToolButtonTextBesideIcon
|
||||||
ArrowDown = Qt.ArrowType.DownArrow
|
ArrowDown = Qt.ArrowType.DownArrow
|
||||||
ArrowRight = Qt.ArrowType.RightArrow
|
ArrowRight = Qt.ArrowType.RightArrow
|
||||||
|
# QSizePolicy Enum-Aliase (Qt6)
|
||||||
SizePolicyPreferred = QSizePolicy.Policy.Preferred
|
SizePolicyPreferred = QSizePolicy.Policy.Preferred
|
||||||
SizePolicyMaximum = QSizePolicy.Policy.Maximum
|
SizePolicyMaximum = QSizePolicy.Policy.Maximum
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# QDockWidget Feature-Aliase (Qt6)
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
DockWidgetMovable = QDockWidget.DockWidgetFeature.DockWidgetMovable
|
DockWidgetMovable = QDockWidget.DockWidgetFeature.DockWidgetMovable
|
||||||
DockWidgetFloatable = QDockWidget.DockWidgetFeature.DockWidgetFloatable
|
DockWidgetFloatable = QDockWidget.DockWidgetFeature.DockWidgetFloatable
|
||||||
DockWidgetClosable = QDockWidget.DockWidgetFeature.DockWidgetClosable
|
DockWidgetClosable = QDockWidget.DockWidgetFeature.DockWidgetClosable
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# Dock-Area-Aliase (Qt6)
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
DockAreaLeft = Qt.DockWidgetArea.LeftDockWidgetArea
|
DockAreaLeft = Qt.DockWidgetArea.LeftDockWidgetArea
|
||||||
DockAreaRight = Qt.DockWidgetArea.RightDockWidgetArea
|
DockAreaRight = Qt.DockWidgetArea.RightDockWidgetArea
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def exec_dialog(dialog: Any) -> Any:
|
def exec_dialog(dialog: Any) -> Any:
|
||||||
return dialog.exec()
|
return dialog.exec()
|
||||||
|
|
||||||
print(f"✅ qt_wrapper: PyQt6 geladen (QT_VERSION={QT_VERSION})")
|
# ---------------------------------------------------------
|
||||||
|
# Versuch: PyQt5
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
# --------------------------- PYQT5 FALLBACK ---------------------------
|
except Exception:
|
||||||
except (ImportError, AttributeError):
|
|
||||||
try:
|
try:
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (# type: ignore
|
||||||
QMessageBox as _QMessageBox,
|
QMessageBox as _QMessageBox,
|
||||||
QFileDialog as _QFileDialog,
|
QFileDialog as _QFileDialog,
|
||||||
QWidget as _QWidget,
|
QWidget as _QWidget,
|
||||||
@@ -170,22 +170,19 @@ except (ImportError, AttributeError):
|
|||||||
QToolButton as _QToolButton,
|
QToolButton as _QToolButton,
|
||||||
QSizePolicy as _QSizePolicy,
|
QSizePolicy as _QSizePolicy,
|
||||||
QComboBox as _QComboBox,
|
QComboBox as _QComboBox,
|
||||||
QHBoxLayout as _QHBoxLayout,
|
|
||||||
)
|
)
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (# type: ignore
|
||||||
QEventLoop as _QEventLoop,
|
QEventLoop as _QEventLoop,
|
||||||
QUrl as _QUrl,
|
QUrl as _QUrl,
|
||||||
QCoreApplication as _QCoreApplication,
|
QCoreApplication as _QCoreApplication,
|
||||||
Qt as _Qt,
|
Qt as _Qt,
|
||||||
QVariant as _QVariant
|
|
||||||
)
|
)
|
||||||
from PyQt5.QtNetwork import (
|
from PyQt5.QtNetwork import (# type: ignore
|
||||||
QNetworkRequest as _QNetworkRequest,
|
QNetworkRequest as _QNetworkRequest,
|
||||||
QNetworkReply as _QNetworkReply,
|
QNetworkReply as _QNetworkReply,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ✅ ALLE GLOBALS ZUWEISEN
|
|
||||||
QT_VERSION = 5
|
|
||||||
QMessageBox = _QMessageBox
|
QMessageBox = _QMessageBox
|
||||||
QFileDialog = _QFileDialog
|
QFileDialog = _QFileDialog
|
||||||
QEventLoop = _QEventLoop
|
QEventLoop = _QEventLoop
|
||||||
@@ -195,6 +192,8 @@ except (ImportError, AttributeError):
|
|||||||
QCoreApplication = _QCoreApplication
|
QCoreApplication = _QCoreApplication
|
||||||
Qt=_Qt
|
Qt=_Qt
|
||||||
QDockWidget = _QDockWidget
|
QDockWidget = _QDockWidget
|
||||||
|
|
||||||
|
|
||||||
QWidget = _QWidget
|
QWidget = _QWidget
|
||||||
QGridLayout = _QGridLayout
|
QGridLayout = _QGridLayout
|
||||||
QLabel = _QLabel
|
QLabel = _QLabel
|
||||||
@@ -209,45 +208,53 @@ except (ImportError, AttributeError):
|
|||||||
QTabWidget = _QTabWidget
|
QTabWidget = _QTabWidget
|
||||||
QToolButton=_QToolButton
|
QToolButton=_QToolButton
|
||||||
QSizePolicy=_QSizePolicy
|
QSizePolicy=_QSizePolicy
|
||||||
QComboBox = _QComboBox
|
ComboBox=_QComboBox
|
||||||
QVariant = _QVariant
|
|
||||||
QHBoxLayout = _QHBoxLayout
|
|
||||||
|
|
||||||
# ✅ PYQT5 ENUMS
|
|
||||||
YES = QMessageBox.Yes
|
YES = QMessageBox.Yes
|
||||||
NO = QMessageBox.No
|
NO = QMessageBox.No
|
||||||
CANCEL = QMessageBox.Cancel
|
CANCEL = QMessageBox.Cancel
|
||||||
ICON_QUESTION = QMessageBox.Question
|
ICON_QUESTION = QMessageBox.Question
|
||||||
AcceptRole = QMessageBox.AcceptRole
|
|
||||||
ActionRole = QMessageBox.ActionRole
|
|
||||||
RejectRole = QMessageBox.RejectRole
|
|
||||||
|
|
||||||
|
QT_VERSION = 5
|
||||||
|
|
||||||
|
# then try next backend
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# Qt5 Enum-Aliase (vereinheitlicht)
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
# PyQt5 Enum-Aliase
|
|
||||||
ToolButtonTextBesideIcon = Qt.ToolButtonTextBesideIcon
|
ToolButtonTextBesideIcon = Qt.ToolButtonTextBesideIcon
|
||||||
ArrowDown = Qt.DownArrow
|
ArrowDown = Qt.DownArrow
|
||||||
ArrowRight = Qt.RightArrow
|
ArrowRight = Qt.RightArrow
|
||||||
|
# QSizePolicy Enum-Aliase (Qt5)
|
||||||
SizePolicyPreferred = QSizePolicy.Preferred
|
SizePolicyPreferred = QSizePolicy.Preferred
|
||||||
SizePolicyMaximum = QSizePolicy.Maximum
|
SizePolicyMaximum = QSizePolicy.Maximum
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# QDockWidget Feature-Aliase (Qt5)
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
DockWidgetMovable = QDockWidget.DockWidgetMovable
|
DockWidgetMovable = QDockWidget.DockWidgetMovable
|
||||||
DockWidgetFloatable = QDockWidget.DockWidgetFloatable
|
DockWidgetFloatable = QDockWidget.DockWidgetFloatable
|
||||||
DockWidgetClosable = QDockWidget.DockWidgetClosable
|
DockWidgetClosable = QDockWidget.DockWidgetClosable
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# Dock-Area-Aliase (Qt5)
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
DockAreaLeft = Qt.LeftDockWidgetArea
|
DockAreaLeft = Qt.LeftDockWidgetArea
|
||||||
DockAreaRight = Qt.RightDockWidgetArea
|
DockAreaRight = Qt.RightDockWidgetArea
|
||||||
|
|
||||||
|
|
||||||
def exec_dialog(dialog: Any) -> Any:
|
def exec_dialog(dialog: Any) -> Any:
|
||||||
return dialog.exec_()
|
return dialog.exec_()
|
||||||
|
|
||||||
print(f"✅ qt_wrapper: PyQt5 Fallback geladen (QT_VERSION={QT_VERSION})")
|
# ---------------------------------------------------------
|
||||||
|
# Mock-Modus
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
# --------------------------- MOCK-MODUS ---------------------------
|
|
||||||
except Exception:
|
except Exception:
|
||||||
QT_VERSION = 0
|
QT_VERSION = 0
|
||||||
print("⚠️ qt_wrapper: Mock-Modus aktiviert (QT_VERSION=0)")
|
|
||||||
|
|
||||||
# Fake Enum für Bit-Operationen
|
|
||||||
class FakeEnum(int):
|
class FakeEnum(int):
|
||||||
def __or__(self, other: Any) -> "FakeEnum":
|
def __or__(self, other: int) -> "FakeEnum":
|
||||||
return FakeEnum(int(self) | int(other))
|
return FakeEnum(int(self) | int(other))
|
||||||
|
|
||||||
YES = FakeEnum(1)
|
YES = FakeEnum(1)
|
||||||
@@ -255,240 +262,66 @@ except (ImportError, AttributeError):
|
|||||||
CANCEL = FakeEnum(4)
|
CANCEL = FakeEnum(4)
|
||||||
ICON_QUESTION = FakeEnum(8)
|
ICON_QUESTION = FakeEnum(8)
|
||||||
|
|
||||||
# Im Mock-Block von qt_wrapper.py:
|
|
||||||
class _MockQMessageBox:
|
class _MockQMessageBox:
|
||||||
Yes = YES
|
Yes = YES
|
||||||
No = NO
|
No = NO
|
||||||
Cancel = CANCEL
|
Cancel = CANCEL
|
||||||
Question = ICON_QUESTION
|
Question = ICON_QUESTION
|
||||||
AcceptRole = 0
|
|
||||||
ActionRole = 3
|
|
||||||
RejectRole = 1
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def question(cls, parent, title, message, buttons, default_button):
|
|
||||||
"""Mock: Gibt immer default_button zurück"""
|
|
||||||
print(f"🔍 Mock QMessageBox.question: '{title}' → {default_button}")
|
|
||||||
return default_button
|
|
||||||
|
|
||||||
QMessageBox = _MockQMessageBox
|
QMessageBox = _MockQMessageBox
|
||||||
|
|
||||||
|
|
||||||
class _MockQFileDialog:
|
class _MockQFileDialog:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getOpenFileName(*args, **kwargs): return ("", "")
|
def getOpenFileName(*args, **kwargs):
|
||||||
|
return ("", "")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getSaveFileName(*args, **kwargs): return ("", "")
|
def getSaveFileName(*args, **kwargs):
|
||||||
|
return ("", "")
|
||||||
|
|
||||||
QFileDialog = _MockQFileDialog
|
QFileDialog = _MockQFileDialog
|
||||||
|
|
||||||
class _MockQEventLoop:
|
class _MockQEventLoop:
|
||||||
def exec(self) -> int: return 0
|
def exec(self) -> int:
|
||||||
def quit(self) -> None: pass
|
return 0
|
||||||
|
|
||||||
|
def quit(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
QEventLoop = _MockQEventLoop
|
QEventLoop = _MockQEventLoop
|
||||||
|
|
||||||
class _MockQUrl(str):
|
class _MockQUrl(str):
|
||||||
def isValid(self) -> bool: return True
|
def isValid(self) -> bool:
|
||||||
|
return True
|
||||||
|
|
||||||
QUrl = _MockQUrl
|
QUrl = _MockQUrl
|
||||||
|
|
||||||
class _MockQNetworkRequest:
|
class _MockQNetworkRequest:
|
||||||
def __init__(self, url: Any): self.url = url
|
def __init__(self, url: Any):
|
||||||
|
self.url = url
|
||||||
|
|
||||||
QNetworkRequest = _MockQNetworkRequest
|
QNetworkRequest = _MockQNetworkRequest
|
||||||
|
|
||||||
class _MockQNetworkReply:
|
class _MockQNetworkReply:
|
||||||
def error(self) -> int: return 0
|
def error(self) -> int:
|
||||||
def errorString(self) -> str: return ""
|
return 0
|
||||||
def readAll(self) -> bytes: return b""
|
|
||||||
def deleteLater(self) -> None: pass
|
def errorString(self) -> str:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def readAll(self) -> bytes:
|
||||||
|
return b""
|
||||||
|
|
||||||
|
def deleteLater(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
QNetworkReply = _MockQNetworkReply
|
QNetworkReply = _MockQNetworkReply
|
||||||
|
|
||||||
class _MockWidget: pass
|
class _MockWidget:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
class _MockLayout:
|
class _MockLayout:
|
||||||
def __init__(self, *args, **kwargs): self._widgets = []
|
|
||||||
def addWidget(self, widget): self._widgets.append(widget)
|
|
||||||
def addLayout(self, layout): pass
|
|
||||||
def addStretch(self, *args, **kwargs): pass
|
|
||||||
def setSpacing(self, *args, **kwargs): pass
|
|
||||||
def setContentsMargins(self, *args, **kwargs): pass
|
|
||||||
|
|
||||||
class _MockLabel:
|
|
||||||
def __init__(self, text: str = ""): self._text = text
|
|
||||||
class _MockLineEdit:
|
|
||||||
def __init__(self, *args, **kwargs): self._text = ""
|
|
||||||
def text(self) -> str: return self._text
|
|
||||||
def setText(self, value: str) -> None: self._text = value
|
|
||||||
|
|
||||||
class _MockButton:
|
|
||||||
def __init__(self, *args, **kwargs): self.clicked = lambda *a, **k: None
|
|
||||||
|
|
||||||
QWidget = _MockWidget
|
|
||||||
QGridLayout = _MockLayout
|
|
||||||
QLabel = _MockLabel
|
|
||||||
QLineEdit = _MockLineEdit
|
|
||||||
QGroupBox = _MockWidget
|
|
||||||
QVBoxLayout = _MockLayout
|
|
||||||
QPushButton = _MockButton
|
|
||||||
QCoreApplication = object()
|
|
||||||
|
|
||||||
class _MockQt:
|
|
||||||
ToolButtonTextBesideIcon = 0
|
|
||||||
ArrowDown = 1
|
|
||||||
ArrowRight = 2
|
|
||||||
LeftDockWidgetArea = 1
|
|
||||||
RightDockWidgetArea = 2
|
|
||||||
|
|
||||||
Qt = _MockQt()
|
|
||||||
ToolButtonTextBesideIcon = Qt.ToolButtonTextBesideIcon
|
|
||||||
ArrowDown = Qt.ArrowDown
|
|
||||||
ArrowRight = Qt.ArrowRight
|
|
||||||
DockAreaLeft = Qt.LeftDockWidgetArea
|
|
||||||
DockAreaRight = Qt.RightDockWidgetArea
|
|
||||||
|
|
||||||
class _MockQDockWidget(_MockWidget):
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self._object_name = ""
|
|
||||||
def setObjectName(self, name: str) -> None: self._object_name = name
|
|
||||||
def objectName(self) -> str: return self._object_name
|
|
||||||
def show(self) -> None: pass
|
|
||||||
def deleteLater(self) -> None: pass
|
|
||||||
|
|
||||||
QDockWidget = _MockQDockWidget
|
|
||||||
|
|
||||||
class _MockAction:
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self._checked = False
|
|
||||||
self.triggered = lambda *a, **k: None
|
|
||||||
def setToolTip(self, text: str) -> None: pass
|
|
||||||
def setCheckable(self, value: bool) -> None: pass
|
|
||||||
def setChecked(self, value: bool) -> None: self._checked = value
|
|
||||||
|
|
||||||
class _MockMenu:
|
|
||||||
def __init__(self, *args, **kwargs): self._actions = []
|
|
||||||
def addAction(self, action): self._actions.append(action)
|
|
||||||
def removeAction(self, action):
|
|
||||||
if action in self._actions: self._actions.remove(action)
|
|
||||||
def clear(self): self._actions.clear()
|
|
||||||
def menuAction(self): return self
|
|
||||||
|
|
||||||
class _MockToolBar:
|
|
||||||
def __init__(self, *args, **kwargs): self._actions = []
|
|
||||||
def setObjectName(self, name: str) -> None: pass
|
|
||||||
def addAction(self, action): self._actions.append(action)
|
|
||||||
def removeAction(self, action):
|
|
||||||
if action in self._actions: self._actions.remove(action)
|
|
||||||
def clear(self): self._actions.clear()
|
|
||||||
|
|
||||||
class _MockActionGroup:
|
|
||||||
def __init__(self, *args, **kwargs): self._actions = []
|
|
||||||
def setExclusive(self, value: bool) -> None: pass
|
|
||||||
def addAction(self, action): self._actions.append(action)
|
|
||||||
|
|
||||||
QAction = _MockAction
|
|
||||||
QMenu = _MockMenu
|
|
||||||
QToolBar = _MockToolBar
|
|
||||||
QActionGroup = _MockActionGroup
|
|
||||||
|
|
||||||
class _MockToolButton(_MockWidget):
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self._checked = False
|
|
||||||
self.toggled = lambda *a, **k: None
|
|
||||||
def setText(self, text: str) -> None: pass
|
|
||||||
def setCheckable(self, value: bool) -> None: pass
|
|
||||||
def setChecked(self, value: bool) -> None: self._checked = value
|
|
||||||
def setToolButtonStyle(self, *args, **kwargs): pass
|
|
||||||
def setArrowType(self, *args, **kwargs): pass
|
|
||||||
def setStyleSheet(self, *args, **kwargs): pass
|
|
||||||
|
|
||||||
QToolButton = _MockToolButton
|
|
||||||
|
|
||||||
class _MockQSizePolicy:
|
|
||||||
Preferred = 3
|
|
||||||
Maximum = 2
|
|
||||||
|
|
||||||
QSizePolicy = _MockQSizePolicy
|
|
||||||
SizePolicyPreferred = QSizePolicy.Preferred
|
|
||||||
SizePolicyMaximum = QSizePolicy.Maximum
|
|
||||||
DockWidgetMovable = 1
|
|
||||||
DockWidgetFloatable = 2
|
|
||||||
DockWidgetClosable = 4
|
|
||||||
|
|
||||||
class _MockTabWidget:
|
|
||||||
def __init__(self, *args, **kwargs): self._tabs = []
|
|
||||||
def addTab(self, widget, title: str): self._tabs.append((widget, title))
|
|
||||||
|
|
||||||
QTabWidget = _MockTabWidget
|
|
||||||
|
|
||||||
class _MockComboBox:
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
self._items = []
|
|
||||||
self._index = -1
|
|
||||||
self.currentTextChanged = type('Signal', (), {'connect': lambda s, cb: None, 'emit': lambda s, v: None})()
|
|
||||||
def addItem(self, text: str) -> None: self._items.append(text)
|
|
||||||
def addItems(self, items): [self.addItem(it) for it in items]
|
|
||||||
def findText(self, text: str) -> int:
|
|
||||||
return self._items.index(text) if text in self._items else -1
|
|
||||||
def setCurrentIndex(self, idx: int) -> None:
|
|
||||||
if 0 <= idx < len(self._items):
|
|
||||||
self._index = idx
|
|
||||||
self.currentTextChanged.emit(self.currentText())
|
|
||||||
def setCurrentText(self, text: str) -> None:
|
|
||||||
idx = self.findText(text)
|
|
||||||
if idx >= 0: self.setCurrentIndex(idx)
|
|
||||||
def currentText(self) -> str:
|
|
||||||
return self._items[self._index] if 0 <= self._index < len(self._items) else ""
|
|
||||||
|
|
||||||
QComboBox = _MockComboBox
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
|
||||||
# Mock für QVariant
|
|
||||||
# ---------------------------
|
|
||||||
|
|
||||||
class _MockQVariant:
|
|
||||||
"""
|
|
||||||
Minimaler Ersatz für QtCore.QVariant.
|
|
||||||
|
|
||||||
Ziel:
|
|
||||||
- Werte transparent durchreichen
|
|
||||||
- Typ-Konstanten bereitstellen
|
|
||||||
- Keine Qt-Abhängigkeiten
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Typ-Konstanten (symbolisch, Werte egal)
|
|
||||||
Invalid = 0
|
|
||||||
Int = 1
|
|
||||||
Double = 2
|
|
||||||
String = 3
|
|
||||||
Bool = 4
|
|
||||||
Date = 5
|
|
||||||
DateTime = 6
|
|
||||||
|
|
||||||
def __init__(self, value: Any = None):
|
|
||||||
self._value = value
|
|
||||||
|
|
||||||
def value(self) -> Any:
|
|
||||||
return self._value
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
|
||||||
return f"QVariant({self._value!r})"
|
|
||||||
|
|
||||||
# Optional: automatische Entpackung
|
|
||||||
def __int__(self):
|
|
||||||
return int(self._value)
|
|
||||||
|
|
||||||
def __float__(self):
|
|
||||||
return float(self._value)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return str(self._value)
|
|
||||||
QVariant = _MockQVariant
|
|
||||||
|
|
||||||
class _MockQHBoxLayout:
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self._widgets = []
|
self._widgets = []
|
||||||
|
|
||||||
@@ -506,9 +339,242 @@ except (ImportError, AttributeError):
|
|||||||
|
|
||||||
def setContentsMargins(self, *args, **kwargs):
|
def setContentsMargins(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
QHBoxLayout = _MockQHBoxLayout
|
|
||||||
|
|
||||||
|
|
||||||
|
class _MockLabel:
|
||||||
|
def __init__(self, text: str = ""):
|
||||||
|
self._text = text
|
||||||
|
|
||||||
|
class _MockLineEdit:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self._text = ""
|
||||||
|
|
||||||
|
def text(self) -> str:
|
||||||
|
return self._text
|
||||||
|
|
||||||
|
def setText(self, value: str) -> None:
|
||||||
|
self._text = value
|
||||||
|
|
||||||
|
class _MockButton:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.clicked = lambda *a, **k: None
|
||||||
|
|
||||||
|
QWidget = _MockWidget
|
||||||
|
QGridLayout = _MockLayout
|
||||||
|
QLabel = _MockLabel
|
||||||
|
QLineEdit = _MockLineEdit
|
||||||
|
QGroupBox = _MockWidget
|
||||||
|
QVBoxLayout = _MockLayout
|
||||||
|
QPushButton = _MockButton
|
||||||
|
|
||||||
|
class _MockQCoreApplication:
|
||||||
|
pass
|
||||||
|
|
||||||
|
QCoreApplication = _MockQCoreApplication
|
||||||
|
class _MockQt:
|
||||||
|
# ToolButtonStyle
|
||||||
|
ToolButtonTextBesideIcon = 0
|
||||||
|
|
||||||
|
# ArrowType
|
||||||
|
ArrowDown = 1
|
||||||
|
ArrowRight = 2
|
||||||
|
|
||||||
|
Qt=_MockQt
|
||||||
|
ToolButtonTextBesideIcon = Qt.ToolButtonTextBesideIcon
|
||||||
|
ArrowDown = Qt.ArrowDown
|
||||||
|
ArrowRight = Qt.ArrowRight
|
||||||
|
|
||||||
|
class _MockQDockWidget(_MockWidget):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self._object_name = ""
|
||||||
|
|
||||||
|
def setObjectName(self, name: str) -> None:
|
||||||
|
self._object_name = name
|
||||||
|
|
||||||
|
def objectName(self) -> str:
|
||||||
|
return self._object_name
|
||||||
|
|
||||||
|
def show(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def deleteLater(self) -> None:
|
||||||
|
pass
|
||||||
|
QDockWidget = _MockQDockWidget
|
||||||
|
class _MockAction:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self._checked = False
|
||||||
|
self.triggered = lambda *a, **k: None
|
||||||
|
|
||||||
|
def setToolTip(self, text: str) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setCheckable(self, value: bool) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setChecked(self, value: bool) -> None:
|
||||||
|
self._checked = value
|
||||||
|
|
||||||
|
|
||||||
|
class _MockMenu:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self._actions = []
|
||||||
|
|
||||||
|
def addAction(self, action):
|
||||||
|
self._actions.append(action)
|
||||||
|
|
||||||
|
def removeAction(self, action):
|
||||||
|
if action in self._actions:
|
||||||
|
self._actions.remove(action)
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self._actions.clear()
|
||||||
|
|
||||||
|
def menuAction(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
class _MockToolBar:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self._actions = []
|
||||||
|
|
||||||
|
def setObjectName(self, name: str) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def addAction(self, action):
|
||||||
|
self._actions.append(action)
|
||||||
|
|
||||||
|
def removeAction(self, action):
|
||||||
|
if action in self._actions:
|
||||||
|
self._actions.remove(action)
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self._actions.clear()
|
||||||
|
|
||||||
|
|
||||||
|
class _MockActionGroup:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self._actions = []
|
||||||
|
|
||||||
|
def setExclusive(self, value: bool) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def addAction(self, action):
|
||||||
|
self._actions.append(action)
|
||||||
|
QAction = _MockAction
|
||||||
|
QMenu = _MockMenu
|
||||||
|
QToolBar = _MockToolBar
|
||||||
|
QActionGroup = _MockActionGroup
|
||||||
|
|
||||||
|
class _MockToolButton(_MockWidget):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self._checked = False
|
||||||
|
self.toggled = lambda *a, **k: None
|
||||||
|
|
||||||
|
def setText(self, text: str) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setCheckable(self, value: bool) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setChecked(self, value: bool) -> None:
|
||||||
|
self._checked = value
|
||||||
|
|
||||||
|
def setToolButtonStyle(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setArrowType(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setStyleSheet(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
QToolButton=_MockToolButton
|
||||||
|
|
||||||
|
class _MockQSizePolicy:
|
||||||
|
# horizontale Policies
|
||||||
|
Fixed = 0
|
||||||
|
Minimum = 1
|
||||||
|
Maximum = 2
|
||||||
|
Preferred = 3
|
||||||
|
Expanding = 4
|
||||||
|
MinimumExpanding = 5
|
||||||
|
Ignored = 6
|
||||||
|
|
||||||
|
# vertikale Policies (Qt nutzt dieselben Werte)
|
||||||
|
def __init__(self, horizontal=None, vertical=None):
|
||||||
|
self.horizontal = horizontal
|
||||||
|
self.vertical = vertical
|
||||||
|
QSizePolicy=_MockQSizePolicy
|
||||||
|
SizePolicyPreferred = QSizePolicy.Preferred
|
||||||
|
SizePolicyMaximum = QSizePolicy.Maximum
|
||||||
|
DockWidgetMovable = 1
|
||||||
|
DockWidgetFloatable = 2
|
||||||
|
DockWidgetClosable = 4
|
||||||
|
DockAreaLeft = 1
|
||||||
|
DockAreaRight = 2
|
||||||
|
|
||||||
def exec_dialog(dialog: Any) -> Any:
|
def exec_dialog(dialog: Any) -> Any:
|
||||||
return YES
|
return YES
|
||||||
# --------------------------- TEST ---------------------------
|
class _MockTabWidget:
|
||||||
if __name__ == "__main__":
|
def __init__(self, *args, **kwargs):
|
||||||
debug_qt_status()
|
self._tabs = []
|
||||||
|
|
||||||
|
def addTab(self, widget, title: str):
|
||||||
|
self._tabs.append((widget, title))
|
||||||
|
QTabWidget = _MockTabWidget
|
||||||
|
|
||||||
|
# -------------------------
|
||||||
|
# Mock ComboBox Implementation
|
||||||
|
# -------------------------
|
||||||
|
class _MockSignal:
|
||||||
|
def __init__(self):
|
||||||
|
self._slots = []
|
||||||
|
|
||||||
|
def connect(self, cb):
|
||||||
|
self._slots.append(cb)
|
||||||
|
|
||||||
|
def emit(self, value):
|
||||||
|
for s in list(self._slots):
|
||||||
|
try:
|
||||||
|
s(value)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
class _MockComboBox:
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
self._items = []
|
||||||
|
self._index = -1
|
||||||
|
self.currentTextChanged = _MockSignal()
|
||||||
|
|
||||||
|
def addItem(self, text: str) -> None:
|
||||||
|
self._items.append(text)
|
||||||
|
|
||||||
|
def addItems(self, items):
|
||||||
|
for it in items:
|
||||||
|
self.addItem(it)
|
||||||
|
|
||||||
|
def findText(self, text: str) -> int:
|
||||||
|
try:
|
||||||
|
return self._items.index(text)
|
||||||
|
except ValueError:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
def setCurrentIndex(self, idx: int) -> None:
|
||||||
|
if 0 <= idx < len(self._items):
|
||||||
|
self._index = idx
|
||||||
|
self.currentTextChanged.emit(self.currentText())
|
||||||
|
|
||||||
|
def setCurrentText(self, text: str) -> None:
|
||||||
|
idx = self.findText(text)
|
||||||
|
if idx >= 0:
|
||||||
|
self.setCurrentIndex(idx)
|
||||||
|
|
||||||
|
def currentText(self) -> str:
|
||||||
|
if 0 <= self._index < len(self._items):
|
||||||
|
return self._items[self._index]
|
||||||
|
return ""
|
||||||
|
|
||||||
|
ComboBox = _MockComboBox
|
||||||
|
|||||||
13
metadata.txt
Normal file
13
metadata.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[general]
|
||||||
|
name=LNO Sachsen | Basisfunktionen
|
||||||
|
qgisMinimumVersion=3.0
|
||||||
|
description=Plugin mit Basisfunktionen
|
||||||
|
version=25.11.4
|
||||||
|
author=Michael Otto
|
||||||
|
email=michael.otto@landkreis-mittelsachsen.de
|
||||||
|
about=Plugin mit Basisfunktionen
|
||||||
|
category=Plugins
|
||||||
|
homepage=https://entwicklung.vln-sn.de/AG_QGIS/Plugin_SN_Basis
|
||||||
|
repository=https://entwicklung.vln-sn.de/AG_QGIS/Repository
|
||||||
|
supportsQt6=true
|
||||||
|
experimental=true
|
||||||
@@ -1,27 +1,40 @@
|
|||||||
|
# sn_basis/modules/DataGrabber.py
|
||||||
"""
|
"""
|
||||||
DataGrabber module
|
DataGrabber module
|
||||||
==================
|
==================
|
||||||
|
|
||||||
UI‑freier Orchestrator für die Prüfung und Klassifikation von Datenquellen.
|
Leichter Orchestrator, der eine Quelle (Datei, Einzellink, Datenbank)
|
||||||
|
analysiert, passende Prüfer aufruft und die Ergebnisse an den
|
||||||
|
:class:`sn_basis.modules.Pruefmanager.Pruefmanager` delegiert.
|
||||||
|
|
||||||
Der DataGrabber:
|
Dieses vereinfachte Modul geht davon aus, dass alle benötigten Prüfer
|
||||||
- klassifiziert die übergebene Quelle (Datei, Dienst, Datenbank, Excel),
|
und der ExcelImporter vorhanden und importierbar sind. Es enthält
|
||||||
- ruft passende Prüfer (Dateipruefer, Linkpruefer, Layerpruefer, Stilpruefer) auf,
|
keine Fallbacks oder defensive Exception-Handling-Pfade für fehlende
|
||||||
- sammelt alle rohen ``pruef_ergebnis``‑Objekte,
|
Prüfer-Module — fehlende Komponenten führen zu Import- oder Laufzeitfehlern,
|
||||||
- aggregiert diese zu einem zusammenfassenden Ergebnis,
|
die bewusst nicht unterdrückt werden.
|
||||||
- **löst selbst keinerlei UI‑Interaktion aus**.
|
|
||||||
|
|
||||||
Alle Nutzerinteraktionen (MessageBar, QMessageBox, Logging) erfolgen
|
|
||||||
ausschließlich über den ``Pruefmanager`` im aufrufenden Kontext (UI / Pipeline).
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, Dict, List, Mapping, Optional, Tuple, Literal
|
from typing import (
|
||||||
|
Optional,
|
||||||
|
Any,
|
||||||
|
Mapping,
|
||||||
|
Iterable,
|
||||||
|
Dict,
|
||||||
|
Protocol,
|
||||||
|
Literal,
|
||||||
|
Tuple,
|
||||||
|
List,
|
||||||
|
)
|
||||||
|
from pathlib import Path
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis
|
|
||||||
from sn_basis.modules.Pruefmanager import Pruefmanager
|
from sn_basis.modules.Pruefmanager import Pruefmanager
|
||||||
|
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis, PruefAktion
|
||||||
|
|
||||||
|
# In dieser vereinfachten Variante werden die Prüfer und der ExcelImporter
|
||||||
|
# direkt importiert. Fehlende Module führen zu ImportError (gewollt).
|
||||||
from sn_basis.modules.Dateipruefer import Dateipruefer
|
from sn_basis.modules.Dateipruefer import Dateipruefer
|
||||||
from sn_basis.modules.linkpruefer import Linkpruefer
|
from sn_basis.modules.linkpruefer import Linkpruefer
|
||||||
from sn_basis.modules.layerpruefer import Layerpruefer
|
from sn_basis.modules.layerpruefer import Layerpruefer
|
||||||
@@ -29,144 +42,383 @@ from sn_basis.modules.stilpruefer import Stilpruefer
|
|||||||
from sn_basis.modules.excel_importer import ExcelImporter
|
from sn_basis.modules.excel_importer import ExcelImporter
|
||||||
|
|
||||||
|
|
||||||
SourceType = Literal["service", "database", "excel", "unknown"]
|
SourceType = Literal["file", "link", "database", "unknown"]
|
||||||
|
|
||||||
SourceDict = Dict[str, List[Mapping[str, Any]]]
|
|
||||||
|
class LinklistAdapter(Protocol):
|
||||||
|
"""
|
||||||
|
Minimal-Protokoll für Adapter, die Linklisten liefern/normalisieren.
|
||||||
|
|
||||||
|
Implementierende Klassen sollten:
|
||||||
|
- load() -> Iterable[Mapping[str, Any]]
|
||||||
|
- normalize(raw_item) -> Mapping[str, Any]
|
||||||
|
"""
|
||||||
|
def load(self) -> Iterable[Mapping[str, Any]]:
|
||||||
|
...
|
||||||
|
def normalize(self, raw_item: Mapping[str, Any]) -> Mapping[str, Any]:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
class DataGrabber:
|
class DataGrabber:
|
||||||
"""
|
"""
|
||||||
Analysiert und prüft Datenquellen für den Fachdatenabruf.
|
DataGrabber orchestriert das Einlesen einer Quelle und die Übergabe an Prüfer.
|
||||||
|
|
||||||
Der DataGrabber ist **UI‑frei**. Er erzeugt ausschließlich rohe
|
Diese vereinfachte Implementierung erwartet, dass alle Prüferklassen und
|
||||||
``pruef_ergebnis``‑Objekte und überlässt deren Verarbeitung
|
der ExcelImporter vorhanden sind. Es gibt keine defensive Logik für
|
||||||
vollständig dem aufrufenden Code.
|
fehlende Komponenten.
|
||||||
|
|
||||||
|
Konstruktor-Parameter
|
||||||
|
--------------------
|
||||||
|
:param pruefmanager: Instanz des Pruefmanagers (verpflichtend).
|
||||||
|
:param datei_pruefer_cls: Klasse des Dateipruefers (Standard: Dateipruefer).
|
||||||
|
:param link_pruefer: Instanz des Linkpruefers.
|
||||||
|
:param layer_pruefer: Instanz des Layerpruefers.
|
||||||
|
:param stil_pruefer: Instanz des Stilpruefers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
pruefmanager: Pruefmanager,
|
pruefmanager: Pruefmanager,
|
||||||
*,
|
*,
|
||||||
datei_pruefer_cls: type[Dateipruefer] = Dateipruefer,
|
datei_pruefer_cls=Dateipruefer,
|
||||||
link_pruefer: Optional[Linkpruefer] = None,
|
link_pruefer: Linkpruefer,
|
||||||
layer_pruefer: Optional[Layerpruefer] = None,
|
layer_pruefer: Layerpruefer,
|
||||||
stil_pruefer: Optional[Stilpruefer] = None,
|
stil_pruefer: Stilpruefer,
|
||||||
excel_importer_cls: type[ExcelImporter] = ExcelImporter,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.pruefmanager = pruefmanager
|
# Pruefmanager ist verpflichtend
|
||||||
|
self.pruefmanager: Pruefmanager = pruefmanager
|
||||||
|
|
||||||
|
# Dateipruefer-Klasse (wird zur Laufzeit mit einem Pfad instanziert)
|
||||||
self._datei_pruefer_cls = datei_pruefer_cls
|
self._datei_pruefer_cls = datei_pruefer_cls
|
||||||
self.link_pruefer = link_pruefer
|
|
||||||
self.layer_pruefer = layer_pruefer
|
|
||||||
self.stil_pruefer = stil_pruefer
|
|
||||||
self._excel_importer_cls = excel_importer_cls
|
|
||||||
|
|
||||||
self._source: Optional[str] = None
|
# Prüfer-Instanzen (werden direkt verwendet)
|
||||||
|
self.link_pruefer: Linkpruefer = link_pruefer
|
||||||
|
self.layer_pruefer: Layerpruefer = layer_pruefer
|
||||||
|
self.stil_pruefer: Stilpruefer = stil_pruefer
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# Quelle (wird später gesetzt)
|
||||||
# Öffentliche API
|
self.source: Optional[str] = None
|
||||||
# ------------------------------------------------------------------
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# Source Management
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
def set_source(self, source: str) -> None:
|
def set_source(self, source: str) -> None:
|
||||||
"""Setzt die aktuell zu untersuchende Rohquelle."""
|
|
||||||
self._source = source
|
|
||||||
|
|
||||||
def analyze_source_type(self, source: str) -> SourceType:
|
|
||||||
"""
|
"""
|
||||||
Klassifiziert die Quelle.
|
Setzt die Quelle für den DataGrabber.
|
||||||
|
|
||||||
Aktuell Platzhalter – liefert ``"unknown"``.
|
Die Quelle ist ein String, der entweder ein lokaler Dateipfad,
|
||||||
|
ein Einzellink (URL/URI) oder ein Pfad zu einer Datenbank/GeoPackage ist.
|
||||||
"""
|
"""
|
||||||
|
self.source = source
|
||||||
|
|
||||||
|
def analyze_source(self, source: str) -> SourceType:
|
||||||
|
"""
|
||||||
|
Klassifiziert die angegebene Quelle ausschließlich anhand des Dateipruefers.
|
||||||
|
|
||||||
|
Ablauf
|
||||||
|
------
|
||||||
|
1. Instanziere den Dateipruefer mit `pfad=source` und `temporaer_erlaubt=False`.
|
||||||
|
2. Rufe `pruefe()` auf und werte das zurückgegebene :class:`pruef_ergebnis` aus.
|
||||||
|
3. Bei `ok==True` wird anhand der Dateiendung zwischen "database" (gpkg/sqlite/db)
|
||||||
|
und "file" unterschieden.
|
||||||
|
4. Bei `ok==False` werden typische Aktionen wie "datei_nicht_gefunden" als "link"
|
||||||
|
interpretiert; bei "falsche_endung" wird anhand der Endung klassifiziert.
|
||||||
|
"""
|
||||||
|
dp = self._datei_pruefer_cls(pfad=source, temporaer_erlaubt=False)
|
||||||
|
pe: pruef_ergebnis = dp.pruefe()
|
||||||
|
|
||||||
|
if getattr(pe, "ok", False):
|
||||||
|
suffix = Path(source).suffix.lower()
|
||||||
|
if suffix in (".gpkg", ".sqlite", ".db"):
|
||||||
|
return "database"
|
||||||
|
return "file"
|
||||||
|
|
||||||
|
aktion = getattr(pe, "aktion", None)
|
||||||
|
if aktion in ("datei_nicht_gefunden", "pfad_nicht_gefunden", "kein_dateipfad"):
|
||||||
|
return "link"
|
||||||
|
if aktion == "falsche_endung":
|
||||||
|
lower = source.lower()
|
||||||
|
for db_ext in (".gpkg", ".sqlite", ".db"):
|
||||||
|
if lower.endswith(db_ext):
|
||||||
|
return "database"
|
||||||
|
for file_ext in (".xlsx", ".xls", ".csv"):
|
||||||
|
if lower.endswith(file_ext):
|
||||||
|
return "file"
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
def run(self, source: str) -> Tuple[SourceDict, pruef_ergebnis]:
|
# ------------------------------------------------------------------ #
|
||||||
"""
|
# Excel-Verarbeitung
|
||||||
Führt die vollständige Quellprüfung aus.
|
#Es werden alle Werte mit gültigem Link übernommen. Die restliche Struktur
|
||||||
|
#wird nicht überprüft, da alle Fachplugins unterschiedliche Strukturen haben können
|
||||||
Diese Methode ist **UI‑frei**. Sie gibt rohe Ergebnisse zurück,
|
# ------------------------------------------------------------------ #
|
||||||
die vom Aufrufer über den ``Pruefmanager`` verarbeitet werden.
|
def process_excel_source(
|
||||||
"""
|
|
||||||
self.set_source(source)
|
|
||||||
source_type = self.analyze_source_type(source)
|
|
||||||
|
|
||||||
source_dict: SourceDict = {}
|
|
||||||
partial_results: List[pruef_ergebnis] = []
|
|
||||||
|
|
||||||
if source_type == "excel":
|
|
||||||
source_dict, partial_results = self._process_excel_source(source)
|
|
||||||
elif source_type == "database":
|
|
||||||
source_dict, partial_results = self._process_database_source(source)
|
|
||||||
elif source_type == "service":
|
|
||||||
source_dict, partial_results = self._process_service_source(source)
|
|
||||||
else:
|
|
||||||
partial_results.append(
|
|
||||||
pruef_ergebnis(
|
|
||||||
ok=False,
|
|
||||||
meldung="Quelle konnte nicht klassifiziert werden",
|
|
||||||
aktion="kein_dateipfad",
|
|
||||||
kontext={"source": source},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
summary = self._aggregate_results(source, source_dict, partial_results)
|
|
||||||
return source_dict, summary
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Excel‑Quellen
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def _process_excel_source(
|
|
||||||
self, filepath: str
|
|
||||||
) -> Tuple[SourceDict, List[pruef_ergebnis]]:
|
|
||||||
source_dict: SourceDict = {}
|
|
||||||
results: List[pruef_ergebnis] = []
|
|
||||||
return source_dict, results
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Datenbank‑Quellen
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def _process_database_source(
|
|
||||||
self, db_path: str
|
|
||||||
) -> Tuple[SourceDict, List[pruef_ergebnis]]:
|
|
||||||
source_dict: SourceDict = {}
|
|
||||||
results: List[pruef_ergebnis] = []
|
|
||||||
return source_dict, results
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Dienst‑Quellen
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def _process_service_source(
|
|
||||||
self, link: str
|
|
||||||
) -> Tuple[SourceDict, List[pruef_ergebnis]]:
|
|
||||||
source_dict: SourceDict = {}
|
|
||||||
results: List[pruef_ergebnis] = []
|
|
||||||
return source_dict, results
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Aggregation
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def _aggregate_results(
|
|
||||||
self,
|
self,
|
||||||
source: str,
|
filepath: str
|
||||||
source_dict: SourceDict,
|
) -> Tuple[Optional[Dict[str, List[Mapping[str, Any]]]], Any]:
|
||||||
partial_results: List[pruef_ergebnis],
|
|
||||||
) -> pruef_ergebnis:
|
|
||||||
"""
|
"""
|
||||||
Aggregiert Einzelprüfungen zu einem Gesamt‑``pruef_ergebnis``.
|
Liest eine Excel-Datei ein und übernimmt ausschließlich die Zeilen,
|
||||||
|
deren Link durch den Linkpruefer als gültig eingestuft wurde.
|
||||||
|
|
||||||
**Keine UI‑Interaktion.**
|
Ablauf
|
||||||
|
------
|
||||||
|
1. Die Excel-Datei wird mit dem ``ExcelImporter`` eingelesen.
|
||||||
|
Erwartet wird eine Liste von Mappings (z.B. dicts), die jeweils
|
||||||
|
die Linkparameter enthalten.
|
||||||
|
|
||||||
|
2. Für jede Zeile wird der Wert ``row["Link"]`` extrahiert und durch
|
||||||
|
``self.link_pruefer.pruefe(...)`` geprüft.
|
||||||
|
|
||||||
|
3. Das Prüfergebnis wird durch ``self.pruefmanager.verarbeite(...)``
|
||||||
|
geleitet, der UI-Interaktion, Logging und finale Entscheidung übernimmt.
|
||||||
|
|
||||||
|
4. Nur Zeilen, deren verarbeitete Prüfergebnisse ``ok == True`` liefern,
|
||||||
|
werden in die Ergebnisliste übernommen.
|
||||||
|
|
||||||
|
5. Wenn mindestens eine Zeile gültig ist, wird ein Dict der Form::
|
||||||
|
|
||||||
|
{"rows": [row1, row2, ...]}
|
||||||
|
|
||||||
|
zurückgegeben.
|
||||||
|
Wenn keine Zeile gültig ist, wird ``None`` zurückgegeben.
|
||||||
|
|
||||||
|
Parameter
|
||||||
|
---------
|
||||||
|
filepath:
|
||||||
|
Pfad zur Excel-Datei, die eingelesen werden soll.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Tuple[Optional[Dict[str, List[Mapping[str, Any]]]], pruef_ergebnis]
|
||||||
|
- ``data``: ``{"rows": [...]} `` wenn gültige Zeilen existieren,
|
||||||
|
sonst ``None``.
|
||||||
|
- ``pruef_ergebnis``: ein zusammenfassendes Prüfergebnis, das
|
||||||
|
den Lesevorgang beschreibt (nicht die Einzelprüfungen).
|
||||||
|
|
||||||
|
Hinweise
|
||||||
|
--------
|
||||||
|
- Diese Methode führt **keine Normalisierung** durch.
|
||||||
|
- Die Verantwortung für die Struktur der Excel-Zeilen liegt beim Fachplugin.
|
||||||
|
- Der Linkpruefer prüft ausschließlich den Wert ``row["Link"]``.
|
||||||
"""
|
"""
|
||||||
if source_dict:
|
|
||||||
return pruef_ergebnis(
|
# 1) Excel einlesen
|
||||||
|
importer = ExcelImporter(filepath=filepath, pruefmanager=self.pruefmanager)
|
||||||
|
rows = importer.import_xlsx() # erwartet: List[Mapping[str, Any]]
|
||||||
|
|
||||||
|
valid_rows: List[Mapping[str, Any]] = []
|
||||||
|
|
||||||
|
# 2) Jede Zeile einzeln prüfen
|
||||||
|
for row in rows:
|
||||||
|
raw_link = row.get("Link")
|
||||||
|
|
||||||
|
# 2a) Fachliche Prüfung
|
||||||
|
pe = self.link_pruefer.pruefe(raw_link)
|
||||||
|
|
||||||
|
# 2b) Verarbeitung durch den Pruefmanager
|
||||||
|
processed = self.pruefmanager.verarbeite(pe)
|
||||||
|
|
||||||
|
# 2c) Nur gültige Zeilen übernehmen
|
||||||
|
if getattr(processed, "ok", False):
|
||||||
|
valid_rows.append(row)
|
||||||
|
|
||||||
|
# 3) Zusammenfassendes Prüfergebnis erzeugen
|
||||||
|
if valid_rows:
|
||||||
|
pe_ok = pruef_ergebnis(
|
||||||
ok=True,
|
ok=True,
|
||||||
meldung="Quelle erfolgreich geprüft",
|
meldung=f"{len(valid_rows)} gültige Zeilen aus Excel gelesen",
|
||||||
aktion="ok",
|
aktion="ok",
|
||||||
kontext={
|
kontext=filepath,
|
||||||
"source": source,
|
|
||||||
"valid_entries": sum(len(v) for v in source_dict.values()),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
processed_summary = self.pruefmanager.verarbeite(pe_ok)
|
||||||
|
return {"rows": valid_rows}, processed_summary
|
||||||
|
|
||||||
return pruef_ergebnis(
|
# Keine gültigen Zeilen
|
||||||
|
pe_fail = pruef_ergebnis(
|
||||||
ok=False,
|
ok=False,
|
||||||
meldung="Keine gültigen Einträge in der Quelle gefunden",
|
meldung="Keine gültigen Links in der Excel-Datei gefunden",
|
||||||
aktion="read_error",
|
aktion="read_error",
|
||||||
kontext={"source": source},
|
kontext=filepath,
|
||||||
)
|
)
|
||||||
|
processed_summary = self.pruefmanager.verarbeite(pe_fail)
|
||||||
|
return None, processed_summary
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# Einzellink-Verarbeitung
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
def process_single_link(
|
||||||
|
self,
|
||||||
|
link: Mapping[str, Any]
|
||||||
|
) -> Tuple[Optional[Dict[str, List[Mapping[str, Any]]]], Any]:
|
||||||
|
"""
|
||||||
|
Prüft einen einzelnen Link anhand der im Link-Dict enthaltenen Link-URL.
|
||||||
|
|
||||||
|
Ablauf
|
||||||
|
------
|
||||||
|
1. Erwartet wird ein Mapping (z.B. dict), das die Linkparameter enthält.
|
||||||
|
Mindestens der Schlüssel ``"Link"`` muss vorhanden sein.
|
||||||
|
|
||||||
|
2. Der eigentliche Link (z.B. URL) wird aus ``link["Link"]`` extrahiert
|
||||||
|
und an ``self.link_pruefer.pruefe(...)`` übergeben.
|
||||||
|
|
||||||
|
3. Das Prüfergebnis wird anschließend durch ``self.pruefmanager.verarbeite(...)``
|
||||||
|
geleitet, der UIInteraktion, Logging und finale Entscheidung übernimmt.
|
||||||
|
|
||||||
|
4. Wenn das verarbeitete Prüfergebnis **nicht OK** ist, wird
|
||||||
|
``(None, pruef_ergebnis)`` zurückgegeben.
|
||||||
|
|
||||||
|
5. Wenn das Prüfergebnis **OK** ist, wird das unveränderte LinkDict
|
||||||
|
in der Struktur ``{"rows": [link]}`` zurückgegeben.
|
||||||
|
|
||||||
|
Parameter
|
||||||
|
---------
|
||||||
|
link:
|
||||||
|
Ein Mapping mit den Linkparametern (z.B. id, Thema, Gruppe, Link,
|
||||||
|
Anbieter, Stildatei). Diese Methode verändert das Mapping nicht.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Tuple[Optional[Dict[str, List[Mapping[str, Any]]]], pruef_ergebnis]
|
||||||
|
- ``data``: ``{"rows": [link]}`` wenn gültig, sonst ``None``
|
||||||
|
- ``pruef_ergebnis``: das vom Pruefmanager verarbeitete Ergebnis
|
||||||
|
|
||||||
|
Hinweise
|
||||||
|
--------
|
||||||
|
- Diese Methode führt **keine Normalisierung** durch.
|
||||||
|
- Die Verantwortung für die Struktur des Link-Dicts liegt beim Fachplugin.
|
||||||
|
- Der Linkpruefer prüft ausschließlich den Wert ``link["Link"]``.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 1) Link extrahieren (Fachplugin garantiert, dass "Link" existiert)
|
||||||
|
raw_link = link.get("Link")
|
||||||
|
|
||||||
|
# 2) Fachliche Prüfung durch den Linkpruefer
|
||||||
|
pruef_ergebnis = self.link_pruefer.pruefe(raw_link)
|
||||||
|
|
||||||
|
# 3) Verarbeitung durch den Pruefmanager
|
||||||
|
processed = self.pruefmanager.verarbeite(pruef_ergebnis)
|
||||||
|
|
||||||
|
# 4) Wenn Prüfung nicht OK → keine Daten zurückgeben
|
||||||
|
if not getattr(processed, "ok", False):
|
||||||
|
return None, processed
|
||||||
|
|
||||||
|
# 5) Prüfung OK → unverändertes Link-Dict zurückgeben
|
||||||
|
data = {"rows": [link]}
|
||||||
|
|
||||||
|
return data, processed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# Datenbank-Verarbeitung
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
#def process_database_table(self, db_path: str, table: Optional[str] = None) -> Tuple[Optional[Dict[str, List[Mapping[str, Any]]]], pruef_ergebnis]:
|
||||||
|
#noch nicht implementiert
|
||||||
|
"""
|
||||||
|
Liest eine Tabelle aus einer SQLite/GeoPackage-Datei.
|
||||||
|
|
||||||
|
Verhalten
|
||||||
|
---------
|
||||||
|
1. Validiert die Datei mit dem Dateipruefer.
|
||||||
|
2. Falls OK, versucht es, die angegebene Tabelle zu lesen; falls keine Tabelle
|
||||||
|
angegeben ist, wird nach einer typischen Metadaten-Tabelle 'layer_metadaten'
|
||||||
|
gesucht und diese gelesen.
|
||||||
|
3. Gibt die Zeilen als Liste von Dicts zurück.
|
||||||
|
"""
|
||||||
|
dp = self._datei_pruefer_cls(pfad=db_path, temporaer_erlaubt=False)
|
||||||
|
pe = dp.pruefe()
|
||||||
|
processed = self.pruefmanager.verarbeite(pe)
|
||||||
|
if not getattr(processed, "ok", False):
|
||||||
|
return None, processed
|
||||||
|
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cur = conn.cursor()
|
||||||
|
if table:
|
||||||
|
cur.execute(f"SELECT * FROM {table}")
|
||||||
|
cols = [d[0] for d in cur.description]
|
||||||
|
rows = [dict(zip(cols, r)) for r in cur.fetchall()]
|
||||||
|
else:
|
||||||
|
cur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='layer_metadaten'")
|
||||||
|
if cur.fetchone():
|
||||||
|
cur.execute("SELECT * FROM layer_metadaten")
|
||||||
|
cols = [d[0] for d in cur.description]
|
||||||
|
rows = [dict(zip(cols, r)) for r in cur.fetchall()]
|
||||||
|
else:
|
||||||
|
rows = []
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
pe_ok = pruef_ergebnis(ok=True, meldung="DB gelesen", aktion="ok", kontext=db_path)
|
||||||
|
processed_ok = self.pruefmanager.verarbeite(pe_ok)
|
||||||
|
return {"rows": rows}, processed_ok
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# Hauptlauf / Dispatch
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
def run(self) -> Dict[str, Any]:
|
||||||
|
"""
|
||||||
|
Hauptmethode des DataGrabbers.
|
||||||
|
|
||||||
|
Ablauf
|
||||||
|
------
|
||||||
|
1. Prüft, ob eine Quelle gesetzt ist.
|
||||||
|
2. Klassifiziert die Quelle via :meth:`analyze_source`.
|
||||||
|
3. Dispatch:
|
||||||
|
- file (.xlsx/.xls) -> :meth:`process_excel_source`
|
||||||
|
- link -> :meth:`process_single_link`
|
||||||
|
- database -> :meth:`process_database_table`
|
||||||
|
- unknown -> Fehler
|
||||||
|
4. Aggregiert geladene Einträge in einem Ergebnis-Dict und gibt dieses zurück.
|
||||||
|
|
||||||
|
Rückgabeformat
|
||||||
|
-------------
|
||||||
|
Ein Dict mit den Schlüsseln:
|
||||||
|
- 'geladen' : Liste der geladenen Themen/Namen
|
||||||
|
- 'fehler' : Mapping Thema -> Fehlermeldung
|
||||||
|
- 'ausserhalb': Liste der als ausserhalb klassifizierten Themen
|
||||||
|
- 'relevant' : Liste der relevanten Themen
|
||||||
|
- 'details' : zusätzliche Detailinformationen (z. B. Anzahl Zeilen)
|
||||||
|
"""
|
||||||
|
result: Dict[str, Any] = {"geladen": [], "fehler": {}, "ausserhalb": [], "relevant": [], "details": {}}
|
||||||
|
|
||||||
|
if not self.source:
|
||||||
|
pe = pruef_ergebnis(ok=False, meldung="Keine Quelle gesetzt", aktion="kein_dateipfad", kontext=None)
|
||||||
|
processed = self.pruefmanager.verarbeite(pe)
|
||||||
|
result["fehler"]["source"] = getattr(processed, "meldung", "Keine Quelle")
|
||||||
|
return result
|
||||||
|
|
||||||
|
src_type = self.analyze_source(self.source)
|
||||||
|
|
||||||
|
if src_type == "file":
|
||||||
|
suffix = Path(self.source).suffix.lower()
|
||||||
|
if suffix in (".xlsx", ".xls"):
|
||||||
|
data_dict, pe = self.process_excel_source(self.source)
|
||||||
|
else:
|
||||||
|
pe = pruef_ergebnis(ok=False, meldung="Dateityp nicht unterstützt", aktion="falsche_endung", kontext=self.source)
|
||||||
|
pe = self.pruefmanager.verarbeite(pe)
|
||||||
|
data_dict = None
|
||||||
|
|
||||||
|
elif src_type == "link":
|
||||||
|
data_dict, pe = self.process_single_link(self.source)
|
||||||
|
|
||||||
|
#elif src_type == "database":
|
||||||
|
#data_dict, pe = self.process_database_table(self.source, table=None)
|
||||||
|
|
||||||
|
else:
|
||||||
|
pe = pruef_ergebnis(ok=False, meldung="Quelle unbekannt", aktion="kein_dateipfad", kontext=self.source)
|
||||||
|
pe = self.pruefmanager.verarbeite(pe)
|
||||||
|
data_dict = None
|
||||||
|
|
||||||
|
# Falls Daten vorhanden: fülle result['geladen'] und details
|
||||||
|
if data_dict and "rows" in data_dict:
|
||||||
|
rows = data_dict["rows"]
|
||||||
|
for r in rows:
|
||||||
|
thema = r.get("Inhalt") or r.get("ident") or r.get("Link") or "unbenannt"
|
||||||
|
result["geladen"].append(thema)
|
||||||
|
result["details"]["source_rows"] = len(rows)
|
||||||
|
|
||||||
|
# Falls das letzte pruef_ergebnis einen Fehler enthält, übernehme es
|
||||||
|
if not getattr(pe, "ok", False):
|
||||||
|
result["fehler"]["source"] = getattr(pe, "meldung", "Fehler bei Quelle")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|||||||
@@ -1,175 +1,98 @@
|
|||||||
"""
|
"""
|
||||||
sn_basis/modules/Dateipruefer.py
|
sn_basis/modules/Dateipruefer.py – Prüfung von Dateieingaben für das Plugin.
|
||||||
|
Verwendet sys_wrapper und gibt pruef_ergebnis an den Pruefmanager zurück.
|
||||||
Erweiterter Dateiprüfer für Verfahrens-DB-Workflows mit vollständiger Unterstützung
|
|
||||||
der Anforderungen 1-2.e (leerer Pfad, fehlende Datei, bestehende Datei).
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from sn_basis.functions.sys_wrapper import join_path, file_exists
|
from sn_basis.functions.sys_wrapper import (
|
||||||
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis, PruefAktion
|
join_path,
|
||||||
|
file_exists,
|
||||||
|
)
|
||||||
|
|
||||||
|
from sn_basis.modules.Pruefmanager import pruef_ergebnis
|
||||||
|
|
||||||
|
|
||||||
class Dateipruefer:
|
class Dateipruefer:
|
||||||
"""
|
"""
|
||||||
Prüft Dateieingaben für Verfahrens-DB-Workflows und liefert :class:`pruef_ergebnis`.
|
Prüft Dateieingaben und liefert ein pruef_ergebnis zurück.
|
||||||
|
Die eigentliche Nutzerinteraktion übernimmt der Pruefmanager.
|
||||||
**Funktionsweise (deine Anforderungen 1-2.e):**
|
|
||||||
|
|
||||||
+---------------------+------------------------------------------+---------------+
|
|
||||||
| **Fall** | **Ergebnis** | **ok** |
|
|
||||||
+=====================+==========================================+===============+
|
|
||||||
| 1. Leerer Pfad | ``temporaer_erlaubt`` | False |
|
|
||||||
+---------------------+------------------------------------------+---------------+
|
|
||||||
| 2.a Leerer Pfad | Pruefmanager fragt → ``temporaer_erzeugen`` | True |
|
|
||||||
+---------------------+------------------------------------------+---------------+
|
|
||||||
| 2.b Datei existiert | ``ok`` | True |
|
|
||||||
+---------------------+------------------------------------------+---------------+
|
|
||||||
| 2.c Ungültiger Pfad | ``datei_nicht_gefunden`` | False |
|
|
||||||
+---------------------+------------------------------------------+---------------+
|
|
||||||
| **2.d Datei fehlt** | **``datei_wird_erzeugt``** | **True** |
|
|
||||||
+---------------------+------------------------------------------+---------------+
|
|
||||||
| **2.e Datei da** | **``datei_existiert``** | **False** |
|
|
||||||
+---------------------+------------------------------------------+---------------+
|
|
||||||
|
|
||||||
Der Dateiprüfer führt **keine UI-Interaktion** durch.
|
|
||||||
Entscheidungen werden ausschließlich vom :class:`Pruefmanager` getroffen.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
pfad: Optional[str],
|
pfad: str,
|
||||||
basis_pfad: str = "",
|
basis_pfad: str = "",
|
||||||
leereingabe_erlaubt: bool = False,
|
leereingabe_erlaubt: bool = False,
|
||||||
standarddatei: Optional[str] = None,
|
standarddatei: str | None = None,
|
||||||
temporaer_erlaubt: bool = False,
|
temporaer_erlaubt: bool = False,
|
||||||
*,
|
):
|
||||||
verfahrens_db_modus: bool = True, # 🆕 Verfahrens-DB-spezifische Logik
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
pfad : Optional[str]
|
|
||||||
Vom UI gelieferter Dateipfad (kann leer oder Whitespace sein).
|
|
||||||
basis_pfad : str, optional
|
|
||||||
Basisverzeichnis für relative Pfade (default: "").
|
|
||||||
leereingabe_erlaubt : bool, optional
|
|
||||||
Ob leere Eingabe grundsätzlich erlaubt ist (default: False).
|
|
||||||
standarddatei : Optional[str], optional
|
|
||||||
Optionaler Standardpfad (default: None).
|
|
||||||
temporaer_erlaubt : bool, optional
|
|
||||||
Ob bei leerer Eingabe temporäre Layer erlaubt sind (default: False).
|
|
||||||
verfahrens_db_modus : bool, optional
|
|
||||||
Aktiviert Verfahrens-DB-spezifische Logik (2.d, 2.e) (default: True).
|
|
||||||
"""
|
|
||||||
self.pfad = pfad
|
self.pfad = pfad
|
||||||
self.basis_pfad = basis_pfad
|
self.basis_pfad = basis_pfad
|
||||||
self.leereingabe_erlaubt = leereingabe_erlaubt
|
self.leereingabe_erlaubt = leereingabe_erlaubt
|
||||||
self.standarddatei = standarddatei
|
self.standarddatei = standarddatei
|
||||||
self.temporaer_erlaubt = temporaer_erlaubt
|
self.temporaer_erlaubt = temporaer_erlaubt
|
||||||
self.verfahrens_db_modus = verfahrens_db_modus
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# Hilfsfunktionen
|
# Hilfsfunktion
|
||||||
# ------------------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
def _pfad(self, relativer_pfad: str) -> Path:
|
def _pfad(self, relativer_pfad: str) -> Path:
|
||||||
"""Erzeugt OS-unabhängigen Pfad relativ zum Basisverzeichnis."""
|
"""
|
||||||
|
Erzeugt einen OS-unabhängigen Pfad relativ zum Basisverzeichnis.
|
||||||
|
"""
|
||||||
return join_path(self.basis_pfad, relativer_pfad)
|
return join_path(self.basis_pfad, relativer_pfad)
|
||||||
|
|
||||||
def _ist_leer(self) -> bool:
|
# ---------------------------------------------------------
|
||||||
"""
|
# Hauptfunktion
|
||||||
Prüft robust, ob Eingabe als „leer" zu behandeln ist.
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
bool
|
|
||||||
True bei None, leerem String oder reinem Whitespace.
|
|
||||||
"""
|
|
||||||
if self.pfad is None:
|
|
||||||
return True
|
|
||||||
if not isinstance(self.pfad, str):
|
|
||||||
return True
|
|
||||||
return not self.pfad.strip()
|
|
||||||
|
|
||||||
def _ist_gueltiger_gpkg_pfad(self, pfad: Path) -> bool:
|
|
||||||
"""
|
|
||||||
Prüft, ob Pfad für GPKG geeignet ist (Endung + Schreibrechte).
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
bool
|
|
||||||
True wenn `.gpkg`-Endung und Verzeichnis beschreibbar.
|
|
||||||
"""
|
|
||||||
if not str(pfad).lower().endswith('.gpkg'):
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Verzeichnis muss beschreibbar sein
|
|
||||||
return pfad.parent.exists() and pfad.parent.is_dir()
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Hauptlogik: deine Anforderungen 1-2.e
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def pruefe(self) -> pruef_ergebnis:
|
def pruefe(self) -> pruef_ergebnis:
|
||||||
"""
|
"""
|
||||||
🆕 Prüft Dateieingabe gemäß Anforderungen 1-2.e.
|
Prüft eine Dateieingabe und liefert ein pruef_ergebnis zurück.
|
||||||
|
Der Pruefmanager entscheidet später, wie der Nutzer gefragt wird.
|
||||||
**Workflow:**
|
|
||||||
1. **Leere Eingabe** → ``temporaer_erlaubt`` (Pruefmanager fragt)
|
|
||||||
2. **Pfad prüfen**:
|
|
||||||
- **Ungültig** → 2.c ``datei_nicht_gefunden``
|
|
||||||
- **Gültig, fehlt** → **2.d** ``datei_wird_erzeugt`` (ok=True!)
|
|
||||||
- **Gültig, existiert** → **2.e** ``datei_existiert`` (Pruefmanager fragt)
|
|
||||||
3. **Datei OK** → 2.b ``ok``
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
pruef_ergebnis
|
|
||||||
Mit korrekter Aktion für jeden Fall.
|
|
||||||
"""
|
"""
|
||||||
# 1. 🎯 ANFORDERUNG 1: Leere Eingabe
|
|
||||||
if self._ist_leer():
|
# -----------------------------------------------------
|
||||||
|
# 1. Fall: Eingabe ist leer
|
||||||
|
# -----------------------------------------------------
|
||||||
|
if not self.pfad:
|
||||||
return self._handle_leere_eingabe()
|
return self._handle_leere_eingabe()
|
||||||
|
|
||||||
# 2. Pfad normalisieren
|
# -----------------------------------------------------
|
||||||
pfad = self._pfad(self.pfad.strip())
|
# 2. Fall: Eingabe ist nicht leer → Datei prüfen
|
||||||
|
# -----------------------------------------------------
|
||||||
|
pfad = self._pfad(self.pfad)
|
||||||
|
|
||||||
# 🆕 2.c: Ungültiger GPKG-Pfad?
|
if not file_exists(pfad):
|
||||||
if not self.verfahrens_db_modus or not self._ist_gueltiger_gpkg_pfad(pfad):
|
|
||||||
return pruef_ergebnis(
|
return pruef_ergebnis(
|
||||||
ok=False,
|
ok=False,
|
||||||
meldung=f"Der Pfad '{self.pfad}' ist kein gültiger GPKG-Pfad.",
|
meldung=f"Die Datei '{self.pfad}' wurde nicht gefunden.",
|
||||||
aktion="datei_nicht_gefunden",
|
aktion="datei_nicht_gefunden",
|
||||||
kontext=pfad,
|
kontext=pfad,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 🆕 2.d: Gültiger Pfad, Datei fehlt → DIREKT WEITER (ok=True!)
|
# -----------------------------------------------------
|
||||||
if not file_exists(pfad):
|
# 3. Datei existiert → Erfolg
|
||||||
|
# -----------------------------------------------------
|
||||||
return pruef_ergebnis(
|
return pruef_ergebnis(
|
||||||
ok=True, # 🎯 WICHTIG: Pipeline fortsetzen!
|
ok=True,
|
||||||
meldung=f"Datei '{self.pfad}' wird erzeugt.",
|
meldung="Datei gefunden.",
|
||||||
aktion="datei_wird_erzeugt",
|
aktion="ok",
|
||||||
kontext=pfad,
|
kontext=pfad,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 🆕 2.e: Datei existiert → Pruefmanager fragt Überschreiben/etc.
|
# ---------------------------------------------------------
|
||||||
return pruef_ergebnis(
|
# Behandlung leerer Eingaben
|
||||||
ok=False, # 🎯 Pruefmanager soll 4-Optionen-Dialog zeigen
|
# ---------------------------------------------------------
|
||||||
meldung=f"Datei '{self.pfad}' existiert bereits.",
|
|
||||||
aktion="datei_existiert",
|
|
||||||
kontext=pfad,
|
|
||||||
)
|
|
||||||
|
|
||||||
# 2.b: Wird nicht erreicht (durch 2.e abgefangen)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Leere Eingabe (ANFORDERUNG 1, 2.a)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def _handle_leere_eingabe(self) -> pruef_ergebnis:
|
def _handle_leere_eingabe(self) -> pruef_ergebnis:
|
||||||
"""
|
"""
|
||||||
Behandelt leere Eingaben (Priorität: leereingabe → Standard → temporär → Fehler).
|
Liefert ein pruef_ergebnis für den Fall, dass das Dateifeld leer ist.
|
||||||
|
Der Pruefmanager fragt später den Nutzer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# 1. Leereingabe erlaubt → Nutzer fragen, ob das beabsichtigt war
|
||||||
if self.leereingabe_erlaubt:
|
if self.leereingabe_erlaubt:
|
||||||
return pruef_ergebnis(
|
return pruef_ergebnis(
|
||||||
ok=False,
|
ok=False,
|
||||||
@@ -178,17 +101,19 @@ class Dateipruefer:
|
|||||||
kontext=None,
|
kontext=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 2. Standarddatei verfügbar → Nutzer fragen, ob sie verwendet werden soll
|
||||||
if self.standarddatei:
|
if self.standarddatei:
|
||||||
return pruef_ergebnis(
|
return pruef_ergebnis(
|
||||||
ok=False,
|
ok=False,
|
||||||
meldung=(
|
meldung=(
|
||||||
"Es wurde keine Datei angegeben. "
|
f"Es wurde keine Datei angegeben. "
|
||||||
f"Soll die Standarddatei '{self.standarddatei}' verwendet werden?"
|
f"Soll die Standarddatei '{self.standarddatei}' verwendet werden?"
|
||||||
),
|
),
|
||||||
aktion="standarddatei_vorschlagen",
|
aktion="standarddatei_vorschlagen",
|
||||||
kontext=self._pfad(self.standarddatei),
|
kontext=self._pfad(self.standarddatei),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 3. Temporäre Datei erlaubt → Nutzer fragen, ob temporär gearbeitet werden soll
|
||||||
if self.temporaer_erlaubt:
|
if self.temporaer_erlaubt:
|
||||||
return pruef_ergebnis(
|
return pruef_ergebnis(
|
||||||
ok=False,
|
ok=False,
|
||||||
@@ -200,6 +125,7 @@ class Dateipruefer:
|
|||||||
kontext=None,
|
kontext=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 4. Leereingabe nicht erlaubt → Fehler
|
||||||
return pruef_ergebnis(
|
return pruef_ergebnis(
|
||||||
ok=False,
|
ok=False,
|
||||||
meldung="Es wurde keine Datei angegeben.",
|
meldung="Es wurde keine Datei angegeben.",
|
||||||
|
|||||||
@@ -1,45 +1,66 @@
|
|||||||
"""
|
|
||||||
sn_basis/modules/Pruefmanager.py
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import Optional, Any
|
from typing import Optional, Any
|
||||||
|
|
||||||
from sn_basis.functions import ask_yes_no, info, warning, error, ask_overwrite_append_cancel_custom
|
from sn_basis.functions import (
|
||||||
|
ask_yes_no,
|
||||||
|
info,
|
||||||
|
warning,
|
||||||
|
error,
|
||||||
|
set_layer_visible,
|
||||||
|
)
|
||||||
|
|
||||||
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis, PruefAktion
|
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis, PruefAktion
|
||||||
print("DEBUG: Pruefmanager DATEI GELADEN:", __file__)
|
|
||||||
|
|
||||||
class Pruefmanager:
|
class Pruefmanager:
|
||||||
def __init__(self, ui_modus: str = "qgis", parent: Optional[Any] = None) -> None:
|
"""
|
||||||
|
Zentrale Verarbeitung von pruef_ergebnis-Objekten.
|
||||||
|
|
||||||
|
Erwartete öffentliche API (verwendet von Core-Komponenten wie DataGrabber):
|
||||||
|
- report_error(thema, meldung, *, aktion: Optional[PruefAktion]=None, kontext=None) -> None
|
||||||
|
- request_decision(pruef_res) -> str
|
||||||
|
- report_summary(summary: dict) -> None
|
||||||
|
- verarbeite(ergebnis: pruef_ergebnis) -> pruef_ergebnis
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, ui_modus: str = "qgis", parent: Optional[Any] = None):
|
||||||
self.ui_modus = ui_modus
|
self.ui_modus = ui_modus
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
# Meldungen / Zusammenfassungen
|
# Basis-API: Meldungen / Zusammenfassungen
|
||||||
# ------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
def report_error(
|
def report_error(self, thema: str, meldung: str, *, aktion: Optional[PruefAktion] = None, kontext: Optional[Any] = None) -> None:
|
||||||
self,
|
"""
|
||||||
thema: str,
|
Einheitliche Meldung für Fehler/Warnungen aus dem Core.
|
||||||
meldung: str,
|
Keine Rückgabe; dient als zentraler Hook für Logging/UI.
|
||||||
*,
|
"""
|
||||||
aktion: Optional[PruefAktion] = None,
|
|
||||||
kontext: Optional[Any] = None,
|
|
||||||
) -> None:
|
|
||||||
critical_actions = {
|
critical_actions = {
|
||||||
"netzwerkfehler", "pruefe_exception", "save_exception",
|
"netzwerkfehler",
|
||||||
"layer_create_failed", "read_error", "open_error",
|
"pruefe_exception",
|
||||||
|
"save_exception",
|
||||||
|
"layer_create_failed",
|
||||||
|
"read_error",
|
||||||
|
"open_error",
|
||||||
}
|
}
|
||||||
warn_actions = {
|
warn_actions = {
|
||||||
"datei_nicht_gefunden", "pfad_nicht_gefunden", "url_nicht_erreichbar",
|
"datei_nicht_gefunden",
|
||||||
"falsche_endung", "kein_header", "kein_arbeitsblatt",
|
"pfad_nicht_gefunden",
|
||||||
|
"url_nicht_erreichbar",
|
||||||
|
"falsche_endung",
|
||||||
|
"kein_header",
|
||||||
|
"kein_arbeitsblatt",
|
||||||
}
|
}
|
||||||
|
|
||||||
if aktion in critical_actions:
|
if aktion in critical_actions:
|
||||||
error(thema, meldung)
|
error(thema, meldung)
|
||||||
return
|
return
|
||||||
|
|
||||||
if aktion in warn_actions:
|
if aktion in warn_actions:
|
||||||
warning(thema, meldung)
|
warning(thema, meldung)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Default: informative Warnung
|
||||||
warning(thema, meldung)
|
warning(thema, meldung)
|
||||||
|
|
||||||
def report_summary(self, summary: dict) -> None:
|
def report_summary(self, summary: dict) -> None:
|
||||||
@@ -54,165 +75,202 @@ class Pruefmanager:
|
|||||||
f"Dienste ausserhalb: {len(ausserhalb)}\n"
|
f"Dienste ausserhalb: {len(ausserhalb)}\n"
|
||||||
f"Fehler: {len(fehler)}"
|
f"Fehler: {len(fehler)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
info("DataGrabber Zusammenfassung", message)
|
info("DataGrabber Zusammenfassung", message)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
# VERFAHRENS-DB-spezifische Entscheidungen
|
# Entscheidungs-API
|
||||||
# ------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
def _handle_datei_existiert(self, ergebnis: pruef_ergebnis) -> pruef_ergebnis:
|
def request_decision(self, pruef_res: Any) -> str:
|
||||||
"""Handhabt das Szenario, dass die Ziel-Verfahrens-DB bereits existiert.
|
|
||||||
|
|
||||||
Zeigt einen einzigen Dialog mit drei Optionen an:
|
|
||||||
- **Überschreiben**: Bestehende Layer ersetzen (entspricht YES)
|
|
||||||
- **Anhängen**: Neue Layer zur Datei hinzufügen (entspricht NO)
|
|
||||||
- **Abbrechen**: Vorgang beenden (entspricht CANCEL)
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
ergebnis : pruef_ergebnis
|
|
||||||
Eingabe-Ergebnis mit Dateipfad im ``kontext``-Attribut.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
pruef_ergebnis
|
|
||||||
Ergebnis mit Aktion:
|
|
||||||
- ``datei_existiert_ueberschreiben``
|
|
||||||
- ``datei_existiert_anhaengen``
|
|
||||||
- ``datei_existiert_ueberspringen`` (für Cancel-Fall)
|
|
||||||
"""
|
"""
|
||||||
if self.ui_modus != "qgis":
|
Synchronously request a decision from the user (or return a default in headless mode).
|
||||||
return ergebnis
|
|
||||||
|
|
||||||
pfad = ergebnis.kontext
|
Returns one of:
|
||||||
pfad_str = str(pfad) if pfad else "unbekannt"
|
- "abort"
|
||||||
|
- "continue"
|
||||||
|
- "temporaer_erzeugen"
|
||||||
|
- "ignore"
|
||||||
|
"""
|
||||||
|
aktion = getattr(pruef_res, "aktion", None)
|
||||||
|
meldung = getattr(pruef_res, "meldung", str(pruef_res))
|
||||||
|
|
||||||
titel = "Verfahrens-DB existiert bereits"
|
|
||||||
meldung = (
|
|
||||||
f"Die Datei '{pfad_str}' existiert bereits.\n\n"
|
|
||||||
"Was soll geschehen?\n\n"
|
|
||||||
"• **Überschreiben**: Bestehende Layer ersetzen\n"
|
|
||||||
"• **Anhängen**: Neue Layer hinzufügen\n"
|
|
||||||
"• **Abbrechen**: Vorgang beenden"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Einzelner Dialog mit drei Optionen
|
|
||||||
entscheidung = ask_overwrite_append_cancel_custom(
|
|
||||||
parent=self.parent,
|
|
||||||
title=titel,
|
|
||||||
message=meldung
|
|
||||||
)
|
|
||||||
|
|
||||||
if entscheidung == "overwrite":
|
|
||||||
return pruef_ergebnis(
|
|
||||||
ok=True,
|
|
||||||
aktion="datei_existiert_ueberschreiben",
|
|
||||||
kontext=ergebnis.kontext,
|
|
||||||
)
|
|
||||||
elif entscheidung == "append":
|
|
||||||
return pruef_ergebnis(
|
|
||||||
ok=True,
|
|
||||||
aktion="datei_existiert_anhaengen",
|
|
||||||
kontext=ergebnis.kontext,
|
|
||||||
)
|
|
||||||
else: # cancel
|
|
||||||
return pruef_ergebnis(
|
|
||||||
ok=True,
|
|
||||||
aktion="datei_existiert_ueberspringen",
|
|
||||||
kontext=ergebnis.kontext,
|
|
||||||
)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Basis-Entscheidungen (KORREKT: → pruef_ergebnis)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def _handle_basic_decision(self, ergebnis: pruef_ergebnis) -> pruef_ergebnis:
|
|
||||||
"""Basis-Entscheidung für einfache Ja/Nein-Fragen."""
|
|
||||||
print(f"DEBUG _handle_basic_decision: aktion='{ergebnis.aktion}', ui_modus='{self.ui_modus}'")
|
|
||||||
|
|
||||||
if self.ui_modus != "qgis":
|
|
||||||
print("DEBUG: Nicht QGIS → ergebnis unverändert")
|
|
||||||
return ergebnis
|
|
||||||
|
|
||||||
title_map = {
|
|
||||||
"leereingabe_erlaubt": "Ohne Eingabe fortfahren",
|
|
||||||
"standarddatei_vorschlagen": "Standarddatei verwenden",
|
|
||||||
"temporaer_erlaubt": "Temporäre Layer erzeugen",
|
|
||||||
"layer_unsichtbar": "Layer einblenden",
|
|
||||||
}
|
|
||||||
|
|
||||||
title = title_map.get(ergebnis.aktion, "Entscheidung erforderlich")
|
|
||||||
meldung = ergebnis.meldung or ""
|
|
||||||
|
|
||||||
try:
|
|
||||||
print(f"DEBUG ask_yes_no: title='{title}', meldung='{meldung[:50]}...'")
|
|
||||||
yes = ask_yes_no(title, meldung, default=False, parent=self.parent)
|
|
||||||
print(f"DEBUG ask_yes_no: yes={yes}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"DEBUG ask_yes_no Exception: {e}")
|
|
||||||
return ergebnis
|
|
||||||
|
|
||||||
if not yes:
|
|
||||||
print("DEBUG: Nutzer sagte Nein → ok=False")
|
|
||||||
return ergebnis
|
|
||||||
|
|
||||||
# Nutzer sagte Ja
|
|
||||||
if ergebnis.aktion == "temporaer_erlaubt":
|
|
||||||
print("DEBUG: temporaer_erlaubt bestätigt → ok=True")
|
|
||||||
return pruef_ergebnis(
|
|
||||||
ok=True,
|
|
||||||
aktion="temporaer_erlaubt",
|
|
||||||
kontext=ergebnis.kontext
|
|
||||||
)
|
|
||||||
|
|
||||||
print("DEBUG: Andere Aktion bestätigt → ok=True, aktion='ok'")
|
|
||||||
return pruef_ergebnis(
|
|
||||||
ok=True,
|
|
||||||
aktion="ok",
|
|
||||||
kontext=ergebnis.kontext
|
|
||||||
)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
# Hauptlogik: verarbeite() (KORRIGIERT!)
|
|
||||||
# ------------------------------------------------------------------
|
|
||||||
def verarbeite(self, ergebnis: pruef_ergebnis) -> pruef_ergebnis:
|
|
||||||
print("🔥 verarbeite() START")
|
|
||||||
print("DEBUG Pruefmanager:", ergebnis.ok, ergebnis.aktion)
|
|
||||||
print("DEBUG ergebnis.aktion TYPE:", type(ergebnis.aktion), repr(ergebnis.aktion))
|
|
||||||
|
|
||||||
# 1. Erfolg → direkt weiter
|
|
||||||
print("🔍 Schritt 1: Prüfe ergebnis.ok =", ergebnis.ok)
|
|
||||||
if ergebnis.ok:
|
|
||||||
print("✅ Schritt 1: ok=True → return")
|
|
||||||
return ergebnis
|
|
||||||
|
|
||||||
# 2. VERFAHRENS-DB: Bestehende Datei
|
|
||||||
print("🔍 Schritt 2: Prüfe datei_existiert =", ergebnis.aktion == "datei_existiert")
|
|
||||||
if ergebnis.aktion == "datei_existiert":
|
|
||||||
print("✅ Schritt 2: _handle_datei_existiert")
|
|
||||||
return self._handle_datei_existiert(ergebnis)
|
|
||||||
|
|
||||||
# 3. Basis interaktive Aktionen
|
|
||||||
print("🔍 Schritt 3: Definiere interactive_actions")
|
|
||||||
interactive_actions = {
|
interactive_actions = {
|
||||||
"leereingabe_erlaubt",
|
"leereingabe_erlaubt",
|
||||||
"standarddatei_vorschlagen",
|
"standarddatei_vorschlagen",
|
||||||
"temporaer_erlaubt",
|
"temporaer_erlaubt",
|
||||||
"layer_unsichtbar",
|
"layer_unsichtbar",
|
||||||
}
|
}
|
||||||
print("DEBUG interactive_actions:", repr(interactive_actions))
|
|
||||||
print("DEBUG ergebnis.aktion in interactive_actions?", ergebnis.aktion in interactive_actions)
|
|
||||||
|
|
||||||
if ergebnis.aktion in interactive_actions:
|
if aktion in interactive_actions:
|
||||||
print("✅ Schritt 3: Interaktive Aktion → _handle_basic_decision")
|
if self.ui_modus == "qgis":
|
||||||
decision = self._handle_basic_decision(ergebnis)
|
title_map = {
|
||||||
print(f"DEBUG: _handle_basic_decision Ergebnis: ok={decision.ok}, aktion='{decision.aktion}'")
|
"leereingabe_erlaubt": "Ohne Eingabe fortfahren",
|
||||||
return decision
|
"standarddatei_vorschlagen": "Standarddatei verwenden",
|
||||||
|
"temporaer_erlaubt": "Temporäre Datei erzeugen",
|
||||||
|
"layer_unsichtbar": "Layer einblenden",
|
||||||
|
}
|
||||||
|
title = title_map.get(aktion, "Entscheidung erforderlich")
|
||||||
|
try:
|
||||||
|
yes = ask_yes_no(title, meldung, default=False, parent=self.parent)
|
||||||
|
except Exception:
|
||||||
|
return "abort"
|
||||||
|
if yes:
|
||||||
|
if aktion == "temporaer_erlaubt":
|
||||||
|
return "temporaer_erzeugen"
|
||||||
|
return "continue"
|
||||||
|
return "abort"
|
||||||
|
|
||||||
# 4. Fehler behandeln
|
if self.ui_modus == "headless":
|
||||||
print("❌ Schritt 4: FEHLER BEHANDELN")
|
return "abort"
|
||||||
self.report_error(
|
|
||||||
thema=ergebnis.aktion or "pruefung",
|
informational_actions = {
|
||||||
meldung=ergebnis.meldung or "",
|
"leer",
|
||||||
aktion=ergebnis.aktion,
|
"datei_nicht_gefunden",
|
||||||
kontext=ergebnis.kontext,
|
"pfad_nicht_gefunden",
|
||||||
)
|
"url_nicht_erreichbar",
|
||||||
print("🔥 verarbeite() ENDE mit ok=False")
|
"netzwerkfehler",
|
||||||
|
"falscher_geotyp",
|
||||||
|
"layer_leer",
|
||||||
|
"falscher_layertyp",
|
||||||
|
"falsches_crs",
|
||||||
|
"felder_fehlen",
|
||||||
|
"datenquelle_unerwartet",
|
||||||
|
"layer_nicht_editierbar",
|
||||||
|
"kein_header",
|
||||||
|
"kein_arbeitsblatt",
|
||||||
|
"read_error",
|
||||||
|
"open_error",
|
||||||
|
"pflichtfelder_fehlen",
|
||||||
|
}
|
||||||
|
if aktion in informational_actions:
|
||||||
|
return "abort"
|
||||||
|
|
||||||
|
return "abort"
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
# Höhere Abstraktion: verarbeite
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
def verarbeite(self, ergebnis: pruef_ergebnis) -> pruef_ergebnis:
|
||||||
|
"""
|
||||||
|
Verarbeitet ein pruef_ergebnis-Objekt und führt ggf. Nutzerinteraktion durch.
|
||||||
|
Liefert ein ggf. modifiziertes pruef_ergebnis zurück.
|
||||||
|
"""
|
||||||
|
if ergebnis.ok:
|
||||||
return ergebnis
|
return ergebnis
|
||||||
|
|
||||||
|
aktion = ergebnis.aktion
|
||||||
|
kontext = ergebnis.kontext
|
||||||
|
meldung = ergebnis.meldung
|
||||||
|
|
||||||
|
# Zentrale Meldung
|
||||||
|
self.report_error(aktion or "pruefung", meldung or "", aktion=aktion, kontext=kontext)
|
||||||
|
|
||||||
|
# Interaktive Entscheidungen
|
||||||
|
if aktion in ("leereingabe_erlaubt", "standarddatei_vorschlagen", "temporaer_erlaubt", "layer_unsichtbar"):
|
||||||
|
decision = self.request_decision(ergebnis)
|
||||||
|
if decision == "temporaer_erzeugen":
|
||||||
|
return pruef_ergebnis(ok=True, meldung="Temporäre Datei soll erzeugt werden.", aktion="temporaer_erzeugen", kontext=None)
|
||||||
|
if decision == "continue":
|
||||||
|
return pruef_ergebnis(ok=True, meldung="Fortgefahren.", aktion="ok", kontext=kontext)
|
||||||
|
return ergebnis # abort / unverändert
|
||||||
|
|
||||||
|
# Spezielle Excel/Importer-Fälle: klare Meldungen, keine interaktive Entscheidung
|
||||||
|
if aktion == "kein_header":
|
||||||
|
warning("Excel-Import", meldung or "")
|
||||||
|
return ergebnis
|
||||||
|
|
||||||
|
if aktion == "kein_arbeitsblatt":
|
||||||
|
warning("Excel-Import", meldung or "")
|
||||||
|
return ergebnis
|
||||||
|
|
||||||
|
if aktion in ("read_error", "open_error"):
|
||||||
|
error("Excel-Import", meldung or "")
|
||||||
|
return ergebnis
|
||||||
|
|
||||||
|
if aktion == "datei_nicht_gefunden":
|
||||||
|
warning("Datei nicht gefunden", meldung or "")
|
||||||
|
return ergebnis
|
||||||
|
|
||||||
|
# Spezieller Fall: layer_unsichtbar (falls nicht interaktiv behandelt)
|
||||||
|
if aktion == "layer_unsichtbar":
|
||||||
|
if kontext is not None:
|
||||||
|
try:
|
||||||
|
set_layer_visible(kontext, True)
|
||||||
|
return pruef_ergebnis(ok=True, meldung="Layer wurde eingeblendet.", aktion="ok", kontext=kontext)
|
||||||
|
except Exception:
|
||||||
|
return ergebnis
|
||||||
|
return ergebnis
|
||||||
|
|
||||||
|
# Standard: keine Änderung
|
||||||
|
return ergebnis
|
||||||
|
def ask_overwrite_append_cancel(self, layer_name: str, default: str = "overwrite") -> str:
|
||||||
|
"""
|
||||||
|
Zeigt dem Nutzer eine Auswahl für einen bereits existierenden Layer an.
|
||||||
|
|
||||||
|
Rückgabe
|
||||||
|
-------
|
||||||
|
str
|
||||||
|
Einer der Werte: "overwrite", "append", "cancel".
|
||||||
|
|
||||||
|
Verhalten
|
||||||
|
--------
|
||||||
|
- Verwendet bevorzugt die UI-Wrapper-Funktion `qt_wrapper` / `qgisui_wrapper`,
|
||||||
|
falls vorhanden (z. B. ein QMessageBox-Dialog mit drei Buttons).
|
||||||
|
- Im Mock- oder Headless-Modus (kein Qt/QGIS verfügbar) wird der übergebene
|
||||||
|
`default`-Wert zurückgegeben.
|
||||||
|
- Alle Nutzerinteraktionen laufen über diese zentrale Methode, damit das
|
||||||
|
Plugin an einer Stelle gesteuert und ggf. getested werden kann.
|
||||||
|
|
||||||
|
Parameter
|
||||||
|
---------
|
||||||
|
layer_name:
|
||||||
|
Anzeigename des Layers, der bereits existiert (wird im Dialog angezeigt).
|
||||||
|
default:
|
||||||
|
Rückgabewert im Headless/Mock-Modus oder wenn der Dialog nicht verfügbar ist.
|
||||||
|
Gültige Werte: "overwrite", "append", "cancel". Standard: "overwrite".
|
||||||
|
"""
|
||||||
|
# Validierung des Defaults
|
||||||
|
if default not in ("overwrite", "append", "cancel"):
|
||||||
|
default = "overwrite"
|
||||||
|
|
||||||
|
# Versuche, eine UI-Wrapper-Funktion zu verwenden, falls vorhanden
|
||||||
|
try:
|
||||||
|
# qgisui_wrapper kann eine spezialisierte Dialogfunktion bereitstellen
|
||||||
|
from sn_basis.functions import qgisui_wrapper as qgisui
|
||||||
|
ask_fn = getattr(qgisui, "ask_overwrite_append_cancel", None)
|
||||||
|
if callable(ask_fn):
|
||||||
|
# Die Wrapper-Funktion soll genau die drei Strings zurückgeben
|
||||||
|
choice = ask_fn(layer_name)
|
||||||
|
if choice in ("overwrite", "append", "cancel"):
|
||||||
|
return choice
|
||||||
|
except Exception:
|
||||||
|
# Falls Import/Wrapper fehlschlägt, weiter zum Qt-Fallback
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Fallback: direkte Qt-Dialoge über qt_wrapper (wenn verfügbar)
|
||||||
|
try:
|
||||||
|
from sn_basis.functions import qt_wrapper as qt
|
||||||
|
QMessageBox = getattr(qt, "QMessageBox", None)
|
||||||
|
if QMessageBox is not None:
|
||||||
|
# Erzeuge und konfiguriere Dialog
|
||||||
|
msg = QMessageBox()
|
||||||
|
msg.setWindowTitle("Layer bereits vorhanden")
|
||||||
|
msg.setText(f"Der Layer '{layer_name}' existiert bereits. Was möchten Sie tun?")
|
||||||
|
overwrite_btn = msg.addButton("Überschreiben", QMessageBox.AcceptRole)
|
||||||
|
append_btn = msg.addButton("Anhängen", QMessageBox.AcceptRole)
|
||||||
|
cancel_btn = msg.addButton("Abbrechen", QMessageBox.RejectRole)
|
||||||
|
msg.setDefaultButton(overwrite_btn)
|
||||||
|
# Blockierend anzeigen
|
||||||
|
msg.exec_()
|
||||||
|
clicked = msg.clickedButton()
|
||||||
|
if clicked == overwrite_btn:
|
||||||
|
return "overwrite"
|
||||||
|
if clicked == append_btn:
|
||||||
|
return "append"
|
||||||
|
return "cancel"
|
||||||
|
except Exception:
|
||||||
|
# Qt nicht verfügbar oder Fehler beim Dialogaufbau
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Headless / Mock: gib Default zurück
|
||||||
|
return default
|
||||||
|
|||||||
@@ -1,21 +1,9 @@
|
|||||||
"""
|
|
||||||
sn_basis/modules/pruef_ergebnis.py
|
|
||||||
|
|
||||||
Erweitertes Ergebnisobjekt für Dateiprüfungen mit Verfahrens-DB-spezifischen Aktionen.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Optional, Literal
|
from typing import Any, Optional, Literal
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
|
||||||
# Erweiterte PruefAktionen für Verfahrens-DB-Workflow
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
|
# Erweitertes Literal mit allen erlaubten Aktionen (PruefAktion)
|
||||||
PruefAktion = Literal[
|
PruefAktion = Literal[
|
||||||
# Basis-Aktionen (bestehend)
|
|
||||||
"ok",
|
"ok",
|
||||||
"leer",
|
"leer",
|
||||||
"leereingabe_erlaubt",
|
"leereingabe_erlaubt",
|
||||||
@@ -28,8 +16,6 @@ PruefAktion = Literal[
|
|||||||
"pfad_nicht_gefunden",
|
"pfad_nicht_gefunden",
|
||||||
"url_nicht_erreichbar",
|
"url_nicht_erreichbar",
|
||||||
"netzwerkfehler",
|
"netzwerkfehler",
|
||||||
|
|
||||||
# Layer-spezifisch
|
|
||||||
"layer_nicht_gefunden",
|
"layer_nicht_gefunden",
|
||||||
"layer_unsichtbar",
|
"layer_unsichtbar",
|
||||||
"falscher_geotyp",
|
"falscher_geotyp",
|
||||||
@@ -39,26 +25,15 @@ PruefAktion = Literal[
|
|||||||
"felder_fehlen",
|
"felder_fehlen",
|
||||||
"datenquelle_unerwartet",
|
"datenquelle_unerwartet",
|
||||||
"layer_nicht_editierbar",
|
"layer_nicht_editierbar",
|
||||||
|
|
||||||
# Dateiendung/Format
|
|
||||||
"falsche_endung",
|
"falsche_endung",
|
||||||
"pflichtfelder_fehlen",
|
"pflichtfelder_fehlen",
|
||||||
|
# Excel / Import-spezifische Aktionen
|
||||||
# Excel/Import
|
|
||||||
"kein_header",
|
"kein_header",
|
||||||
"kein_arbeitsblatt",
|
"kein_arbeitsblatt",
|
||||||
"read_error",
|
"read_error",
|
||||||
"open_error",
|
"open_error",
|
||||||
"datenabruf",
|
"datenabruf",
|
||||||
|
# Generische Prüf-/Speicher-Aktionen
|
||||||
# 🆕 VERFAHRENS-DB SPEZIFISCH (deine Anforderungen 2.d, 2.e)
|
|
||||||
"datei_wird_erzeugt", # 2.d: Pfad gültig, Datei fehlt → weiter
|
|
||||||
"datei_existiert", # Datei vorhanden → Layer-Entscheidung
|
|
||||||
"datei_existiert_ueberschreiben", # 2.e: Nutzer wählt "Überschreiben"
|
|
||||||
"datei_existiert_anhaengen", # 2.e: Nutzer wählt "Anhängen"
|
|
||||||
"datei_existiert_ueberspringen", # 2.e: Nutzer wählt "Überspringen"
|
|
||||||
|
|
||||||
# Generisch
|
|
||||||
"pruefe_exception",
|
"pruefe_exception",
|
||||||
"save_exception",
|
"save_exception",
|
||||||
"save_not_implemented",
|
"save_not_implemented",
|
||||||
@@ -67,113 +42,22 @@ PruefAktion = Literal[
|
|||||||
"needs_user_action",
|
"needs_user_action",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class pruef_ergebnis:
|
class pruef_ergebnis:
|
||||||
"""
|
"""
|
||||||
Einheitliches Ergebnisobjekt für Prüfer im Verfahrens-DB-Workflow.
|
Einheitliches Ergebnisobjekt für Prüfer.
|
||||||
|
- ok: True wenn Prüfung bestanden
|
||||||
Attributes
|
- meldung: menschenlesbare Meldung
|
||||||
----------
|
- aktion: maschinenlesbarer Aktionscode (PruefAktion)
|
||||||
ok : bool
|
- kontext: optionaler Zusatzkontext (z. B. Pfad, Layer-Objekt)
|
||||||
True wenn Prüfung bestanden und Pipeline fortgesetzt werden kann.
|
|
||||||
False signalisiert Fehler oder Nutzerentscheidung erforderlich.
|
|
||||||
meldung : Optional[str], optional
|
|
||||||
Menschenlesbare Meldung für UI-Dialoge (BY: Pruefmanager).
|
|
||||||
aktion : Optional[PruefAktion], optional
|
|
||||||
Maschinenlesbarer Aktionscode für nachfolgende Pipeline-Schritte.
|
|
||||||
kontext : Optional[Any], optional
|
|
||||||
Zusatzkontext: meist `pathlib.Path` für Dateipfade oder Layer-Objekte.
|
|
||||||
|
|
||||||
Verfahrens-DB-spezifische Aktionen:
|
|
||||||
|
|
||||||
+-----------------------------+-------------------------------------------------+
|
|
||||||
| Aktion | Bedeutung |
|
|
||||||
+=============================+=================================================+
|
|
||||||
| ``datei_wird_erzeugt`` | 2.d: Neues GPKG wird angelegt (Pfad gültig) |
|
|
||||||
+-----------------------------+-------------------------------------------------+
|
|
||||||
| ``datei_existiert`` | Datei vorhanden → Layer-Überschreibung prüfen |
|
|
||||||
+-----------------------------+-------------------------------------------------+
|
|
||||||
| ``datei_existiert_*`` | 2.e: Nutzerentscheidung für bestehende Datei |
|
|
||||||
+-----------------------------+-------------------------------------------------+
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ok: bool
|
ok: bool
|
||||||
meldung: Optional[str] = None
|
meldung: Optional[str] = None
|
||||||
aktion: Optional[PruefAktion] = None
|
aktion: Optional[PruefAktion] = None
|
||||||
kontext: Optional[Any] = None
|
kontext: Optional[Any] = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, ok: bool, meldung: Optional[str] = None, aktion: Optional[PruefAktion] = None, kontext: Optional[Any] = None):
|
||||||
self,
|
|
||||||
ok: bool,
|
|
||||||
meldung: Optional[str] = None,
|
|
||||||
aktion: Optional[PruefAktion] = None,
|
|
||||||
kontext: Optional[Any] = None,
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Erstellt ein neues Prüfergebnis.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
ok : bool
|
|
||||||
True für "weiter mit Pipeline", False für "Entscheidung/Fehler".
|
|
||||||
meldung : Optional[str]
|
|
||||||
UI-Text für Nutzerdialoge.
|
|
||||||
aktion : Optional[PruefAktion]
|
|
||||||
Maschinenaktion für nachfolgende Verarbeitung.
|
|
||||||
kontext : Optional[Any]
|
|
||||||
Typischerweise `pathlib.Path` (Dateipfad) oder `QgsVectorLayer`.
|
|
||||||
"""
|
|
||||||
self.ok = ok
|
self.ok = ok
|
||||||
self.meldung = meldung
|
self.meldung = meldung
|
||||||
self.aktion = aktion
|
self.aktion = aktion
|
||||||
self.kontext = kontext
|
self.kontext = kontext
|
||||||
|
|
||||||
@property
|
|
||||||
def ist_verfahrens_db_aktion(self) -> bool:
|
|
||||||
"""
|
|
||||||
Prüft, ob es sich um eine Verfahrens-DB-spezifische Aktion handelt.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
bool
|
|
||||||
True für ``datei_wird_erzeugt`` oder ``datei_existiert*``.
|
|
||||||
"""
|
|
||||||
return self.aktion in {
|
|
||||||
"datei_wird_erzeugt",
|
|
||||||
"datei_existiert",
|
|
||||||
"datei_existiert_ueberschreiben",
|
|
||||||
"datei_existiert_anhaengen",
|
|
||||||
"datei_existiert_ueberspringen",
|
|
||||||
}
|
|
||||||
|
|
||||||
@property
|
|
||||||
def dateipfad(self) -> Optional[Path]:
|
|
||||||
"""
|
|
||||||
Extrahiert den Dateipfad aus dem Kontext (falls vorhanden).
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Optional[Path]
|
|
||||||
`Path`-Objekt oder None.
|
|
||||||
"""
|
|
||||||
if isinstance(self.kontext, Path):
|
|
||||||
return self.kontext
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def erlaubte_persistierung(self) -> bool:
|
|
||||||
"""
|
|
||||||
Prüft, ob die Pipeline Daten persistieren darf.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
bool
|
|
||||||
True für ``datei_wird_erzeugt``, ``datei_existiert_ueberschreiben``,
|
|
||||||
``datei_existiert_anhaengen``.
|
|
||||||
"""
|
|
||||||
return self.aktion in {
|
|
||||||
"datei_wird_erzeugt",
|
|
||||||
"datei_existiert_ueberschreiben",
|
|
||||||
"datei_existiert_anhaengen",
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Die Anwendung erfolgt später über eine Aktion.
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from sn_basis.functions.sys_wrapper import file_exists
|
from sn_basis.functions import file_exists
|
||||||
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis
|
from sn_basis.modules.pruef_ergebnis import pruef_ergebnis
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
plugin.info
11
plugin.info
@@ -1,11 +0,0 @@
|
|||||||
name=LNO Sachsen | Basisfunktionen
|
|
||||||
description=Plugin mit Basisfunktionen
|
|
||||||
author=Daniel Helbig
|
|
||||||
email=daniel.helbig@kreis-meissen.de
|
|
||||||
qgisMinimumVersion=3.0
|
|
||||||
qgisMaximumVersion=3.99
|
|
||||||
deprecated=False
|
|
||||||
experimental=False
|
|
||||||
supportsQt6=Yes
|
|
||||||
|
|
||||||
zip_folder=sn_basis
|
|
||||||
Reference in New Issue
Block a user