Skip to content

Commit

Permalink
Fix progress step index, remove unused method
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSander committed Oct 5, 2024
1 parent 466f6bc commit 47333bd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
7 changes: 0 additions & 7 deletions geocatbridge/servers/models/geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,13 +972,6 @@ def workspaceExists(self):
url = f"{self.apiUrl}/workspaces.json"
return self._exists(url, "workspace", self.workspace)

def willDeleteLayersOnPublication(self, to_publish: List[str]):
""" Checks if any of the layer names of the given QGIS layer IDs already exist on the server workspace. """
if self.workspaceExists():
# If the set of selected QGIS layers is NOT disjoint with the layers on the server, layers will be deleted!
return not frozenset(listLayerNames(to_publish)).isdisjoint(self.layerNames().keys())
return False

def datastoreExists(self, name):
url = f"{self.apiUrl}/workspaces/{self.workspace}/datastores.json"
return self._exists(url, "dataStore", name)
Expand Down
10 changes: 6 additions & 4 deletions geocatbridge/servers/views/geoserver.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import time
from functools import partial
from itertools import chain
from requests import HTTPError
from typing import Optional

from qgis.PyQt.QtWidgets import QHBoxLayout
from qgis.PyQt.QtWidgets import QHBoxLayout, QProgressDialog

from geocatbridge.servers.bases import ServerWidgetBase
from geocatbridge.servers.models.gs_storage import GeoserverStorage
Expand Down Expand Up @@ -177,7 +178,7 @@ def updateDbServersCombo(self, managed_by_geoserver: bool, init_value=None):
this value can be set immediately as the only available and selected item.
Doing so prevents a full refresh of GeoServer datastores.
"""
def addGeoserverPgDatastores(current_db_: str, worker_result):
def _addGeoserverPgDatastores(current_db_: str, worker_result):
if worker_result:
# Worker result might be a list of lists, so we should flatten it
datastores = list(chain.from_iterable(worker_result))
Expand Down Expand Up @@ -221,10 +222,11 @@ def addGeoserverPgDatastores(current_db_: str, worker_result):
pg_dialog = self.parent.getProgressDialog("Retrieving PostGIS datastores...",
len(workspaces), self.dsThread.requestInterruption)
self.dsWorker.progress.connect(pg_dialog.setValue)
self.dsWorker.results.connect(partial(addGeoserverPgDatastores, current_db))
self.dsWorker.finished.connect(pg_dialog.close)
self.dsWorker.results.connect(partial(_addGeoserverPgDatastores, current_db))
self.dsWorker.start()
except Exception as e:
msg = f'Failed to retrieve datastores for {getattr(server, "serverName", self.txtGeoserverName.text())}' # noqa
msg = f'Failed to retrieve datastores for {getattr(server, "serverName", self.txtGeoserverName.text())}'
if isinstance(e, HTTPError) and e.response.status_code == 401:
msg = f'{msg}: please check credentials'
else:
Expand Down
1 change: 1 addition & 0 deletions geocatbridge/ui/publishwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ def _testServer(srv: manager.bases.ServerBase, combo: QComboBox) -> bool:
for err in errors:
self.showErrorBar("Error", err)
return False
combo.setStyleSheet('') # reset default style
return True

def _testServers() -> tuple[manager.bases.DataCatalogServerBase, manager.bases.MetaCatalogServerBase]:
Expand Down
10 changes: 8 additions & 2 deletions geocatbridge/utils/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ def getProgressDialog(self, label, max_length, callback=None) -> QProgressDialog
:param callback: Callback function to be executed when the user presses "Cancel".
:return: A QProgressDialog instance.
"""
pg_dialog = QProgressDialog(label, self.translate("Cancel"), 0, max_length,
self if isinstance(self, QWidget) else None)
if not isinstance(self, QWidget):
raise ValueError("A QWidget parent instance is required to show a progress dialog.")
pg_dialog = QProgressDialog(self, QtCore.Qt.WindowType.Popup)
pg_dialog.setLabelText(label)
pg_dialog.setAutoReset(False)
pg_dialog.setAutoClose(False)
pg_dialog.setCancelButtonText(self.tr("Cancel"))
pg_dialog.setRange(0, max_length)
pg_dialog.canceled.connect(callback, type=QtCore.Qt.DirectConnection) # noqa
pg_dialog.setWindowModality(QtCore.Qt.WindowModal)
pg_dialog.setWindowTitle(getAppName())
Expand Down
7 changes: 3 additions & 4 deletions geocatbridge/utils/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,13 @@ class BackgroundWorker(QtCore.QObject):
finished = QtCore.pyqtSignal()
results = QtCore.pyqtSignal(list)

def __init__(self):
super().__init__()

def _run(self, func: Callable, items: Iterable):
results_ = []
try:
if isgenerator(items):
# Flatten generators into a tuple
items = tuple(items)
for step, item in enumerate(items):
for step, item in enumerate(items, 1):
self.progress.emit(step)
try:
results_.append(func(item))
Expand All @@ -100,6 +97,8 @@ def _run(self, func: Callable, items: Iterable):
results_.append(e)
if self.thread().isInterruptionRequested():
break
# Tiny delay so user can see the progress bar at 100%
self.thread().msleep(100)
finally:
self.results.emit(results_)
self.finished.emit()
Expand Down

0 comments on commit 47333bd

Please sign in to comment.