Skip to content

Commit

Permalink
[ili2db] Add export_metaconfig handy method to Ili2dbUtils; parse par…
Browse files Browse the repository at this point in the history
…ameters from an exported metaConfig .ini file in ilitoppingmaker
  • Loading branch information
gacarrillor committed Nov 26, 2024
1 parent c1216a4 commit 66122d5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
15 changes: 15 additions & 0 deletions modelbaker/ilitoppingmaker/ili2dbsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* *
***************************************************************************/
"""
import configparser
from pathlib import Path


class Ili2dbSettings(dict):
Expand Down Expand Up @@ -105,3 +107,16 @@ def parse_parameters_from_db(self, db_connector):
self.parameters["createTidCol"] = True

return True

def parse_parameters_from_ini_file(self, ini_file: str) -> bool:
p = Path(ini_file)
if p.exists():
config = configparser.ConfigParser()
config.read(ini_file)
if not "CONFIGURATION" in config or not "ch.ehi.ili2db" in config:
return False

self.parameters = dict(config["ch.ehi.ili2db"])
return True

return False
45 changes: 43 additions & 2 deletions modelbaker/utils/ili2db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
"""
from qgis.PyQt.QtCore import QObject, Qt, pyqtSignal

from ..iliwrapper import ilideleter
from ..iliwrapper.ili2dbconfig import DeleteConfiguration, Ili2DbCommandConfiguration
from ..iliwrapper import ilideleter, ilimetaconfigexporter
from ..iliwrapper.ili2dbconfig import (
DeleteConfiguration,
ExportMetaConfigConfiguration,
Ili2DbCommandConfiguration,
)
from ..iliwrapper.ili2dbutils import JavaNotFoundError
from ..utils.qt_utils import OverrideCursor

Expand Down Expand Up @@ -108,6 +112,43 @@ def delete_dataset(

return res, msg

def export_metaconfig(
self, ini_file: str, configuration: Ili2DbCommandConfiguration = None
):
"""
:param ini_file: Output file
:param configuration: Base Ili2DbCommandConfiguration object
:return: Tuple with boolean result and optional message
"""
metaconfig_exporter = ilimetaconfigexporter.MetaConfigExporter()
metaconfig_exporter.tool = configuration.tool
metaconfig_exporter.configuration = ExportMetaConfigConfiguration(configuration)
metaconfig_exporter.configuration.metaconfigoutputfile = ini_file

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

res = True
msg = self.tr("MetaConfig successfully exported to '{}'!").format(ini_file)
try:
if (
metaconfig_exporter.run()
!= ilimetaconfigexporter.MetaConfigExporter.SUCCESS
):
msg = self.tr(
"An error occurred when exporting the metaconfig from the DB to '{}' (check the QGIS log panel)."
).format(ini_file)
res = False
self.log_on_error.emit(self._log)
except JavaNotFoundError as e:
msg = e.error_string
res = False

self._disconnect_ili_executable_signals(metaconfig_exporter)

return res, msg

def _connect_ili_executable_signals(self, ili_executable):
ili_executable.process_started.connect(self.process_started)
ili_executable.stderr.connect(self.stderr)
Expand Down

0 comments on commit 66122d5

Please sign in to comment.