Skip to content

Commit

Permalink
Implement delete basket method in Ili2dbUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor committed Oct 31, 2024
1 parent d424cbe commit 2b96644
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modelbaker/iliwrapper/ili2dbconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ class DeleteConfiguration(Ili2DbCommandConfiguration):
def __init__(self, other: Ili2DbCommandConfiguration = None):
super().__init__(other)
self.dataset = ""
self.baskets = ""

def to_ili2db_args(self, extra_args=[], with_action=True):
args = list()
Expand All @@ -491,7 +492,11 @@ def to_ili2db_args(self, extra_args=[], with_action=True):

self.append_args(args, extra_args)

self.append_args(args, ["--dataset", self.dataset])
if self.dataset:
self.append_args(args, ["--dataset", self.dataset])

if self.baskets:
self.append_args(args, ["--baskets", self.baskets])

self.append_args(args, Ili2DbCommandConfiguration.to_ili2db_args(self))

Expand Down
39 changes: 39 additions & 0 deletions modelbaker/utils/ili2db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,48 @@ def __init__(self):

self._log = ""

def delete_baskets(
self, baskets: str, configuration: Ili2DbCommandConfiguration = None
):
"""
:param baskets: Semicolon-separated list of baskets to be deleted
:param configuration: Base Ili2DbCommandConfiguration object
:return: Tuple with boolean result and optional message
"""
deleter = ilideleter.Deleter()
deleter.tool = configuration.tool
deleter.configuration = DeleteConfiguration(configuration)
deleter.configuration.baskets = baskets

with OverrideCursor(Qt.WaitCursor):
self._connect_ili_executable_signals(deleter)
self._log = ""

res = True
msg = self.tr("Basket(s) '{}' successfully deleted!").format(baskets)
try:
if deleter.run() != ilideleter.Deleter.SUCCESS:
msg = self.tr(
"An error occurred when deleting the basket(s) '{}' from the DB (check the QGIS log panel)."
).format(baskets)
res = False
self.log_on_error.emit(self._log)
except JavaNotFoundError as e:
msg = e.error_string
res = False

self._disconnect_ili_executable_signals(deleter)

return res, msg

def delete_dataset(
self, dataset: str, configuration: Ili2DbCommandConfiguration = None
):
"""
:param dataset: Dataset id to be deleted
:param configuration: Base Ili2DbCommandConfiguration object
:return: Tuple with boolean result and optional message
"""
deleter = ilideleter.Deleter()
deleter.tool = configuration.tool
deleter.configuration = DeleteConfiguration(configuration)
Expand Down

0 comments on commit 2b96644

Please sign in to comment.