Skip to content

Commit

Permalink
Merge pull request #121 from opengisch/add_exportmetaconfig_operation
Browse files Browse the repository at this point in the history
Add ili2db's exportMetaConfig operation
  • Loading branch information
signedav authored Nov 27, 2024
2 parents e21e709 + c798083 commit 6ab186b
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:

# Remove unused imports/variables
- repo: https://github.com/myint/autoflake
rev: v1.4
rev: v2.3.1
hooks:
- id: autoflake
args:
Expand Down
85 changes: 16 additions & 69 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 All @@ -33,75 +35,20 @@ def __init__(self):
self.prescript_path = None
self.models = []

def parse_parameters_from_db(self, db_connector):
"""
Fill the parameter list according to a existing database schema (passed by the specific extension of DBConnector).
It only considers the settings "known" by modelbaker (the parameters set by the user or by modelbaker per default).
The parameter are only set when they are available (and not unset when they are not available).
"""
def parse_parameters_from_ini_file(self, ini_file: str) -> bool:
p = Path(ini_file)
if p.exists():
config = configparser.ConfigParser()
config.optionxform = str # To preserve case
config.read(ini_file)
if not "CONFIGURATION" in config or not "ch.ehi.ili2db" in config:
return False

setting_records = db_connector.get_ili2db_settings()
settings_dict = {}
self.parameters = {}
for setting_record in setting_records:
settings_dict[setting_record["tag"]] = setting_record["setting"]

# user settings
if settings_dict.get("ch.ehi.ili2db.inheritanceTrafo", None) == "smart1":
self.parameters["smart1Inheritance"] = True
if settings_dict.get("ch.ehi.ili2db.inheritanceTrafo", None) == "smart2":
self.parameters["smart2Inheritance"] = True
if settings_dict.get("ch.ehi.ili2db.StrokeArcs", None) == "enable":
self.parameters["strokeArcs"] = True
if settings_dict.get("ch.ehi.ili2db.BasketHandling", None) == "readWrite":
self.parameters["createBasketCol"] = True
if settings_dict.get("ch.ehi.ili2db.defaultSrsAuthority", None):
self.parameters["defaultSrsAuth"] = settings_dict[
"ch.ehi.ili2db.defaultSrsAuthority"
]
if settings_dict.get("ch.ehi.ili2db.StrokedefaultSrsCodeArcs", None):
self.parameters["defaultSrsCode"] = settings_dict[
"ch.ehi.ili2db.defaultSrsCode"
]
def parse_boolean(v):
return True if v == "true" else (False if v == "false" else v)

# modelbaker default settings
if settings_dict.get("ch.ehi.ili2db.catalogueRefTrafo", None) == "coalesce":
self.parameters["coalesceCatalogueRef"] = True
if (
settings_dict.get("ch.ehi.ili2db.createEnumDefs", None)
== "multiTableWithId"
):
self.parameters["createEnumTabsWithId"] = True
if settings_dict.get("ch.ehi.ili2db.numericCheckConstraints", None) == "create":
self.parameters["createNumChecks"] = True
if settings_dict.get("ch.ehi.ili2db.uniqueConstraints", None) == "create":
self.parameters["createUnique"] = True
if settings_dict.get("ch.ehi.ili2db.createForeignKey", None) == "yes":
self.parameters["createFk"] = True
if settings_dict.get("ch.ehi.ili2db.createForeignKeyIndex", None) == "yes":
self.parameters["createFkIdx"] = True
if settings_dict.get("ch.ehi.ili2db.multiSurfaceTrafo", None) == "coalesce":
self.parameters["coalesceMultiSurface"] = True
if settings_dict.get("ch.ehi.ili2db.multiLineTrafo", None) == "coalesce":
self.parameters["coalesceMultiLine"] = True
if settings_dict.get("ch.ehi.ili2db.multiPointTrafo", None) == "coalesce":
self.parameters["coalesceMultiPoint"] = True
if settings_dict.get("ch.ehi.ili2db.arrayTrafo", None) == "coalesce":
self.parameters["coalesceArray"] = True
if (
settings_dict.get("ch.ehi.ili2db.beautifyEnumDispName", None)
== "underscore"
):
self.parameters["beautifyEnumDispName"] = True
if settings_dict.get("ch.ehi.sqlgen.createGeomIndex", None) == "underscore":
self.parameters["createGeomIdx"] = True
if settings_dict.get("ch.ehi.ili2db.createMetaInfo", None):
self.parameters["createMetaInfo"] = True
if settings_dict.get("ch.ehi.ili2db.multilingualTrafo", None) == "expand":
self.parameters["expandMultilingual"] = True
if settings_dict.get("ch.ehi.ili2db.createTypeConstraint", None):
self.parameters["createTypeConstraint"] = True
if settings_dict.get("ch.ehi.ili2db.TidHandling", None) == "property":
self.parameters["createTidCol"] = True
params = dict(config["ch.ehi.ili2db"])
self.parameters = {k: parse_boolean(v) for k, v in params.items()}
return True

return True
return False
20 changes: 20 additions & 0 deletions modelbaker/iliwrapper/ili2dbconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,23 @@ def to_ili2db_args(self, extra_args=[], with_action=True):
self.append_args(args, Ili2DbCommandConfiguration.to_ili2db_args(self))

return args


class ExportMetaConfigConfiguration(Ili2DbCommandConfiguration):
def __init__(self, other: Ili2DbCommandConfiguration = None):
super().__init__(other)
self.metaconfigoutputfile = ""

def to_ili2db_args(self, extra_args=[], with_action=True):
args = list()

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

self.append_args(args, extra_args)

self.append_args(args, ["--metaConfig", self.metaconfigoutputfile])

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

return args
2 changes: 1 addition & 1 deletion modelbaker/iliwrapper/iliexecutable.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IliExecutable(QObject, metaclass=AbstractQObjectMeta):
process_finished = pyqtSignal(int, int)
cancel_process = pyqtSignal()

__done_pattern = re.compile(r"Info: \.\.\.([a-z]+ )?done")
__done_pattern = re.compile(r"Info: \.\.\.([a-zA-Z]+ )?done")
__result = None

def __init__(self, parent=None):
Expand Down
32 changes: 32 additions & 0 deletions modelbaker/iliwrapper/ilimetaconfigexporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
/***************************************************************************
-------------------
begin : 20/11/24
git sha : :%H$
copyright : (C) 2024 by Germán Carrillo
email : german@opengis.ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from .ili2dbconfig import ExportMetaConfigConfiguration, Ili2DbCommandConfiguration
from .iliexecutable import IliExecutable


class MetaConfigExporter(IliExecutable):
def __init__(self, parent=None):
super().__init__(parent)
self.version = 4

def _create_config(self) -> Ili2DbCommandConfiguration:
return ExportMetaConfigConfiguration()

def _get_ili2db_version(self):
return self.version
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
Loading

0 comments on commit 6ab186b

Please sign in to comment.