From 96b0f46ae2bf6bf3daca641990867f9ea54ff9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Wed, 20 Nov 2024 18:52:41 -0500 Subject: [PATCH 1/7] [ili2db] Add ili2db's exportMetaConfig operation (available since ili2db v5.2.0) to get all parameters used in the schema import operation exported to a single file --- modelbaker/iliwrapper/ili2dbconfig.py | 20 ++++++++++++ modelbaker/iliwrapper/iliexecutable.py | 2 +- .../iliwrapper/ilimetaconfigexporter.py | 32 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 modelbaker/iliwrapper/ilimetaconfigexporter.py diff --git a/modelbaker/iliwrapper/ili2dbconfig.py b/modelbaker/iliwrapper/ili2dbconfig.py index 1d2344d..f22486a 100644 --- a/modelbaker/iliwrapper/ili2dbconfig.py +++ b/modelbaker/iliwrapper/ili2dbconfig.py @@ -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 diff --git a/modelbaker/iliwrapper/iliexecutable.py b/modelbaker/iliwrapper/iliexecutable.py index 92feec7..34f6180 100644 --- a/modelbaker/iliwrapper/iliexecutable.py +++ b/modelbaker/iliwrapper/iliexecutable.py @@ -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): diff --git a/modelbaker/iliwrapper/ilimetaconfigexporter.py b/modelbaker/iliwrapper/ilimetaconfigexporter.py new file mode 100644 index 0000000..25dba56 --- /dev/null +++ b/modelbaker/iliwrapper/ilimetaconfigexporter.py @@ -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 From f4ff6e7b9a84a4338d4b6ddaae3e8c168c92a6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Wed, 20 Nov 2024 18:53:50 -0500 Subject: [PATCH 2/7] [tests] Add tests for ili2db's exportMetaConfig operation --- tests/test_exportmetaconfig.py | 240 +++++++++++++++++++++++++++++++++ tests/utils.py | 26 ++++ 2 files changed, 266 insertions(+) create mode 100644 tests/test_exportmetaconfig.py diff --git a/tests/test_exportmetaconfig.py b/tests/test_exportmetaconfig.py new file mode 100644 index 0000000..f0ee41f --- /dev/null +++ b/tests/test_exportmetaconfig.py @@ -0,0 +1,240 @@ +""" +/*************************************************************************** + ------------------- + begin : 20.11.2024 + git sha : :%H$ + copyright : (C) 2024 by Germán Carrillo + email : german at 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. * + * * + ***************************************************************************/ +""" + +import configparser +import datetime +import logging +import os +import shutil +import tempfile + +from qgis.testing import start_app, unittest + +from modelbaker.iliwrapper import iliimporter, ilimetaconfigexporter +from modelbaker.iliwrapper.globals import DbIliMode +from tests.utils import iliimporter_config, ilimetaconfigexporter_config, testdata_path + +start_app() + + +class TestExportMetaConfig(unittest.TestCase): + @classmethod + def setUpClass(cls): + """Run before all tests.""" + cls.basetestpath = tempfile.mkdtemp() + + def test_exportmetaconfig_postgis(self): + # Schema Import + importer = iliimporter.Importer() + importer.tool = DbIliMode.ili2pg + importer.configuration = iliimporter_config(importer.tool) + importer.configuration.ilifile = testdata_path( + "ilimodels/PipeBasketTest_V1.ili" + ) + importer.configuration.ilimodels = "PipeBasketTest" + importer.configuration.dbschema = "any_{:%Y%m%d%H%M%S%f}".format( + datetime.datetime.now() + ) + importer.configuration.inheritance = "smart2" + importer.configuration.create_basket_col = True + importer.stdout.connect(self.print_info) + importer.stderr.connect(self.print_error) + assert importer.run() == iliimporter.Importer.SUCCESS + + # ExportMetaConfig + exportMetaConfig = ilimetaconfigexporter.MetaConfigExporter() + exportMetaConfig.tool = DbIliMode.ili2pg + exportMetaConfig.configuration = ilimetaconfigexporter_config(importer.tool) + metaconfig_file = os.path.join( + self.basetestpath, "tmp_exported_metaconfig_pg.ini" + ) + exportMetaConfig.configuration.metaconfigoutputfile = metaconfig_file + exportMetaConfig.stdout.connect(self.print_info) + exportMetaConfig.stderr.connect(self.print_error) + assert ( + exportMetaConfig.run() == ilimetaconfigexporter.MetaConfigExporter.SUCCESS + ) + + # Check output metaConfig file + assert os.path.isfile(metaconfig_file) + + config = configparser.ConfigParser() + config.read(metaconfig_file) + assert "CONFIGURATION" in config + assert "ch.ehi.ili2db" in config + params = dict(config["ch.ehi.ili2db"]) + + expected_key_values = { + "iligml20": "false", + "beautifyenumdispname": "false", + "createbasketcol": "false", + "createdatasetcol": "false", + "createdatetimechecks": "false", + "createenumcolasitfcode": "false", + "createenumtxtcol": "false", + "createfk": "false", + "createfkidx": "false", + "creategeomidx": "false", + "createimporttabs": "false", + "createmandatorychecks": "false", + "createmetainfo": "false", + "createnlstab": "false", + "createnumchecks": "false", + "createstdcols": "false", + "createtextchecks": "false", + "createtidcol": "false", + "createtypeconstraint": "false", + "createtypediscriminator": "false", + "createunique": "false", + "disableareavalidation": "false", + "disableboundaryrecoding": "true", + "disablenameoptimization": "false", + "disablerounding": "false", + "disablevalidation": "true", + "exporttid": "false", + "forcetypevalidation": "false", + "importbid": "false", + "importtid": "false", + "keeparearef": "false", + "multisrs": "false", + "namebytopic": "false", + "nosmartmapping": "true", + "skipgeometryerrors": "false", + "skipreferenceerrors": "false", + "sqlcolsastext": "false", + "sqlenablenull": "false", + "sqlextrefcols": "false", + "strokearcs": "false", + "ver3-translation": "false", + } + + for k, v in expected_key_values.items(): + assert k in params and params[k] == v + + def test_exportmetaconfig_geopackage(self): + # Schema Import + importer = iliimporter.Importer() + importer.tool = DbIliMode.ili2gpkg + importer.configuration = iliimporter_config(importer.tool) + importer.configuration.ilifile = testdata_path( + "ilimodels/PipeBasketTest_V1.ili" + ) + importer.configuration.ilimodels = "PipeBasketTest" + importer.configuration.dbfile = os.path.join( + self.basetestpath, "tmp_delete_dataset_gpkg.gpkg" + ) + importer.configuration.inheritance = "smart2" + importer.configuration.create_basket_col = True + importer.stdout.connect(self.print_info) + importer.stderr.connect(self.print_error) + assert importer.run() == iliimporter.Importer.SUCCESS + + # ExportMetaConfig + exportMetaConfig = ilimetaconfigexporter.MetaConfigExporter() + exportMetaConfig.tool = DbIliMode.ili2gpkg + exportMetaConfig.configuration = ilimetaconfigexporter_config(importer.tool) + exportMetaConfig.configuration.dbfile = importer.configuration.dbfile + metaconfig_file = os.path.join( + self.basetestpath, "tmp_exported_metaconfig_gpkg.ini" + ) + exportMetaConfig.configuration.metaconfigoutputfile = metaconfig_file + exportMetaConfig.stdout.connect(self.print_info) + exportMetaConfig.stderr.connect(self.print_error) + assert ( + exportMetaConfig.run() == ilimetaconfigexporter.MetaConfigExporter.SUCCESS + ) + + # Check output metaConfig file + assert os.path.isfile(metaconfig_file) + + config = configparser.ConfigParser() + config.read(metaconfig_file) + assert "CONFIGURATION" in config + assert "ch.ehi.ili2db" in config + params = dict(config["ch.ehi.ili2db"]) + + expected_key_values = { + "iligml20": "false", + "beautifyenumdispname": "true", + "coalescearray": "true", + "coalescecatalogueref": "true", + "coalescejson": "true", + "coalescemultiline": "true", + "coalescemultipoint": "true", + "coalescemultisurface": "true", + "createbasketcol": "true", + "createdatasetcol": "false", + "createdatetimechecks": "false", + "createenumcolasitfcode": "false", + "createenumtabswithid": "true", + "createenumtxtcol": "false", + "createfk": "true", + "createfkidx": "true", + "creategeomidx": "true", + "createimporttabs": "false", + "createmandatorychecks": "false", + "createmetainfo": "true", + "createnlstab": "true", + "createnumchecks": "true", + "createstdcols": "false", + "createtextchecks": "false", + "createtidcol": "true", + "createtypeconstraint": "true", + "createtypediscriminator": "false", + "createunique": "true", + "defaultsrsauth": "EPSG", + "defaultsrscode": "2056", + "disableareavalidation": "false", + "disableboundaryrecoding": "true", + "disablenameoptimization": "false", + "disablerounding": "false", + "disablevalidation": "true", + "expandlocalised": "true", + "expandmultilingual": "true", + "exporttid": "false", + "forcetypevalidation": "false", + "importbid": "false", + "importtid": "false", + "keeparearef": "false", + "maxnamelength": "60", + "multisrs": "false", + "namebytopic": "false", + "skipgeometryerrors": "false", + "skipreferenceerrors": "false", + "smart2inheritance": "true", + "sqlcolsastext": "false", + "sqlenablenull": "false", + "sqlextrefcols": "false", + "strokearcs": "true", + "ver3-translation": "false", + } + + for k, v in expected_key_values.items(): + assert k in params and params[k] == v + + def print_info(self, text): + logging.info(text) + + def print_error(self, text): + logging.error(text) + + @classmethod + def tearDownClass(cls): + """Run after all tests.""" + shutil.rmtree(cls.basetestpath, True) diff --git a/tests/utils.py b/tests/utils.py index fc53132..3e64ae9 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -28,6 +28,7 @@ BaseConfiguration, DeleteConfiguration, ExportConfiguration, + ExportMetaConfigConfiguration, ImportDataConfiguration, SchemaImportConfiguration, UpdateDataConfiguration, @@ -192,6 +193,31 @@ def ilideleter_config(tool=DbIliMode.ili2pg, modeldir=None): return configuration +def ilimetaconfigexporter_config(tool=DbIliMode.ili2pg, modeldir=None): + base_config = BaseConfiguration() + if modeldir is None: + base_config.custom_model_directories_enabled = False + else: + base_config.custom_model_directories = testdata_path(modeldir) + base_config.custom_model_directories_enabled = True + + configuration = ExportMetaConfigConfiguration() + if tool == DbIliMode.ili2pg: + configuration.dbhost = os.environ["PGHOST"] + configuration.dbusr = "docker" + configuration.dbpwd = "docker" + configuration.database = "gis" + elif tool == DbIliMode.ili2mssql: + configuration.dbhost = "mssql" + configuration.dbusr = "sa" + configuration.dbpwd = "" + configuration.database = "gis" + + configuration.base_configuration = base_config + + return configuration + + @pytest.mark.skip("This is a utility function, not a test function") def testdata_path(path): basepath = os.path.dirname(os.path.abspath(__file__)) From c1216a447b1dd513f1eb1018e30b978f0e95dc26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Tue, 26 Nov 2024 00:00:38 -0500 Subject: [PATCH 3/7] [pre-commit] Upgrade autoflake so that we get rid of its distutils dependency (package removed in Python 3.12, and deprecated in Python 3.10) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8a3d203..3ed6586 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: From 66122d583ea68e8ffdab0a4afcd34bbe7f241d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Tue, 26 Nov 2024 00:01:03 -0500 Subject: [PATCH 4/7] [ili2db] Add export_metaconfig handy method to Ili2dbUtils; parse parameters from an exported metaConfig .ini file in ilitoppingmaker --- modelbaker/ilitoppingmaker/ili2dbsettings.py | 15 +++++++ modelbaker/utils/ili2db_utils.py | 45 +++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/modelbaker/ilitoppingmaker/ili2dbsettings.py b/modelbaker/ilitoppingmaker/ili2dbsettings.py index 9b4ea87..8146e8d 100644 --- a/modelbaker/ilitoppingmaker/ili2dbsettings.py +++ b/modelbaker/ilitoppingmaker/ili2dbsettings.py @@ -16,6 +16,8 @@ * * ***************************************************************************/ """ +import configparser +from pathlib import Path class Ili2dbSettings(dict): @@ -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 diff --git a/modelbaker/utils/ili2db_utils.py b/modelbaker/utils/ili2db_utils.py index b8410d4..786386a 100644 --- a/modelbaker/utils/ili2db_utils.py +++ b/modelbaker/utils/ili2db_utils.py @@ -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 @@ -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) From a4614ad35ae2a44fd4ceba7440456f6626d4e086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Tue, 26 Nov 2024 13:18:06 -0500 Subject: [PATCH 5/7] Make sure ConfigParser preserves case when parsing exported metaConfig file --- modelbaker/ilitoppingmaker/ili2dbsettings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modelbaker/ilitoppingmaker/ili2dbsettings.py b/modelbaker/ilitoppingmaker/ili2dbsettings.py index 8146e8d..e8a5ff4 100644 --- a/modelbaker/ilitoppingmaker/ili2dbsettings.py +++ b/modelbaker/ilitoppingmaker/ili2dbsettings.py @@ -112,6 +112,7 @@ 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 From 13e09e9dc1d271568d3c5193d4d3f32bf2ab50db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Tue, 26 Nov 2024 17:01:13 -0500 Subject: [PATCH 6/7] Remove parse_parameters_from_db in favor() of parse_parameters_from_ini_file() when getting ili2db settings for the topping maker --- modelbaker/ilitoppingmaker/ili2dbsettings.py | 73 -------------------- tests/test_ilitoppingmaker.py | 20 +++--- tests/testdata/metaconfig/ini_file.ini | 9 +++ 3 files changed, 17 insertions(+), 85 deletions(-) create mode 100644 tests/testdata/metaconfig/ini_file.ini diff --git a/modelbaker/ilitoppingmaker/ili2dbsettings.py b/modelbaker/ilitoppingmaker/ili2dbsettings.py index e8a5ff4..ff02325 100644 --- a/modelbaker/ilitoppingmaker/ili2dbsettings.py +++ b/modelbaker/ilitoppingmaker/ili2dbsettings.py @@ -35,79 +35,6 @@ 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). - """ - - 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" - ] - - # 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 - - return True - def parse_parameters_from_ini_file(self, ini_file: str) -> bool: p = Path(ini_file) if p.exists(): diff --git a/tests/test_ilitoppingmaker.py b/tests/test_ilitoppingmaker.py index 1928049..c9b5466 100644 --- a/tests/test_ilitoppingmaker.py +++ b/tests/test_ilitoppingmaker.py @@ -25,7 +25,6 @@ from qgis.core import QgsProject, QgsVectorLayer from qgis.testing import start_app, unittest -import modelbaker.utils.db_utils as db_utils from modelbaker.dataobjects.project import Project from modelbaker.db_factory.gpkg_command_config_manager import GpkgCommandConfigManager from modelbaker.generator.generator import Generator @@ -129,9 +128,9 @@ def test_workflow_stepbystep(self): configuration.dbfile = self.dbfile configuration.tool = DbIliMode.ili2gpkg - db_connector = db_utils.get_db_connector(configuration) - if db_connector: - topping.metaconfig.ili2db_settings.parse_parameters_from_db(db_connector) + # Let's pretend we've obtained the exported MetaConfig file already + ini_file = testdata_path("metaconfig/ini_file.ini") + topping.metaconfig.ili2db_settings.parse_parameters_from_ini_file(ini_file) topping.metaconfig.ili2db_settings.metaattr_path = testdata_path( "toml/KbS_V1_5.toml" @@ -147,8 +146,7 @@ def test_workflow_stepbystep(self): ) assert topping.metaconfig.ili2db_settings.parameters["createTidCol"] == True assert topping.metaconfig.ili2db_settings.parameters["createBasketCol"] == True - # unset so not existing - assert not topping.metaconfig.ili2db_settings.parameters.get("strokeArcs", None) + assert topping.metaconfig.ili2db_settings.parameters["strokeArcs"] == False # ... and finally create the cake @@ -195,12 +193,10 @@ def test_workflow_makeit_way(self): # prepare metaconfig metaconfig = MetaConfig() - configuration = Ili2DbCommandConfiguration() - configuration.dbfile = self.dbfile - configuration.tool = DbIliMode.ili2gpkg - db_connector = db_utils.get_db_connector(configuration) - if db_connector: - metaconfig.ili2db_settings.parse_parameters_from_db(db_connector) + + # Let's pretend we've already obtained the exported settings in the MetaConfig ini file + ini_file = testdata_path("metaconfig/ini_file.ini") + metaconfig.ili2db_settings.parse_parameters_from_ini_file(ini_file) metaconfig.ili2db_settings.metaattr_path = testdata_path("toml/KbS_V1_5.toml") metaconfig.ili2db_settings.prescript_path = "" metaconfig.ili2db_settings.postscript_path = ( diff --git a/tests/testdata/metaconfig/ini_file.ini b/tests/testdata/metaconfig/ini_file.ini new file mode 100644 index 0000000..b198f91 --- /dev/null +++ b/tests/testdata/metaconfig/ini_file.ini @@ -0,0 +1,9 @@ +[CONFIGURATION] +qgis.modelbaker.projecttopping = ilidata:projecttopping_topping_project_yaml_001 + +[ch.ehi.ili2db] +models = City_V1 +smart2Inheritance = true +createTidCol = true +createBasketCol = true +strokeArcs = false From c7980831a3a8d9e4aef739dd92ec956f053f52a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Tue, 26 Nov 2024 17:02:12 -0500 Subject: [PATCH 7/7] Parse boolean values from exportMetaConfig command ('false' -> False and 'true' -> True) --- modelbaker/ilitoppingmaker/ili2dbsettings.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modelbaker/ilitoppingmaker/ili2dbsettings.py b/modelbaker/ilitoppingmaker/ili2dbsettings.py index ff02325..e34221f 100644 --- a/modelbaker/ilitoppingmaker/ili2dbsettings.py +++ b/modelbaker/ilitoppingmaker/ili2dbsettings.py @@ -44,7 +44,11 @@ def parse_parameters_from_ini_file(self, ini_file: str) -> bool: if not "CONFIGURATION" in config or not "ch.ehi.ili2db" in config: return False - self.parameters = dict(config["ch.ehi.ili2db"]) + def parse_boolean(v): + return True if v == "true" else (False if v == "false" else v) + + params = dict(config["ch.ehi.ili2db"]) + self.parameters = {k: parse_boolean(v) for k, v in params.items()} return True return False