From 2826db5c2881053acd04602937dcf0163a2a883e Mon Sep 17 00:00:00 2001 From: signedav Date: Tue, 18 Nov 2025 16:56:18 +0100 Subject: [PATCH 1/3] headers in proper format in tests Header format in proper py docsting style Header docstring in proper format headers of processing --- modelbaker/dataobjects/fields.py | 25 ++-- modelbaker/dataobjects/form.py | 27 ++--- modelbaker/dataobjects/layers.py | 27 ++--- modelbaker/dataobjects/legend.py | 27 ++--- modelbaker/dataobjects/project.py | 27 ++--- .../db_factory/db_command_config_manager.py | 26 ++--- modelbaker/db_factory/db_factory.py | 26 ++--- modelbaker/db_factory/db_simple_factory.py | 26 ++--- .../db_factory/gpkg_command_config_manager.py | 26 ++--- modelbaker/db_factory/gpkg_factory.py | 26 ++--- modelbaker/db_factory/gpkg_layer_uri.py | 26 ++--- modelbaker/db_factory/layer_uri.py | 26 ++--- .../mssql_command_config_manager.py | 26 ++--- modelbaker/db_factory/mssql_factory.py | 26 ++--- modelbaker/db_factory/mssql_layer_uri.py | 26 ++--- .../db_factory/pg_command_config_manager.py | 26 ++--- modelbaker/db_factory/pg_factory.py | 26 ++--- modelbaker/db_factory/pg_layer_uri.py | 26 ++--- modelbaker/dbconnector/config.py | 13 +++ modelbaker/dbconnector/db_connector.py | 34 +++--- modelbaker/dbconnector/gpkg_connector.py | 34 +++--- modelbaker/dbconnector/mssql_connector.py | 31 +++-- modelbaker/dbconnector/pg_connector.py | 44 ++++--- .../generator/domain_relations_generator.py | 27 ++--- modelbaker/generator/generator.py | 27 ++--- modelbaker/ilitoppingmaker/__init__.py | 25 ++-- modelbaker/ilitoppingmaker/ili2dbsettings.py | 27 ++--- modelbaker/ilitoppingmaker/ilidata.py | 27 ++--- .../ilitoppingmaker/iliprojecttopping.py | 26 ++--- modelbaker/ilitoppingmaker/ilitarget.py | 25 ++-- modelbaker/ilitoppingmaker/metaconfig.py | 27 ++--- modelbaker/iliwrapper/globals.py | 24 ++-- modelbaker/iliwrapper/ili2dbargs.py | 26 ++--- modelbaker/iliwrapper/ili2dbconfig.py | 26 ++--- modelbaker/iliwrapper/ili2dbtools.py | 26 ++--- modelbaker/iliwrapper/ili2dbutils.py | 26 ++--- modelbaker/iliwrapper/ilicache.py | 26 ++--- modelbaker/iliwrapper/ilideleter.py | 24 ++-- modelbaker/iliwrapper/iliexecutable.py | 25 ++-- modelbaker/iliwrapper/iliexporter.py | 26 ++--- modelbaker/iliwrapper/iliimporter.py | 24 ++-- .../iliwrapper/ilimetaconfigexporter.py | 24 ++-- modelbaker/iliwrapper/iliupdater.py | 24 ++-- modelbaker/iliwrapper/ilivalidator.py | 26 ++--- modelbaker/processing/ili2db_exporting.py | 18 +-- modelbaker/processing/ili2db_importing.py | 18 +-- modelbaker/processing/ili2db_operating.py | 19 +-- modelbaker/processing/ili2db_validating.py | 18 +-- .../processing/util_layersourceparsing.py | 18 +-- modelbaker/utils/db_utils.py | 26 ++--- modelbaker/utils/globals.py | 25 ++-- modelbaker/utils/ili2db_utils.py | 27 ++--- modelbaker/utils/qgis_utils.py | 26 ++--- modelbaker/utils/qt_utils.py | 25 ++-- tests/test_dataset_handling.py | 27 ++--- tests/test_delete.py | 27 ++--- tests/test_domain_class_relations.py | 26 ++--- tests/test_dump.py | 24 ++-- tests/test_export.py | 26 ++--- tests/test_exportmetaconfig.py | 27 ++--- tests/test_gpkg_pk.py | 26 ++--- tests/test_ili2dbcommandconfiguration.py | 27 ++--- tests/test_ilitoppingmaker.py | 27 ++--- tests/test_import.py | 26 ++--- tests/test_import_dbparams.py | 26 ++--- tests/test_metaconfig.py | 27 ++--- tests/test_multiple_geom_gpkg.py | 27 ++--- tests/test_pgservice.py | 26 ++--- tests/test_plugin.py | 24 ++-- tests/test_processing.py | 25 ++-- tests/test_projectgen.py | 27 ++--- ...rojectgen_extension_optimization_smart1.py | 27 ++--- ...rojectgen_extension_optimization_smart2.py | 27 ++--- tests/test_projectgen_generic_databases.py | 27 ++--- tests/test_projectgen_oids.py | 27 ++--- tests/test_projecttopping.py | 27 ++--- tests/test_sequence_reset.py | 27 ++--- tests/test_translations.py | 109 ++++++++++-------- tests/test_validate.py | 26 ++--- tests/test_z_geom.py | 26 ++--- tests/utils.py | 27 ++--- 81 files changed, 927 insertions(+), 1253 deletions(-) diff --git a/modelbaker/dataobjects/fields.py b/modelbaker/dataobjects/fields.py index 1a695f28..af340a9f 100644 --- a/modelbaker/dataobjects/fields.py +++ b/modelbaker/dataobjects/fields.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 2017-04-12 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@opengis.ch - ***************************************************************************/ +Metadata: + Creation Date: 2012-04-17 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@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. * - * * - ***************************************************************************/ +License: + 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 __future__ import annotations from typing import TYPE_CHECKING diff --git a/modelbaker/dataobjects/form.py b/modelbaker/dataobjects/form.py index 1e3f6998..2464165c 100644 --- a/modelbaker/dataobjects/form.py +++ b/modelbaker/dataobjects/form.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 08/08/17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-08-08 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 __future__ import annotations from typing import TYPE_CHECKING, Optional, Union diff --git a/modelbaker/dataobjects/layers.py b/modelbaker/dataobjects/layers.py index b0c6feab..27309e9f 100644 --- a/modelbaker/dataobjects/layers.py +++ b/modelbaker/dataobjects/layers.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 2016-11-14 - git sha : :%H$ - copyright : (C) 2016 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2014-11-16 + Copyright: (C) 2016 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 __future__ import annotations import logging diff --git a/modelbaker/dataobjects/legend.py b/modelbaker/dataobjects/legend.py index f60a93e2..57a33bca 100644 --- a/modelbaker/dataobjects/legend.py +++ b/modelbaker/dataobjects/legend.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 2016-12-21 - git sha : :%H$ - copyright : (C) 2016 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2021-12-16 + Copyright: (C) 2016 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 __future__ import annotations from typing import Any, Optional, Union diff --git a/modelbaker/dataobjects/project.py b/modelbaker/dataobjects/project.py index dfd58378..86a3b1c9 100644 --- a/modelbaker/dataobjects/project.py +++ b/modelbaker/dataobjects/project.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 2016-12-21 - git sha : :%H$ - copyright : (C) 2016 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2021-12-16 + Copyright: (C) 2016 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 __future__ import annotations from typing import Any, Optional diff --git a/modelbaker/db_factory/db_command_config_manager.py b/modelbaker/db_factory/db_command_config_manager.py index 5994f647..4e0c8db9 100644 --- a/modelbaker/db_factory/db_command_config_manager.py +++ b/modelbaker/db_factory/db_command_config_manager.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 13/05/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-05-13 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 __future__ import annotations from abc import ABC, abstractmethod diff --git a/modelbaker/db_factory/db_factory.py b/modelbaker/db_factory/db_factory.py index 536bf936..3325a7c8 100644 --- a/modelbaker/db_factory/db_factory.py +++ b/modelbaker/db_factory/db_factory.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 08/04/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-04-08 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 __future__ import annotations from abc import ABC, abstractmethod diff --git a/modelbaker/db_factory/db_simple_factory.py b/modelbaker/db_factory/db_simple_factory.py index 82b046cd..96e3096a 100644 --- a/modelbaker/db_factory/db_simple_factory.py +++ b/modelbaker/db_factory/db_simple_factory.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 08/04/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-04-08 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 __future__ import annotations import logging diff --git a/modelbaker/db_factory/gpkg_command_config_manager.py b/modelbaker/db_factory/gpkg_command_config_manager.py index 245f8cee..bd40dbc3 100644 --- a/modelbaker/db_factory/gpkg_command_config_manager.py +++ b/modelbaker/db_factory/gpkg_command_config_manager.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 13/05/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-05-13 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 __future__ import annotations from qgis.PyQt.QtCore import QSettings diff --git a/modelbaker/db_factory/gpkg_factory.py b/modelbaker/db_factory/gpkg_factory.py index 428b9992..d374d2ac 100644 --- a/modelbaker/db_factory/gpkg_factory.py +++ b/modelbaker/db_factory/gpkg_factory.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 08/04/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-04-08 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 __future__ import annotations from typing import Optional diff --git a/modelbaker/db_factory/gpkg_layer_uri.py b/modelbaker/db_factory/gpkg_layer_uri.py index ee828fe1..96b6a8d7 100644 --- a/modelbaker/db_factory/gpkg_layer_uri.py +++ b/modelbaker/db_factory/gpkg_layer_uri.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 30/04/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-04-30 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 .layer_uri import LayerUri diff --git a/modelbaker/db_factory/layer_uri.py b/modelbaker/db_factory/layer_uri.py index 3626aa4b..2e081510 100644 --- a/modelbaker/db_factory/layer_uri.py +++ b/modelbaker/db_factory/layer_uri.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 30/04/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-04-30 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 abc import ABC, abstractmethod diff --git a/modelbaker/db_factory/mssql_command_config_manager.py b/modelbaker/db_factory/mssql_command_config_manager.py index 75b08b12..894456b7 100644 --- a/modelbaker/db_factory/mssql_command_config_manager.py +++ b/modelbaker/db_factory/mssql_command_config_manager.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 09/05/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania (BSF Swissphoto) - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-05-09 + Copyright: (C) 2019 by Yesid Polania (BSF Swissphoto) + Contact: yesidpol.3@gmail.com + +License: + 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 __future__ import annotations from qgis.PyQt.QtCore import QSettings diff --git a/modelbaker/db_factory/mssql_factory.py b/modelbaker/db_factory/mssql_factory.py index 72a86eba..5dc0a61a 100644 --- a/modelbaker/db_factory/mssql_factory.py +++ b/modelbaker/db_factory/mssql_factory.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 10/05/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-05-10 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 __future__ import annotations from typing import Optional diff --git a/modelbaker/db_factory/mssql_layer_uri.py b/modelbaker/db_factory/mssql_layer_uri.py index 61d4a550..f7e58d21 100644 --- a/modelbaker/db_factory/mssql_layer_uri.py +++ b/modelbaker/db_factory/mssql_layer_uri.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 09/05/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania (BSF Swissphoto) - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-05-09 + Copyright: (C) 2019 by Yesid Polania (BSF Swissphoto) + Contact: yesidpol.3@gmail.com + +License: + 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 .layer_uri import LayerUri diff --git a/modelbaker/db_factory/pg_command_config_manager.py b/modelbaker/db_factory/pg_command_config_manager.py index 04b74d03..edae2123 100644 --- a/modelbaker/db_factory/pg_command_config_manager.py +++ b/modelbaker/db_factory/pg_command_config_manager.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 13/05/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-05-13 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 __future__ import annotations from qgis.PyQt.QtCore import QSettings diff --git a/modelbaker/db_factory/pg_factory.py b/modelbaker/db_factory/pg_factory.py index a00071fa..b51538f2 100644 --- a/modelbaker/db_factory/pg_factory.py +++ b/modelbaker/db_factory/pg_factory.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 08/04/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-04-08 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 __future__ import annotations from typing import Optional diff --git a/modelbaker/db_factory/pg_layer_uri.py b/modelbaker/db_factory/pg_layer_uri.py index def97980..bf19c86f 100644 --- a/modelbaker/db_factory/pg_layer_uri.py +++ b/modelbaker/db_factory/pg_layer_uri.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 30/04/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-04-30 + Copyright: (C) 2019 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 .layer_uri import LayerUri diff --git a/modelbaker/dbconnector/config.py b/modelbaker/dbconnector/config.py index 1a0f6dcb..f4e3d041 100644 --- a/modelbaker/dbconnector/config.py +++ b/modelbaker/dbconnector/config.py @@ -1,3 +1,16 @@ +""" +Metadata: + Creation Date: 2025-11-18 + Copyright: (C) 2025 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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. +""" + IGNORED_SCHEMAS = ["pg_catalog", "information_schema", "pg_*"] IGNORED_TABLES = [ diff --git a/modelbaker/dbconnector/db_connector.py b/modelbaker/dbconnector/db_connector.py index ed5f2867..b0655adb 100644 --- a/modelbaker/dbconnector/db_connector.py +++ b/modelbaker/dbconnector/db_connector.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 04/10/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-10-04 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 fnmatch from qgis.PyQt.QtCore import QObject, pyqtSignal @@ -455,10 +451,12 @@ def get_translation_models(self) -> list[str]: Returns a list of models that are a TRANSLATION OF another model. """ return [] - - def get_available_languages(self, irrelevant_models: list[str], relevant_models: list[str]) -> list[str]: + + def get_available_languages( + self, irrelevant_models: list[str], relevant_models: list[str] + ) -> list[str]: """ - Returns a list of available languages in the t_ili2db_nls table and ignores the values for the irrelevant models. + Returns a list of available languages in the t_ili2db_nls table and ignores the values for the irrelevant models. If a list for relevant models is passed, only those are considered (otherwise all the others) """ return [] diff --git a/modelbaker/dbconnector/gpkg_connector.py b/modelbaker/dbconnector/gpkg_connector.py index 520864d7..f4a82167 100644 --- a/modelbaker/dbconnector/gpkg_connector.py +++ b/modelbaker/dbconnector/gpkg_connector.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 04/10/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-10-04 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 errno import os import re @@ -1271,7 +1267,7 @@ def get_translation_models(self): SELECT DISTINCT ilielement FROM "{t_ili2db_meta_attrs}" - WHERE + WHERE attr_name = 'ili2db.ili.translationOf' ; """.format( @@ -1286,7 +1282,7 @@ def get_available_languages(self, irrelevant_models=[], relevant_models=[]): if not self._table_exists(GPKG_METAATTRS_TABLE): return [] - white_list_restriction = '' + white_list_restriction = "" if len(relevant_models) > 0: white_list_restriction = """ AND @@ -1296,7 +1292,7 @@ def get_available_languages(self, irrelevant_models=[], relevant_models=[]): [f"'{modelname}'" for modelname in relevant_models] ), ) - black_list_restriction = '' + black_list_restriction = "" if len(irrelevant_models) > 0: black_list_restriction = """ AND @@ -1311,7 +1307,7 @@ def get_available_languages(self, irrelevant_models=[], relevant_models=[]): """SELECT DISTINCT attr_value FROM "{t_ili2db_meta_attrs}" - WHERE + WHERE attr_name = 'ili2db.ili.lang' {black_list_restriction} {white_list_restriction} diff --git a/modelbaker/dbconnector/mssql_connector.py b/modelbaker/dbconnector/mssql_connector.py index a4f15a1c..4a9a9c49 100644 --- a/modelbaker/dbconnector/mssql_connector.py +++ b/modelbaker/dbconnector/mssql_connector.py @@ -1,19 +1,14 @@ """ -/*************************************************************************** - begin : 01/02/19 - git sha : :%H$ - copyright : (C) 2019 by Yesid Polanía (BSF-Swissphoto) - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-02-01 + Copyright: (C) 2019 by Yesid Polanía (BSF-Swissphoto) + Contact: yesidpol.3@gmail.com + +License: + 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 numbers @@ -1268,7 +1263,7 @@ def get_translation_models(self): SELECT DISTINCT ilielement FROM {schema}.t_ili2db_meta_attrs - WHERE + WHERE attr_name = 'ili2db.ili.translationOf' """ ).format( @@ -1280,7 +1275,7 @@ def get_translation_models(self): def get_available_languages(self, irrelevant_models=[], relevant_models=[]): if self.schema and self._table_exists(METAATTRS_TABLE): - white_list_restriction = '' + white_list_restriction = "" if len(relevant_models) > 0: white_list_restriction = """ AND @@ -1290,7 +1285,7 @@ def get_available_languages(self, irrelevant_models=[], relevant_models=[]): [f"'{modelname}'" for modelname in relevant_models] ), ) - black_list_restriction = '' + black_list_restriction = "" if len(irrelevant_models) > 0: black_list_restriction = """ AND diff --git a/modelbaker/dbconnector/pg_connector.py b/modelbaker/dbconnector/pg_connector.py index 3b564c50..3fb3d2d5 100644 --- a/modelbaker/dbconnector/pg_connector.py +++ b/modelbaker/dbconnector/pg_connector.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - begin : 04/10/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - (C) 2016 by OPENGIS.ch - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-10-04 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 logging import re @@ -1406,7 +1401,7 @@ def get_translation_models(self): SELECT DISTINCT ilielement FROM {schema}.t_ili2db_meta_attrs - WHERE + WHERE attr_name = 'ili2db.ili.translationOf' """ ).format( @@ -1416,13 +1411,13 @@ def get_translation_models(self): return [row["ilielement"] for row in cur.fetchall()] return [] - def get_available_languages(self, irrelevant_models=[], relevant_models=[]): if self.schema and self._table_exists(PG_METAATTRS_TABLE): - - white_list_placeholders = sql.SQL('') + + white_list_placeholders = sql.SQL("") if len(relevant_models) > 0: - white_list_placeholders = sql.SQL(""" + white_list_placeholders = sql.SQL( + """ AND ilielement IN ({relevant_model_list}) """ @@ -1431,9 +1426,10 @@ def get_available_languages(self, irrelevant_models=[], relevant_models=[]): sql.Placeholder() * len(relevant_models) ), ) - black_list_placeholders = sql.SQL('') + black_list_placeholders = sql.SQL("") if len(irrelevant_models) > 0: - black_list_placeholders = sql.SQL(""" + black_list_placeholders = sql.SQL( + """ AND ilielement NOT IN ({irrelevant_model_list}) """ @@ -1460,7 +1456,7 @@ def get_available_languages(self, irrelevant_models=[], relevant_models=[]): white_list_placeholders=white_list_placeholders, black_list_placeholders=black_list_placeholders, ), - relevant_models+irrelevant_models + relevant_models + irrelevant_models, ) return [row["attr_value"] for row in cur.fetchall()] return [] diff --git a/modelbaker/generator/domain_relations_generator.py b/modelbaker/generator/domain_relations_generator.py index 6513350b..c9c78ceb 100644 --- a/modelbaker/generator/domain_relations_generator.py +++ b/modelbaker/generator/domain_relations_generator.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - begin : 04/10/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - (C) 2016 by OPENGIS.ch - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-10-04 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 re from ..dataobjects.relations import Relation diff --git a/modelbaker/generator/generator.py b/modelbaker/generator/generator.py index e66253fe..7f828aa8 100644 --- a/modelbaker/generator/generator.py +++ b/modelbaker/generator/generator.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - begin : 04/10/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - (C) 2016 by OPENGIS.ch - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-10-04 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 __future__ import annotations import re diff --git a/modelbaker/ilitoppingmaker/__init__.py b/modelbaker/ilitoppingmaker/__init__.py index 9e693e6b..2e8535f1 100644 --- a/modelbaker/ilitoppingmaker/__init__.py +++ b/modelbaker/ilitoppingmaker/__init__.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 2022-07-17 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer - email : david at opengis ch - ***************************************************************************/ +Metadata: + Creation Date: 2017-07-22 + Copyright: (C) 2022 by Dave Signer + Contact: david@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. * - * * - ***************************************************************************/ +License: + 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 ..libs.toppingmaker import ExportSettings from .ili2dbsettings import Ili2dbSettings from .ilidata import IliData diff --git a/modelbaker/ilitoppingmaker/ili2dbsettings.py b/modelbaker/ilitoppingmaker/ili2dbsettings.py index e34221fc..5131aab5 100644 --- a/modelbaker/ilitoppingmaker/ili2dbsettings.py +++ b/modelbaker/ilitoppingmaker/ili2dbsettings.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 2022-07-17 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-07-22 + Copyright: (C) 2022 by Dave Signer + Contact: david@opengis.ch + +License: + 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 from pathlib import Path diff --git a/modelbaker/ilitoppingmaker/ilidata.py b/modelbaker/ilitoppingmaker/ilidata.py index b4bbcd5d..0b7b0ba7 100644 --- a/modelbaker/ilitoppingmaker/ilidata.py +++ b/modelbaker/ilitoppingmaker/ilidata.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 2022-07-17 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-07-22 + Copyright: (C) 2022 by Dave Signer + Contact: david@opengis.ch + +License: + 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 mimetypes import os import uuid diff --git a/modelbaker/ilitoppingmaker/iliprojecttopping.py b/modelbaker/ilitoppingmaker/iliprojecttopping.py index 286c1671..4c49b3d1 100644 --- a/modelbaker/ilitoppingmaker/iliprojecttopping.py +++ b/modelbaker/ilitoppingmaker/iliprojecttopping.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 2022-07-17 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-07-22 + Copyright: (C) 2022 by Dave Signer + Contact: david@opengis.ch + +License: + 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. """ diff --git a/modelbaker/ilitoppingmaker/ilitarget.py b/modelbaker/ilitoppingmaker/ilitarget.py index 51bac2c6..97236be9 100644 --- a/modelbaker/ilitoppingmaker/ilitarget.py +++ b/modelbaker/ilitoppingmaker/ilitarget.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 2022-07-17 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer - email : david at opengis ch - ***************************************************************************/ +Metadata: + Creation Date: 2017-07-22 + Copyright: (C) 2022 by Dave Signer + Contact: david@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. * - * * - ***************************************************************************/ +License: + 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 datetime import os import pathlib diff --git a/modelbaker/ilitoppingmaker/metaconfig.py b/modelbaker/ilitoppingmaker/metaconfig.py index dfae78de..67bdd0d0 100644 --- a/modelbaker/ilitoppingmaker/metaconfig.py +++ b/modelbaker/ilitoppingmaker/metaconfig.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 2022-07-17 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-07-22 + Copyright: (C) 2022 by Dave Signer + Contact: david@opengis.ch + +License: + 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 os from typing import Union diff --git a/modelbaker/iliwrapper/globals.py b/modelbaker/iliwrapper/globals.py index 80e11011..b9335125 100644 --- a/modelbaker/iliwrapper/globals.py +++ b/modelbaker/iliwrapper/globals.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 3.10.2017 - git sha : :%H$ - copyright : (C) 2017 by Matthias Kuhn - email : matthias@opengis.ch - ***************************************************************************/ +Metadata: + Creation Date: 2017-10-03 + Copyright: (C) 2017 by Matthias Kuhn + Contact: matthias@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. * - * * - ***************************************************************************/ +License: + 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 enum import IntFlag diff --git a/modelbaker/iliwrapper/ili2dbargs.py b/modelbaker/iliwrapper/ili2dbargs.py index eb23b98d..bc99bc26 100644 --- a/modelbaker/iliwrapper/ili2dbargs.py +++ b/modelbaker/iliwrapper/ili2dbargs.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 07.03.2022 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer / (C) 2021 Germán Carrillo - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2022-03-07 + Copyright: (C) 2022 by Dave Signer / (C) 2021 Germán Carrillo + Contact: david@opengis.ch + +License: + 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 logging diff --git a/modelbaker/iliwrapper/ili2dbconfig.py b/modelbaker/iliwrapper/ili2dbconfig.py index 487d832f..92227b09 100644 --- a/modelbaker/iliwrapper/ili2dbconfig.py +++ b/modelbaker/iliwrapper/ili2dbconfig.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 23/03/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-03-23 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 qgis.core import QgsNetworkAccessManager diff --git a/modelbaker/iliwrapper/ili2dbtools.py b/modelbaker/iliwrapper/ili2dbtools.py index 2d247545..f792e677 100644 --- a/modelbaker/iliwrapper/ili2dbtools.py +++ b/modelbaker/iliwrapper/ili2dbtools.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 07.03.2022 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer / (C) 2021 Germán Carrillo - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2022-03-07 + Copyright: (C) 2022 by Dave Signer / (C) 2021 Germán Carrillo + Contact: david@opengis.ch + +License: + 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 .globals import DbIliMode diff --git a/modelbaker/iliwrapper/ili2dbutils.py b/modelbaker/iliwrapper/ili2dbutils.py index de58d724..d87e94ba 100644 --- a/modelbaker/iliwrapper/ili2dbutils.py +++ b/modelbaker/iliwrapper/ili2dbutils.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 14.9.17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-09-14 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 glob import os diff --git a/modelbaker/iliwrapper/ilicache.py b/modelbaker/iliwrapper/ilicache.py index 37856a15..ec6a2b05 100644 --- a/modelbaker/iliwrapper/ilicache.py +++ b/modelbaker/iliwrapper/ilicache.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 15/06/17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-06-15 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 glob import logging diff --git a/modelbaker/iliwrapper/ilideleter.py b/modelbaker/iliwrapper/ilideleter.py index 1f10bfa3..7a24dbd6 100644 --- a/modelbaker/iliwrapper/ilideleter.py +++ b/modelbaker/iliwrapper/ilideleter.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 27/09/24 - git sha : :%H$ - copyright : (C) 2024 by Germán Carrillo - email : german@opengis.ch - ***************************************************************************/ +Metadata: + Creation Date: 2024-09-27 + Copyright: (C) 2024 by Germán Carrillo + Contact: 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. * - * * - ***************************************************************************/ +License: + 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 DeleteConfiguration, Ili2DbCommandConfiguration from .iliexecutable import IliExecutable diff --git a/modelbaker/iliwrapper/iliexecutable.py b/modelbaker/iliwrapper/iliexecutable.py index 0839dc55..74485146 100644 --- a/modelbaker/iliwrapper/iliexecutable.py +++ b/modelbaker/iliwrapper/iliexecutable.py @@ -1,19 +1,14 @@ """ -/*************************************************************************** - begin : 09/09/23 - git sha : :%H$ - copyright : (C) 2020 by Yesid Polania - email : yesidpol.3@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2023-09-09 + Copyright: (C) 2020 by Yesid Polania + Contact: yesidpol.3@gmail.com + +License: + 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 functools import locale diff --git a/modelbaker/iliwrapper/iliexporter.py b/modelbaker/iliwrapper/iliexporter.py index 87677b86..23bfc314 100644 --- a/modelbaker/iliwrapper/iliexporter.py +++ b/modelbaker/iliwrapper/iliexporter.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 30/05/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-05-30 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 ExportConfiguration, Ili2DbCommandConfiguration from .iliexecutable import IliExecutable diff --git a/modelbaker/iliwrapper/iliimporter.py b/modelbaker/iliwrapper/iliimporter.py index 3ed2849f..6c46a92b 100644 --- a/modelbaker/iliwrapper/iliimporter.py +++ b/modelbaker/iliwrapper/iliimporter.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 23/03/17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@opengis.ch - ***************************************************************************/ +Metadata: + Creation Date: 2017-03-23 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@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. * - * * - ***************************************************************************/ +License: + 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 ( Ili2DbCommandConfiguration, diff --git a/modelbaker/iliwrapper/ilimetaconfigexporter.py b/modelbaker/iliwrapper/ilimetaconfigexporter.py index 25dba561..4d6979b1 100644 --- a/modelbaker/iliwrapper/ilimetaconfigexporter.py +++ b/modelbaker/iliwrapper/ilimetaconfigexporter.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 20/11/24 - git sha : :%H$ - copyright : (C) 2024 by Germán Carrillo - email : german@opengis.ch - ***************************************************************************/ +Metadata: + Creation Date: 2024-11-20 + Copyright: (C) 2024 by Germán Carrillo + Contact: 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. * - * * - ***************************************************************************/ +License: + 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 diff --git a/modelbaker/iliwrapper/iliupdater.py b/modelbaker/iliwrapper/iliupdater.py index e6eea181..ebd9a8d0 100644 --- a/modelbaker/iliwrapper/iliupdater.py +++ b/modelbaker/iliwrapper/iliupdater.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 23/03/17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@opengis.ch - ***************************************************************************/ +Metadata: + Creation Date: 2017-03-23 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@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. * - * * - ***************************************************************************/ +License: + 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. """ diff --git a/modelbaker/iliwrapper/ilivalidator.py b/modelbaker/iliwrapper/ilivalidator.py index 94781a57..c65b887a 100644 --- a/modelbaker/iliwrapper/ilivalidator.py +++ b/modelbaker/iliwrapper/ilivalidator.py @@ -1,20 +1,14 @@ """ -/*************************************************************************** - ------------------- - begin : 11/11/21 - git sha : :%H$ - copyright : (C) 2021 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2021-11-11 + Copyright: (C) 2021 by Dave Signer + Contact: david@opengis.ch + +License: + 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 xml.etree.ElementTree as CET diff --git a/modelbaker/processing/ili2db_exporting.py b/modelbaker/processing/ili2db_exporting.py index 5ef17d33..84aaf550 100644 --- a/modelbaker/processing/ili2db_exporting.py +++ b/modelbaker/processing/ili2db_exporting.py @@ -1,12 +1,14 @@ """ -*************************************************************************** -* * -* 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. * -* * -*************************************************************************** +Metadata: + Creation Date: 2025-10-10 + Copyright: (C) 2025 by Dave Signer + Contact: david@opengis.ch + +License: + 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 typing import Any, Optional diff --git a/modelbaker/processing/ili2db_importing.py b/modelbaker/processing/ili2db_importing.py index 4af48826..bb50ffdc 100644 --- a/modelbaker/processing/ili2db_importing.py +++ b/modelbaker/processing/ili2db_importing.py @@ -1,12 +1,14 @@ """ -*************************************************************************** -* * -* 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. * -* * -*************************************************************************** +Metadata: + Creation Date: 2025-10-10 + Copyright: (C) 2025 by Dave Signer + Contact: david@opengis.ch + +License: + 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 typing import Any, Optional diff --git a/modelbaker/processing/ili2db_operating.py b/modelbaker/processing/ili2db_operating.py index bb1ec0a4..c2254fca 100644 --- a/modelbaker/processing/ili2db_operating.py +++ b/modelbaker/processing/ili2db_operating.py @@ -1,15 +1,16 @@ """ -*************************************************************************** -* * -* 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. * -* * -*************************************************************************** +Metadata: + Creation Date: 2025-10-10 + Copyright: (C) 2025 by Dave Signer + Contact: david@opengis.ch + +License: + 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 qgis.PyQt.QtCore import QCoreApplication, QObject from ..utils.db_utils import get_db_connector diff --git a/modelbaker/processing/ili2db_validating.py b/modelbaker/processing/ili2db_validating.py index 2977547e..ba24b07f 100644 --- a/modelbaker/processing/ili2db_validating.py +++ b/modelbaker/processing/ili2db_validating.py @@ -1,12 +1,14 @@ """ -*************************************************************************** -* * -* 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. * -* * -*************************************************************************** +Metadata: + Creation Date: 2025-10-10 + Copyright: (C) 2025 by Dave Signer + Contact: david@opengis.ch + +License: + 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 os diff --git a/modelbaker/processing/util_layersourceparsing.py b/modelbaker/processing/util_layersourceparsing.py index 25790843..339b6e76 100644 --- a/modelbaker/processing/util_layersourceparsing.py +++ b/modelbaker/processing/util_layersourceparsing.py @@ -1,12 +1,14 @@ """ -*************************************************************************** -* * -* 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. * -* * -*************************************************************************** +Metadata: + Creation Date: 2025-10-10 + Copyright: (C) 2025 by Dave Signer + Contact: david@opengis.ch + +License: + 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 typing import Any, Optional diff --git a/modelbaker/utils/db_utils.py b/modelbaker/utils/db_utils.py index 871b92ac..9f1cc99f 100644 --- a/modelbaker/utils/db_utils.py +++ b/modelbaker/utils/db_utils.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - begin : 18.08.2021 - git sha : :%H$ - copyright : (C) 2021 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2021-08-18 + Copyright: (C) 2021 by Dave Signer + Contact: david@opengis.ch + +License: + 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 qgis.core import ( QgsApplication, QgsAuthMethodConfig, diff --git a/modelbaker/utils/globals.py b/modelbaker/utils/globals.py index ffcf8d33..393504c9 100644 --- a/modelbaker/utils/globals.py +++ b/modelbaker/utils/globals.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 07.03.2022 - git sha : :%H$ - copyright : (C) 2022 by Matthias Kuhn - email : david@opengis.ch - ***************************************************************************/ +Metadata: + Creation Date: 2022-03-07 + Copyright: (C) 2022 by Matthias Kuhn + Contact: david@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. * - * * - ***************************************************************************/ +License: + 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 enum import Enum, IntEnum MODELS_BLACKLIST = [ diff --git a/modelbaker/utils/ili2db_utils.py b/modelbaker/utils/ili2db_utils.py index bcc5bb01..6bc56fbd 100644 --- a/modelbaker/utils/ili2db_utils.py +++ b/modelbaker/utils/ili2db_utils.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 27.09.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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2024-09-27 + Copyright: (C) 2024 by Germán Carrillo + Contact: german@opengisch + +License: + 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 qgis.PyQt.QtCore import QObject, Qt, pyqtSignal from ..iliwrapper import ilideleter, ilimetaconfigexporter diff --git a/modelbaker/utils/qgis_utils.py b/modelbaker/utils/qgis_utils.py index 93753827..1bce5f21 100644 --- a/modelbaker/utils/qgis_utils.py +++ b/modelbaker/utils/qgis_utils.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - begin : 05/03/18 - git sha : :%H$ - copyright : (C) 2018 by Germán Carrillo (BSF-Swissphoto) - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2018-03-05 + Copyright: (C) 2018 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 qgis.core import ( Qgis, QgsAttributeEditorContainer, diff --git a/modelbaker/utils/qt_utils.py b/modelbaker/utils/qt_utils.py index f1761310..ead40fb3 100644 --- a/modelbaker/utils/qt_utils.py +++ b/modelbaker/utils/qt_utils.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 2016 - copyright : (C) 2016 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Copyright: (C) 2016 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 functools import re import unicodedata diff --git a/tests/test_dataset_handling.py b/tests/test_dataset_handling.py index 505fec0d..b02f024b 100644 --- a/tests/test_dataset_handling.py +++ b/tests/test_dataset_handling.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 10.08.2021 - git sha : :%H$ - copyright : (C) 2021 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2021-08-10 + Copyright: (C) 2021 by Dave Signer + Contact: david@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_delete.py b/tests/test_delete.py index db436734..fa097fd4 100644 --- a/tests/test_delete.py +++ b/tests/test_delete.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 27.09.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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2024-09-27 + Copyright: (C) 2024 by Germán Carrillo + Contact: german@opengisch + +License: + 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 datetime import logging import os diff --git a/tests/test_domain_class_relations.py b/tests/test_domain_class_relations.py index dbed0300..3099a6f9 100644 --- a/tests/test_domain_class_relations.py +++ b/tests/test_domain_class_relations.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - begin : 10/10/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-10-10 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 datetime import logging import os diff --git a/tests/test_dump.py b/tests/test_dump.py index 7a2e9f02..058bac2a 100644 --- a/tests/test_dump.py +++ b/tests/test_dump.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - begin : 24.5.2018 - git sha : :%H$ - copyright : (C) 2018 Matthias Kuhn - email : matthias@opengis.ch - ***************************************************************************/ +Metadata: + Creation Date: 2018-05-24 + Copyright: (C) 2018 Matthias Kuhn + Contact: matthias@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. * - * * - ***************************************************************************/ +License: + 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 os from subprocess import call diff --git a/tests/test_export.py b/tests/test_export.py index 47951b5f..502aba43 100644 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - begin : 25/09/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-09-25 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 datetime import logging import os diff --git a/tests/test_exportmetaconfig.py b/tests/test_exportmetaconfig.py index f0ee41f5..06e45453 100644 --- a/tests/test_exportmetaconfig.py +++ b/tests/test_exportmetaconfig.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2024-11-20 + Copyright: (C) 2024 by Germán Carrillo + Contact: german@opengisch + +License: + 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 diff --git a/tests/test_gpkg_pk.py b/tests/test_gpkg_pk.py index 30ff5e83..883bff22 100644 --- a/tests/test_gpkg_pk.py +++ b/tests/test_gpkg_pk.py @@ -1,20 +1,16 @@ """ -/*************************************************************************** - begin : 11.01.2019 - git sha : :%H$ - copyright : (C) 2019 Matthias Kuhn - email : matthias@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2019-01-11 + Copyright: (C) 2019 Matthias Kuhn + Contact: matthias@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_ili2dbcommandconfiguration.py b/tests/test_ili2dbcommandconfiguration.py index e5befd6e..a3d23529 100644 --- a/tests/test_ili2dbcommandconfiguration.py +++ b/tests/test_ili2dbcommandconfiguration.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 27.09.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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2024-09-27 + Copyright: (C) 2024 by Germán Carrillo + Contact: german@opengisch + +License: + 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 qgis.testing import start_app, unittest from modelbaker.iliwrapper.ili2dbconfig import ( diff --git a/tests/test_ilitoppingmaker.py b/tests/test_ilitoppingmaker.py index c9b54664..06448564 100644 --- a/tests/test_ilitoppingmaker.py +++ b/tests/test_ilitoppingmaker.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 2022-07-17 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-07-22 + Copyright: (C) 2022 by Dave Signer + Contact: david@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_import.py b/tests/test_import.py index fa3e8e69..9fd7d30d 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - begin : 25/09/17 - git sha : :%H$ - copyright : (C) 2017 by Germán Carrillo (BSF-Swissphoto) - email : gcarrillo@linuxmail.org - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-09-25 + Copyright: (C) 2017 by Germán Carrillo (BSF-Swissphoto) + Contact: gcarrillo@linuxmail.org + +License: + 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 datetime import logging import os diff --git a/tests/test_import_dbparams.py b/tests/test_import_dbparams.py index 269297c1..26e59835 100644 --- a/tests/test_import_dbparams.py +++ b/tests/test_import_dbparams.py @@ -1,22 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 06/27/2025 - git sha : :%H$ - copyright : (C) 2025 by Dave Signer @ OPENGIS.ch - email : david@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. * - * * - ***************************************************************************/ +Metadata: + Copyright: (C) 2025 by Dave Signer @ OPENGIS.ch + Contact: david@opengis.ch + +License: + 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 datetime import logging import pathlib diff --git a/tests/test_metaconfig.py b/tests/test_metaconfig.py index e551b09e..e0b1753d 100644 --- a/tests/test_metaconfig.py +++ b/tests/test_metaconfig.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 09/08/17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-08-09 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 diff --git a/tests/test_multiple_geom_gpkg.py b/tests/test_multiple_geom_gpkg.py index a31593b9..d2eef07e 100644 --- a/tests/test_multiple_geom_gpkg.py +++ b/tests/test_multiple_geom_gpkg.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 28.10.2024 - git sha : :%H$ - copyright : (C) 2024 by Dave Signer - email : david@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2024-10-28 + Copyright: (C) 2024 by Dave Signer + Contact: david@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_pgservice.py b/tests/test_pgservice.py index 0f560c79..9618252f 100644 --- a/tests/test_pgservice.py +++ b/tests/test_pgservice.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - begin : 24/06/2022 - git sha : :%H$ - copyright : (C) 2022 by Dave Signer (took base from) Damiano Lombardi - email : david@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2022-06-24 + Copyright: (C) 2022 by Dave Signer (took base from) Damiano Lombardi + Contact: david@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 4fbb8afc..c235aa33 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1,18 +1,12 @@ """ -/*************************************************************************** - ------------------- - begin : 09/08/17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@opengis.ch - ***************************************************************************/ +Metadata: + Creation Date: 2017-08-09 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@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. * - * * - ***************************************************************************/ +License: + 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. """ diff --git a/tests/test_processing.py b/tests/test_processing.py index 3461f0c3..0fb12853 100644 --- a/tests/test_processing.py +++ b/tests/test_processing.py @@ -1,19 +1,14 @@ """ -/*************************************************************************** - begin : 27/09/2025 - git sha : :%H$ - copyright : (C) 2025 by Dave Signer - email : david@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2025-10-10 + Copyright: (C) 2025 by Dave Signer + Contact: david@opengis.ch + +License: + 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 datetime diff --git a/tests/test_projectgen.py b/tests/test_projectgen.py index d1987985..f07bb7b6 100644 --- a/tests/test_projectgen.py +++ b/tests/test_projectgen.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 09/08/17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-08-09 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 diff --git a/tests/test_projectgen_extension_optimization_smart1.py b/tests/test_projectgen_extension_optimization_smart1.py index f723e5e5..b533c6aa 100644 --- a/tests/test_projectgen_extension_optimization_smart1.py +++ b/tests/test_projectgen_extension_optimization_smart1.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 14.08.2023 - git sha : :%H$ - copyright : (C) 2023 by Dave Signer - email : david@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2023-08-14 + Copyright: (C) 2023 by Dave Signer + Contact: david@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_projectgen_extension_optimization_smart2.py b/tests/test_projectgen_extension_optimization_smart2.py index e754a27b..1a9e754a 100644 --- a/tests/test_projectgen_extension_optimization_smart2.py +++ b/tests/test_projectgen_extension_optimization_smart2.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 14.08.2023 - git sha : :%H$ - copyright : (C) 2023 by Dave Signer - email : david@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2023-08-14 + Copyright: (C) 2023 by Dave Signer + Contact: david@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_projectgen_generic_databases.py b/tests/test_projectgen_generic_databases.py index 4b8262fa..60c8b0da 100644 --- a/tests/test_projectgen_generic_databases.py +++ b/tests/test_projectgen_generic_databases.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 28/03/18 - git sha : :%H$ - copyright : (C) 2018 by Jorge Useche - email : naturalmentejorge@gmail.com - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2018-03-28 + Copyright: (C) 2018 by Jorge Useche + Contact: naturalmentejorge@gmail.com + +License: + 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 os import shutil import tempfile diff --git a/tests/test_projectgen_oids.py b/tests/test_projectgen_oids.py index 7db687a9..674713b9 100644 --- a/tests/test_projectgen_oids.py +++ b/tests/test_projectgen_oids.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 03.11.2023 - git sha : :%H$ - copyright : (C) 2023 by Dave Signer - email : david@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2023-11-03 + Copyright: (C) 2023 by Dave Signer + Contact: david@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_projecttopping.py b/tests/test_projecttopping.py index 290d0393..7a5c3d1a 100644 --- a/tests/test_projecttopping.py +++ b/tests/test_projecttopping.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 09/08/17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-08-09 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_sequence_reset.py b/tests/test_sequence_reset.py index df77c299..70447bb9 100644 --- a/tests/test_sequence_reset.py +++ b/tests/test_sequence_reset.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 10.11.2023 - git sha : :%H$ - copyright : (C) 2023 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2023-11-10 + Copyright: (C) 2023 by Dave Signer + Contact: david@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_translations.py b/tests/test_translations.py index d5e69be0..35846ee9 100644 --- a/tests/test_translations.py +++ b/tests/test_translations.py @@ -1,22 +1,17 @@ """ -/*************************************************************************** - ------------------- - begin : 31.10.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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2024-10-31 + Copyright: (C) 2024 by Germán Carrillo + Contact: german@opengisch + +License: + 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 datetime import logging import os @@ -52,9 +47,8 @@ def test_translated_db_objects_gpkg(self): importer.configuration = iliimporter_config(importer.tool) importer.configuration.ilimodels = "PlansDAffectation_V1_2" importer.configuration.dbfile = os.path.join( - self.basetestpath, "tmp_translated_{:%Y%m%d%H%M%S%f}.gpkg".format( - datetime.datetime.now() - ), + self.basetestpath, + "tmp_translated_{:%Y%m%d%H%M%S%f}.gpkg".format(datetime.datetime.now()), ) importer.configuration.inheritance = "smart2" importer.configuration.create_basket_col = True @@ -239,9 +233,8 @@ def test_translated_available_langs_gpkg(self): importer.configuration = iliimporter_config(importer.tool) importer.configuration.ilimodels = "PlansDAffectation_V1_2" importer.configuration.dbfile = os.path.join( - self.basetestpath, "tmp_translated_{:%Y%m%d%H%M%S%f}.gpkg".format( - datetime.datetime.now() - ), + self.basetestpath, + "tmp_translated_{:%Y%m%d%H%M%S%f}.gpkg".format(datetime.datetime.now()), ) importer.configuration.inheritance = "smart2" importer.configuration.create_basket_col = True @@ -254,24 +247,35 @@ def test_translated_available_langs_gpkg(self): # Translation handling is active assert db_connector.get_translation_handling() - # Get the translated models + # Get the translated models assert {"PlansDAffectation_V1_2"} == set(db_connector.get_translation_models()) # Get all languages - assert {'en','de','fr'} == set(db_connector.get_available_languages()) + assert {"en", "de", "fr"} == set(db_connector.get_available_languages()) - # ... without irrelevant models - irrelevants = ["AdministrativeUnits_V1","AdministrativeUnitsCH_V1","Dictionaries_V1","DictionariesCH_V1"] - assert {'de','fr'} == set(db_connector.get_available_languages(irrelevants)) + # ... without irrelevant models + irrelevants = [ + "AdministrativeUnits_V1", + "AdministrativeUnitsCH_V1", + "Dictionaries_V1", + "DictionariesCH_V1", + ] + assert {"de", "fr"} == set(db_connector.get_available_languages(irrelevants)) # ... and the language of the translated model only - assert {'fr'} == set(db_connector.get_available_languages([],["PlansDAffectation_V1_2"])) + assert {"fr"} == set( + db_connector.get_available_languages([], ["PlansDAffectation_V1_2"]) + ) # --- and nonsense use case for the validation, get only of an english model - assert {'en'} == set(db_connector.get_available_languages([],["AdministrativeUnits_V1"])) + assert {"en"} == set( + db_connector.get_available_languages([], ["AdministrativeUnits_V1"]) + ) # ... as well as ignoring the translated models and alowing it again and the english one - assert {'de','en'} == set(db_connector.get_available_languages(["PlansDAffectation_V1_2"])) + assert {"de", "en"} == set( + db_connector.get_available_languages(["PlansDAffectation_V1_2"]) + ) def test_translated_available_langs_pg(self): importer = iliimporter.Importer() @@ -292,24 +296,35 @@ def test_translated_available_langs_pg(self): # Translation handling is active assert db_connector.get_translation_handling() - # Get the translated models + # Get the translated models assert {"PlansDAffectation_V1_2"} == set(db_connector.get_translation_models()) # Get all languages - assert {'en','de','fr'} == set(db_connector.get_available_languages()) + assert {"en", "de", "fr"} == set(db_connector.get_available_languages()) - # ... without irrelevant models - irrelevants = ["AdministrativeUnits_V1","AdministrativeUnitsCH_V1","Dictionaries_V1","DictionariesCH_V1"] - assert {'de','fr'} == set(db_connector.get_available_languages(irrelevants)) + # ... without irrelevant models + irrelevants = [ + "AdministrativeUnits_V1", + "AdministrativeUnitsCH_V1", + "Dictionaries_V1", + "DictionariesCH_V1", + ] + assert {"de", "fr"} == set(db_connector.get_available_languages(irrelevants)) # ... and the language of the translated model only - assert {'fr'} == set(db_connector.get_available_languages([],["PlansDAffectation_V1_2"])) + assert {"fr"} == set( + db_connector.get_available_languages([], ["PlansDAffectation_V1_2"]) + ) # --- and nonsense use case for the validation, get only of an english model - assert {'en'} == set(db_connector.get_available_languages([],["AdministrativeUnits_V1"])) - + assert {"en"} == set( + db_connector.get_available_languages([], ["AdministrativeUnits_V1"]) + ) + # ... as well as ignoring the translated models and alowing it again and the english one - assert {'de','en'} == set(db_connector.get_available_languages(["PlansDAffectation_V1_2"])) + assert {"de", "en"} == set( + db_connector.get_available_languages(["PlansDAffectation_V1_2"]) + ) def test_translated_namelang_gpkg(self): # same as translated_db_objects but this time is the schema in French (namelang) and the preferred language German. @@ -318,13 +333,12 @@ def test_translated_namelang_gpkg(self): importer.configuration = iliimporter_config(importer.tool) importer.configuration.ilimodels = "PlansDAffectation_V1_2" importer.configuration.dbfile = os.path.join( - self.basetestpath, "tmp_translated_{:%Y%m%d%H%M%S%f}.gpkg".format( - datetime.datetime.now() - ) + self.basetestpath, + "tmp_translated_{:%Y%m%d%H%M%S%f}.gpkg".format(datetime.datetime.now()), ) importer.configuration.inheritance = "smart2" importer.configuration.create_basket_col = True - importer.configuration.name_lang = 'fr' + importer.configuration.name_lang = "fr" importer.stdout.connect(self.print_info) importer.stderr.connect(self.print_error) assert importer.run() == iliimporter.Importer.SUCCESS @@ -354,7 +368,6 @@ def test_translated_namelang_gpkg(self): project.create(None, qgis_project) count = 0 - fr_layer = None for layer in available_layers: if layer.name == "affectationprimaire_surfacedezones": assert layer.alias == "Grundnutzung_Zonenflaeche" @@ -421,7 +434,7 @@ def test_translated_namelang_pg(self): ) importer.configuration.inheritance = "smart2" importer.configuration.create_basket_col = True - importer.configuration.name_lang = 'fr' + importer.configuration.name_lang = "fr" importer.stdout.connect(self.print_info) importer.stderr.connect(self.print_error) assert importer.run() == iliimporter.Importer.SUCCESS @@ -448,7 +461,6 @@ def test_translated_namelang_pg(self): project.create(None, qgis_project) count = 0 - fr_layer = None for layer in available_layers: if layer.name == "affectationprimaire_surfacedezones": assert layer.alias == "Grundnutzung_Zonenflaeche" @@ -495,10 +507,7 @@ def test_translated_namelang_pg(self): # Check translated relation rels = qgis_project.relationManager().referencedRelations(de_layer) assert len(rels) == 1 - assert ( - rels[0].id() - == "geometrie_document_geomtr_ffcttnrmr_srfcdznes_fkey" - ) + assert rels[0].id() == "geometrie_document_geomtr_ffcttnrmr_srfcdznes_fkey" assert ( rels[0].name() == "Geometrie_Dokument_(Geometrie)_Grundnutzung_Zonenflaeche_(t_id)" diff --git a/tests/test_validate.py b/tests/test_validate.py index cc703fe0..90577742 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - begin : 08.12.2021 - git sha : :%H$ - copyright : (C) 2021 by Dave Signer - email : david 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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2021-12-08 + Copyright: (C) 2021 by Dave Signer + Contact: david@opengis.ch + +License: + 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 datetime import logging import os diff --git a/tests/test_z_geom.py b/tests/test_z_geom.py index b42925fb..3b4de895 100644 --- a/tests/test_z_geom.py +++ b/tests/test_z_geom.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - begin : 12.03.2018 - git sha : :%H$ - copyright : (C) 2018 Matthias Kuhn - email : matthias@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2018-03-12 + Copyright: (C) 2018 Matthias Kuhn + Contact: matthias@opengis.ch + +License: + 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 logging from qgis.core import QgsWkbTypes diff --git a/tests/utils.py b/tests/utils.py index 3e64ae9b..a4f0c3a5 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,21 +1,16 @@ """ -/*************************************************************************** - ------------------- - begin : 24/08/17 - git sha : :%H$ - copyright : (C) 2017 by OPENGIS.ch - email : info@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. * - * * - ***************************************************************************/ +Metadata: + Creation Date: 2017-08-24 + Copyright: (C) 2017 by OPENGIS.ch + Contact: info@opengis.ch + +License: + 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 os from subprocess import call From ade32885501d86ece886c6cf6a1fc44d46ea71e6 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 28 Nov 2025 12:21:01 +0100 Subject: [PATCH 2/3] Converted reSt docstrings to google docstrings - yes, done by AI but checked by real code monkey --- .../db_factory/db_command_config_manager.py | 59 ++++++++--------- modelbaker/db_factory/db_factory.py | 65 +++++++++---------- modelbaker/db_factory/db_simple_factory.py | 27 ++++---- .../db_factory/gpkg_command_config_manager.py | 7 +- modelbaker/db_factory/gpkg_layer_uri.py | 5 +- modelbaker/db_factory/layer_uri.py | 20 +++--- .../db_factory/pg_command_config_manager.py | 7 +- modelbaker/db_factory/pg_layer_uri.py | 5 +- modelbaker/generator/generator.py | 10 +-- modelbaker/iliwrapper/ili2dbargs.py | 9 +-- modelbaker/iliwrapper/ili2dbutils.py | 21 +++--- modelbaker/iliwrapper/iliexecutable.py | 12 ++-- modelbaker/utils/ili2db_utils.py | 33 ++++++---- 13 files changed, 145 insertions(+), 135 deletions(-) diff --git a/modelbaker/db_factory/db_command_config_manager.py b/modelbaker/db_factory/db_command_config_manager.py index 4e0c8db9..81271367 100644 --- a/modelbaker/db_factory/db_command_config_manager.py +++ b/modelbaker/db_factory/db_command_config_manager.py @@ -24,17 +24,16 @@ class DbCommandConfigManager(ABC): """Manages a configuration object to return specific information of some database. This is a abstract class. - Provides database uri, arguments to ili2db and a way to save and load configurations parameters - based on a object configuration. + Provides database uri, arguments to ili2db and a way to save and load configurations parameters + based on a object configuration. - :ivar configuration object that will be managed - """ + configuration object that will be managed""" def __init__(self, configuration: Ili2DbCommandConfiguration) -> None: """ - :param configuration: Configuration object that will be managed. - :type configuration: :class:`Ili2DbCommandConfiguration` - """ + + Args: + configuration (:class:`Ili2DbCommandConfiguration`): Configuration object that will be managed.""" self.configuration = configuration @abstractmethod @@ -43,38 +42,40 @@ def get_uri( ) -> str: """Gets database uri (connection string) for db connectors (:class:`DBConnector`). - :param bool su: *True* to use super user credentials, *False* otherwise. - :param bool qgis: *True* to use qgis specific credentials (e.g. authcfg), *False* otherwise. - :param str fallback_user: a username as fallback most possibly used when you want to pass your os account name to connect the database - :return: Database uri (connection string). - :rtype str - """ + Args: + fallback_user (str): a username as fallback most possibly used when you want to pass your os account name to connect the database + qgis (bool): *True* to use qgis specific credentials (e.g. authcfg), *False* otherwise. + su (bool): *True* to use super user credentials, *False* otherwise. + + Returns: + Database uri (connection string).""" @abstractmethod def get_db_args(self, hide_password: bool = False, su: bool = False) -> list[str]: """Gets a list of ili2db arguments related to database. - :param bool hide_password: *True* to mask the password, *False* otherwise. - :param bool su: *True* to use super user password, *False* otherwise. Default is False. - :return: ili2db arguments list. - :rtype: list - """ + Args: + hide_password (bool): *True* to mask the password, *False* otherwise. + su (bool): *True* to use super user password, *False* otherwise. Default is False. + + Returns: + list: ili2db arguments list.""" def get_schema_import_args(self) -> list[str]: """Gets a list of ili2db arguments to use in operation schema import. - :return: ili2db arguments list. - :rtype: list - """ + Returns: + list: ili2db arguments list.""" return list() def get_ili2db_args(self, hide_password: bool = False) -> list[str]: """Gets a complete list of ili2db arguments in order to execute the app. - :param bool hide_password: *True* to mask the password, *False* otherwise. - :return: ili2db arguments list. - :rtype: list - """ + Args: + hide_password (bool): *True* to mask the password, *False* otherwise. + + Returns: + list: ili2db arguments list.""" db_args = self.get_db_args(hide_password, self.configuration.db_use_super_login) if type(self.configuration) is SchemaImportConfiguration: @@ -88,12 +89,12 @@ def get_ili2db_args(self, hide_password: bool = False) -> list[str]: def save_config_in_qsettings(self) -> None: """Saves configuration values related to database in QSettings. - :return: None - """ + Returns: + None""" @abstractmethod def load_config_from_qsettings(self) -> None: """Loads configuration values related to database from Qsettings. - :return: None - """ + Returns: + None""" diff --git a/modelbaker/db_factory/db_factory.py b/modelbaker/db_factory/db_factory.py index 3325a7c8..ecf6ae2e 100644 --- a/modelbaker/db_factory/db_factory.py +++ b/modelbaker/db_factory/db_factory.py @@ -30,12 +30,12 @@ class DbFactory(ABC): def get_db_connector(self, uri: str, schema: Optional[str]) -> DBConnector: """Returns an instance of connector to database (:class:`DBConnector`). - :param str uri: Database connection string. - :param str schema: Database schema. - :return: A connector to specific database. - :rtype: :class:`DBConnector` - :raises :class:`DBConnectorError`: when the connection fails. - """ + Args: + schema (str): Database schema. + uri (str): Database connection string. + + Returns: + :class:`DBConnector`: A connector to specific database.""" @abstractmethod def get_db_command_config_manager( @@ -43,20 +43,21 @@ def get_db_command_config_manager( ) -> DbCommandConfigManager: """Returns an instance of a database command config manager. - :param configuration: Configuration object that will be managed. - :type configuration: :class:`Ili2DbCommandConfiguration` - :return: Object that manages a configuration object to return specific information of some database. - :rtype :class:`DbCommandConfigManager` - """ + Args: + configuration (:class:`Ili2DbCommandConfiguration`): Configuration object that will be managed. + + Returns: + Object that manages a configuration object to return specific information of some database.""" @abstractmethod def get_layer_uri(self, uri: str) -> LayerUri: """Returns an instance of a layer uri. - :param str uri: Database connection string. - :return: A object that provides layer uri. - :rtype :class:`LayerUri` - """ + Args: + uri (str): Database connection string. + + Returns: + A object that provides layer uri.""" @abstractmethod def pre_generate_project( @@ -64,10 +65,11 @@ def pre_generate_project( ) -> tuple[bool, str]: """This method will be called before an operation of generate project is executed. - :param configuration: Configuration parameters with which will be executed the operation of generate project. - :type configuration: :class:`Ili2DbCommandConfiguration` - :return: *True* and an empty message if the called method was succeeded, *False* and a warning message otherwise. - """ + Args: + configuration (:class:`Ili2DbCommandConfiguration`): Configuration parameters with which will be executed the operation of generate project. + + Returns: + *True* and an empty message if the called method was succeeded, *False* and a warning message otherwise.""" @abstractmethod def post_generate_project_validations( @@ -75,16 +77,15 @@ def post_generate_project_validations( ) -> tuple[bool, str]: """This method will be called after an operation of generate project is executed. - :param class:`Ili2DbCommandConfiguration` configuration: Configuration parameters with which were executed the operation of generate project. - :param str fallback_user: a username as fallback most possibly used when you want to pass your os account name to connect the database - :return: *True* and an empty message if the called method was succeeded, *False* and a warning message otherwise. - """ + Args: + class: `Ili2DbCommandConfiguration` configuration: Configuration parameters with which were executed the operation of generate project. + fallback_user (str): a username as fallback most possibly used when you want to pass your os account name to connect the database - def get_specific_messages(self) -> dict[str, str]: - """Returns specific words that will be used in warning and error messages. + Returns: + *True* and an empty message if the called method was succeeded, *False* and a warning message otherwise.""" - :rtype dict - """ + def get_specific_messages(self) -> dict[str, str]: + """Returns specific words that will be used in warning and error messages.""" messages = {"db_or_schema": "schema", "layers_source": "schema"} return messages @@ -92,10 +93,8 @@ def get_specific_messages(self) -> dict[str, str]: def customize_widget_editor(self, field: Field, data_type: str) -> None: """Allows customizing the way a field is shown in the widget editor. - For instance, a boolean field can be shown as a checkbox. + For instance, a boolean field can be shown as a checkbox. - :param field: The field that will be customized - :type field: :class:`Field` - :param data_type: The type of field - :return None - """ + Args: + data_type: The type of field + field (:class:`Field`): The field that will be customized""" diff --git a/modelbaker/db_factory/db_simple_factory.py b/modelbaker/db_factory/db_simple_factory.py index 96e3096a..cc779408 100644 --- a/modelbaker/db_factory/db_simple_factory.py +++ b/modelbaker/db_factory/db_simple_factory.py @@ -46,10 +46,11 @@ class DbSimpleFactory: def create_factory(self, ili_mode: DbIliMode) -> Optional[DbFactory]: """Creates an instance of :class:`DbFactory` based on ili_mode parameter. - :param ili_mode: Value specifying which factory will be instantiated. - :type ili_mode: :class:`DbIliMode` - :return: A database factory - """ + Args: + ili_mode (:class:`DbIliMode`): Value specifying which factory will be instantiated. + + Returns: + A database factory""" if not ili_mode: return None @@ -69,13 +70,14 @@ def create_factory(self, ili_mode: DbIliMode) -> Optional[DbFactory]: def get_db_list(self, is_schema_import: bool = False) -> list[DbIliMode]: """Gets a list containing the databases available in modelbaker. - This list can be used to show the available databases in GUI, for example, **QComboBox source** - in **Import Data Dialog**. + This list can be used to show the available databases in GUI, for example, **QComboBox source** + in **Import Data Dialog**. + + Args: + is_schema_import (bool): *True* to include interlis operation values, *False* otherwise. - :param bool is_schema_import: *True* to include interlis operation values, *False* otherwise. - :return: A list containing the databases available. - :rtype: list - """ + Returns: + list: A list containing the databases available.""" ili = [] result = available_database_factories.keys() @@ -91,7 +93,6 @@ def get_db_list(self, is_schema_import: bool = False) -> list[DbIliMode]: def default_database(self) -> DbIliMode: """Gets a default database for modelbaker. - :return: Default database for modelbaker. - :rtype: :class:`DbIliMode` - """ + Returns: + :class:`DbIliMode`: Default database for modelbaker.""" return list(available_database_factories.keys())[0] diff --git a/modelbaker/db_factory/gpkg_command_config_manager.py b/modelbaker/db_factory/gpkg_command_config_manager.py index bd40dbc3..5934bf40 100644 --- a/modelbaker/db_factory/gpkg_command_config_manager.py +++ b/modelbaker/db_factory/gpkg_command_config_manager.py @@ -22,11 +22,10 @@ class GpkgCommandConfigManager(DbCommandConfigManager): """Manages a configuration object to return specific information of Geopackage. - Provides database uri, arguments to ili2db and a way to save and load configurations parameters - based on a object configuration. + Provides database uri, arguments to ili2db and a way to save and load configurations parameters + based on a object configuration. - :ivar configuration object that will be managed - """ + configuration object that will be managed""" _settings_base_path = "ili2gpkg/" diff --git a/modelbaker/db_factory/gpkg_layer_uri.py b/modelbaker/db_factory/gpkg_layer_uri.py index 96b6a8d7..b9c82e5f 100644 --- a/modelbaker/db_factory/gpkg_layer_uri.py +++ b/modelbaker/db_factory/gpkg_layer_uri.py @@ -17,10 +17,9 @@ class GpkgLayerUri(LayerUri): """Provides layer uri based on database uri (connection string) and specific information of the data source. - This **layer uri** is used to create a Qgis layer. + This **layer uri** is used to create a Qgis layer. - :ivar str uri: Database uri. - """ + str uri: Database uri.""" def __init__(self, uri: str) -> None: LayerUri.__init__(self, uri) diff --git a/modelbaker/db_factory/layer_uri.py b/modelbaker/db_factory/layer_uri.py index 2e081510..62b23fda 100644 --- a/modelbaker/db_factory/layer_uri.py +++ b/modelbaker/db_factory/layer_uri.py @@ -17,16 +17,15 @@ class LayerUri(ABC): """Provides layer uri based on database uri (connection string) and specific information of the data source. This is a abstract class. - This **layer uri** is used to create a Qgis layer. + This **layer uri** is used to create a Qgis layer. - :ivar str uri: Database uri. - :ivar str provider: Database provider. - """ + str provider: Database provider.""" def __init__(self, uri: str) -> None: """ - :param str uri: Database uri. This is the same database uri of the db connectors. - """ + + Args: + uri (str): Database uri. This is the same database uri of the db connectors.""" self.uri = uri self.provider = None @@ -34,7 +33,8 @@ def __init__(self, uri: str) -> None: def get_data_source_uri(self, record: dict) -> str: """Provides layer uri based on database uri and specific information of the data source. - :param str record: Dictionary containing specific information of the data source. - :return: Layer uri. - :rtype: str - """ + Args: + record (str): Dictionary containing specific information of the data source. + + Returns: + str: Layer uri.""" diff --git a/modelbaker/db_factory/pg_command_config_manager.py b/modelbaker/db_factory/pg_command_config_manager.py index edae2123..77a8b40b 100644 --- a/modelbaker/db_factory/pg_command_config_manager.py +++ b/modelbaker/db_factory/pg_command_config_manager.py @@ -23,11 +23,10 @@ class PgCommandConfigManager(DbCommandConfigManager): """Manages a configuration object to return specific information of Postgres/Postgis. - Provides database uri, arguments to ili2db and a way to save and load configurations parameters - based on a object configuration. + Provides database uri, arguments to ili2db and a way to save and load configurations parameters + based on a object configuration. - :ivar configuration object that will be managed - """ + configuration object that will be managed""" _settings_base_path = "ili2pg/" diff --git a/modelbaker/db_factory/pg_layer_uri.py b/modelbaker/db_factory/pg_layer_uri.py index bf19c86f..92adf4dd 100644 --- a/modelbaker/db_factory/pg_layer_uri.py +++ b/modelbaker/db_factory/pg_layer_uri.py @@ -17,10 +17,9 @@ class PgLayerUri(LayerUri): """Provides layer uri based on database uri (connection string) and specific information of the data source. - This **layer uri** is used to create a Qgis layer. + This **layer uri** is used to create a Qgis layer. - :ivar str uri: Database uri. - """ + str uri: Database uri.""" def __init__(self, uri: str) -> None: LayerUri.__init__(self, uri) diff --git a/modelbaker/generator/generator.py b/modelbaker/generator/generator.py index 7f828aa8..2715056c 100644 --- a/modelbaker/generator/generator.py +++ b/modelbaker/generator/generator.py @@ -52,11 +52,11 @@ def __init__( raw_naming=False, ) -> None: """ - Creates a new Generator objects. - :param uri: The uri that should be used in the resulting project. If authcfg is used, make sure the mgmt_uri is set as well. - :param mgmt_uri: The uri that should be used to create schemas, tables and query meta information. Does not support authcfg but a fallback username. - :consider_basket_handling: Makes the specific handling of basket tables depending if schema is created with createBasketCol. - """ + Creates a new Generator objects. + + Args: + mgmt_uri: The uri that should be used to create schemas, tables and query meta information. Does not support authcfg but a fallback username. + uri: The uri that should be used in the resulting project. If authcfg is used, make sure the mgmt_uri is set as well.""" QObject.__init__(self, parent) self.tool = tool self.uri = uri diff --git a/modelbaker/iliwrapper/ili2dbargs.py b/modelbaker/iliwrapper/ili2dbargs.py index bc99bc26..4e91f0ee 100644 --- a/modelbaker/iliwrapper/ili2dbargs.py +++ b/modelbaker/iliwrapper/ili2dbargs.py @@ -23,10 +23,11 @@ def get_ili2db_args(configuration, hide_password=False): """Gets a complete list of ili2db arguments in order to execute the app. - :param bool hide_password: *True* to mask the password, *False* otherwise. - :return: ili2db arguments list. - :rtype: list - """ + Args: + hide_password (bool): *True* to mask the password, *False* otherwise. + + Returns: + list: ili2db arguments list.""" db_args = _get_db_args(configuration, hide_password) if type(configuration) is SchemaImportConfiguration: diff --git a/modelbaker/iliwrapper/ili2dbutils.py b/modelbaker/iliwrapper/ili2dbutils.py index d87e94ba..45fbe072 100644 --- a/modelbaker/iliwrapper/ili2dbutils.py +++ b/modelbaker/iliwrapper/ili2dbutils.py @@ -248,18 +248,19 @@ def is_version_valid( module_tested="", ): """ - Generic one, it helps us to validate whether a current version is greater or equal to a min_required_version or, - if exact_required_version, if a current version is exactly the required one. + Generic one, it helps us to validate whether a current version is greater or equal to a min_required_version or, + if exact_required_version, if a current version is exactly the required one. - Borrowed from 'Asistente LADM-COL'. + Borrowed from 'Asistente LADM-COL'. - :param current_version: String, in the form 2.9.5 - :param min_required_version: String, in the form 2.9.5 - :param exact_required_version: Boolean, if true, only the exact version is valid. If False, the min_required_version - or any greater version will be accepted. - :param module_tested: String, only for displaying a log with context - :return: Whether the current version is valid or not - """ + Args: + current_version: String, in the form 2.9.5 + exact_required_version: Boolean, if true, only the exact version is valid. If False, the min_required_version or any greater version will be accepted. + min_required_version: String, in the form 2.9.5 + module_tested: String, only for displaying a log with context + + Returns: + Whether the current version is valid or not""" if current_version is None: return False diff --git a/modelbaker/iliwrapper/iliexecutable.py b/modelbaker/iliwrapper/iliexecutable.py index 74485146..c758bd5b 100644 --- a/modelbaker/iliwrapper/iliexecutable.py +++ b/modelbaker/iliwrapper/iliexecutable.py @@ -58,7 +58,8 @@ def __init__(self, parent=None): def _create_config(self) -> Ili2DbCommandConfiguration: """Creates the configuration that will be used by *run* method. - :return: ili2db configuration""" + Returns: + ili2db configuration""" def _get_ili2db_version(self): return self.configuration.db_ili_version @@ -66,10 +67,11 @@ def _get_ili2db_version(self): def _args(self, hide_password): """Gets the list of ili2db arguments from configuration. - :param bool hide_password: *True* to mask the password, *False* otherwise. - :return: ili2db arguments list. - :rtype: list - """ + Args: + hide_password (bool): *True* to mask the password, *False* otherwise. + + Returns: + list: ili2db arguments list.""" self.configuration.tool = self.tool return get_ili2db_args(self.configuration, hide_password) diff --git a/modelbaker/utils/ili2db_utils.py b/modelbaker/utils/ili2db_utils.py index 6bc56fbd..202993c1 100644 --- a/modelbaker/utils/ili2db_utils.py +++ b/modelbaker/utils/ili2db_utils.py @@ -43,10 +43,13 @@ 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 - """ + + Args: + baskets: Semicolon-separated list of baskets to be deleted + configuration: Base Ili2DbCommandConfiguration object + + Returns: + Tuple with boolean result and optional message""" deleter = ilideleter.Deleter() deleter.tool = configuration.tool deleter.configuration = DeleteConfiguration(configuration) @@ -77,10 +80,13 @@ 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 - """ + + Args: + configuration: Base Ili2DbCommandConfiguration object + dataset: Dataset id to be deleted + + Returns: + Tuple with boolean result and optional message""" deleter = ilideleter.Deleter() deleter.tool = configuration.tool deleter.configuration = DeleteConfiguration(configuration) @@ -111,10 +117,13 @@ 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 - """ + + Args: + configuration: Base Ili2DbCommandConfiguration object + ini_file: Output file + + Returns: + Tuple with boolean result and optional message""" metaconfig_exporter = ilimetaconfigexporter.MetaConfigExporter() metaconfig_exporter.tool = configuration.tool metaconfig_exporter.configuration = ExportMetaConfigConfiguration(configuration) From bd9a17f14ef11d8b4436475196fb0c4de6c7af36 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 28 Nov 2025 13:53:54 +0100 Subject: [PATCH 3/3] Type hints for dbconnector Type hints for iliwrapper Typehints for generator Type hints for utils Type hints for ilitoppingmaker --- modelbaker/dataobjects/layers.py | 12 +- modelbaker/dataobjects/legend.py | 4 +- .../db_factory/db_command_config_manager.py | 2 +- modelbaker/db_factory/db_factory.py | 4 +- .../db_factory/gpkg_command_config_manager.py | 2 +- modelbaker/db_factory/gpkg_factory.py | 4 +- .../mssql_command_config_manager.py | 2 +- modelbaker/db_factory/mssql_factory.py | 4 +- .../db_factory/pg_command_config_manager.py | 2 +- modelbaker/db_factory/pg_factory.py | 4 +- modelbaker/dbconnector/db_connector.py | 111 ++++++++++-------- modelbaker/dbconnector/gpkg_connector.py | 65 +++++----- modelbaker/dbconnector/mssql_connector.py | 55 +++++---- modelbaker/dbconnector/pg_connector.py | 65 +++++----- .../generator/domain_relations_generator.py | 46 +++++--- modelbaker/generator/generator.py | 91 ++++++++------ modelbaker/ilitoppingmaker/ilidata.py | 23 ++-- .../ilitoppingmaker/iliprojecttopping.py | 13 +- modelbaker/ilitoppingmaker/ilitarget.py | 9 +- modelbaker/ilitoppingmaker/metaconfig.py | 9 +- modelbaker/iliwrapper/ili2dbargs.py | 12 +- modelbaker/iliwrapper/ili2dbconfig.py | 58 +++++---- modelbaker/iliwrapper/ili2dbtools.py | 4 +- modelbaker/iliwrapper/ili2dbutils.py | 27 +++-- modelbaker/iliwrapper/ilicache.py | 73 +++++++----- modelbaker/iliwrapper/iliexecutable.py | 21 ++-- modelbaker/iliwrapper/iliexporter.py | 4 +- modelbaker/iliwrapper/iliupdater.py | 2 +- modelbaker/iliwrapper/ilivalidator.py | 10 +- modelbaker/utils/db_utils.py | 27 +++-- modelbaker/utils/globals.py | 2 +- modelbaker/utils/ili2db_utils.py | 15 +-- modelbaker/utils/qgis_utils.py | 22 ++-- modelbaker/utils/qt_utils.py | 60 ++++++---- 34 files changed, 499 insertions(+), 365 deletions(-) diff --git a/modelbaker/dataobjects/layers.py b/modelbaker/dataobjects/layers.py index 27309e9f..05d1a314 100644 --- a/modelbaker/dataobjects/layers.py +++ b/modelbaker/dataobjects/layers.py @@ -41,18 +41,18 @@ class Layer: def __init__( self, - provider: str = None, - uri: str = None, - name: str = None, + provider: Optional[str] = None, + uri: Optional[str] = None, + name: Optional[str] = None, srid: Optional[int] = None, extent: Optional[str] = None, - geometry_column: str = None, + geometry_column: Optional[str] = None, wkb_type: QgsWkbTypes = QgsWkbTypes.Type.Unknown, alias: Optional[str] = None, is_domain: bool = False, # is enumeration or catalogue is_structure: bool = False, is_nmrel: bool = False, - display_expression: str = None, + display_expression: Optional[str] = None, coordinate_precision: Optional[float] = None, is_basket_table: bool = False, is_dataset_table: bool = False, @@ -68,7 +68,7 @@ def __init__( qmlstylefile: Optional[str] = None, styles: dict[str, dict[str, str]] = {}, is_enum: bool = False, - base_class: str = None, + base_class: Optional[str] = None, provider_names_map: dict[ str, str ] = {}, # provider specific column names (e.g. T_Id vs t_id) diff --git a/modelbaker/dataobjects/legend.py b/modelbaker/dataobjects/legend.py index 57a33bca..87e9f36c 100644 --- a/modelbaker/dataobjects/legend.py +++ b/modelbaker/dataobjects/legend.py @@ -29,9 +29,9 @@ class LegendGroup: def __init__( self, - name: str = None, + name: Optional[str] = None, expanded: bool = True, - ignore_node_names: bool = None, + ignore_node_names: bool = False, static_sorting: bool = False, ) -> None: self.name = name diff --git a/modelbaker/db_factory/db_command_config_manager.py b/modelbaker/db_factory/db_command_config_manager.py index 81271367..3d2fe4f3 100644 --- a/modelbaker/db_factory/db_command_config_manager.py +++ b/modelbaker/db_factory/db_command_config_manager.py @@ -38,7 +38,7 @@ def __init__(self, configuration: Ili2DbCommandConfiguration) -> None: @abstractmethod def get_uri( - self, su: bool = False, qgis: bool = False, fallback_user: str = None + self, su: bool = False, qgis: bool = False, fallback_user: Optional[str] = None ) -> str: """Gets database uri (connection string) for db connectors (:class:`DBConnector`). diff --git a/modelbaker/db_factory/db_factory.py b/modelbaker/db_factory/db_factory.py index ecf6ae2e..c0e96bdd 100644 --- a/modelbaker/db_factory/db_factory.py +++ b/modelbaker/db_factory/db_factory.py @@ -73,7 +73,9 @@ def pre_generate_project( @abstractmethod def post_generate_project_validations( - self, configuration: Ili2DbCommandConfiguration, fallback_user: str = None + self, + configuration: Ili2DbCommandConfiguration, + fallback_user: Optional[str] = None, ) -> tuple[bool, str]: """This method will be called after an operation of generate project is executed. diff --git a/modelbaker/db_factory/gpkg_command_config_manager.py b/modelbaker/db_factory/gpkg_command_config_manager.py index 5934bf40..22e116dc 100644 --- a/modelbaker/db_factory/gpkg_command_config_manager.py +++ b/modelbaker/db_factory/gpkg_command_config_manager.py @@ -33,7 +33,7 @@ def __init__(self, configuration: Ili2DbCommandConfiguration) -> None: DbCommandConfigManager.__init__(self, configuration) def get_uri( - self, su: bool = False, qgis: bool = False, fallback_user: str = None + self, su: bool = False, qgis: bool = False, fallback_user: Optional[str] = None ) -> str: return self.configuration.dbfile diff --git a/modelbaker/db_factory/gpkg_factory.py b/modelbaker/db_factory/gpkg_factory.py index d374d2ac..270fbec2 100644 --- a/modelbaker/db_factory/gpkg_factory.py +++ b/modelbaker/db_factory/gpkg_factory.py @@ -42,7 +42,9 @@ def pre_generate_project( return True, "" def post_generate_project_validations( - self, configuration: Ili2DbCommandConfiguration, fallback_user: str = None + self, + configuration: Ili2DbCommandConfiguration, + fallback_user: Optional[str] = None, ) -> tuple[bool, str]: return True, "" diff --git a/modelbaker/db_factory/mssql_command_config_manager.py b/modelbaker/db_factory/mssql_command_config_manager.py index 894456b7..6fba5c1d 100644 --- a/modelbaker/db_factory/mssql_command_config_manager.py +++ b/modelbaker/db_factory/mssql_command_config_manager.py @@ -27,7 +27,7 @@ def __init__(self, configuration: Ili2DbCommandConfiguration) -> None: DbCommandConfigManager.__init__(self, configuration) def get_uri( - self, su: bool = False, qgis: bool = False, fallback_user: str = None + self, su: bool = False, qgis: bool = False, fallback_user: Optional[str] = None ) -> str: separator = ";" uri = [] diff --git a/modelbaker/db_factory/mssql_factory.py b/modelbaker/db_factory/mssql_factory.py index 5dc0a61a..d3d92ae4 100644 --- a/modelbaker/db_factory/mssql_factory.py +++ b/modelbaker/db_factory/mssql_factory.py @@ -41,7 +41,9 @@ def pre_generate_project( return True, "" def post_generate_project_validations( - self, configuration: Ili2DbCommandConfiguration, fallback_user: str = None + self, + configuration: Ili2DbCommandConfiguration, + fallback_user: Optional[str] = None, ) -> tuple[bool, str]: return True, "" diff --git a/modelbaker/db_factory/pg_command_config_manager.py b/modelbaker/db_factory/pg_command_config_manager.py index 77a8b40b..971e7705 100644 --- a/modelbaker/db_factory/pg_command_config_manager.py +++ b/modelbaker/db_factory/pg_command_config_manager.py @@ -34,7 +34,7 @@ def __init__(self, configuration: Ili2DbCommandConfiguration) -> None: DbCommandConfigManager.__init__(self, configuration) def get_uri( - self, su: bool = False, qgis: bool = False, fallback_user: str = None + self, su: bool = False, qgis: bool = False, fallback_user: Optional[str] = None ) -> str: uri = [] diff --git a/modelbaker/db_factory/pg_factory.py b/modelbaker/db_factory/pg_factory.py index b51538f2..124f54ac 100644 --- a/modelbaker/db_factory/pg_factory.py +++ b/modelbaker/db_factory/pg_factory.py @@ -67,7 +67,9 @@ def pre_generate_project( return result, message def post_generate_project_validations( - self, configuration: Ili2DbCommandConfiguration, fallback_user: str = None + self, + configuration: Ili2DbCommandConfiguration, + fallback_user: Optional[str] = None, ) -> tuple[bool, str]: result = False message = "" diff --git a/modelbaker/dbconnector/db_connector.py b/modelbaker/dbconnector/db_connector.py index b0655adb..d373bbac 100644 --- a/modelbaker/dbconnector/db_connector.py +++ b/modelbaker/dbconnector/db_connector.py @@ -12,6 +12,7 @@ """ import fnmatch +from typing import Optional from qgis.PyQt.QtCore import QObject, pyqtSignal @@ -37,7 +38,7 @@ def __init__(self, uri, schema, parent=None): self.dataset_table_name = "" # For basket handling, specific for each DB self._lang = "" # Preferred tr language for table/column info (2 characters) - def get_provider_specific_names(self): + def get_provider_specific_names(self) -> dict: """ Returns a dictionary of the provider-specific names defined in the initialization of the derived classes. """ @@ -50,25 +51,25 @@ def get_provider_specific_names(self): "datasettable_name": self.dataset_table_name, } - def map_data_types(self, data_type): + def map_data_types(self, data_type: str) -> str: """Map provider date/time types to QGIS date/time types""" - return None + raise None - def db_or_schema_exists(self): + def db_or_schema_exists(self) -> bool: """Whether the DB (for GPKG) or schema (for PG) exists or not.""" - raise NotImplementedError + raise False - def create_db_or_schema(self, usr): + def create_db_or_schema(self, usr: str) -> bool: """Create the DB (for GPKG) or schema (for PG)""" - raise NotImplementedError + raise False - def metadata_exists(self): + def metadata_exists(self) -> bool: """Whether t_ili2db_table_prop table exists or not. In other words... Does the DB/Schema hold an INTERLIS model? """ - return False + raise False - def get_tables_info(self): + def get_tables_info(self) -> list[dict]: """ Info about tables found in the database (or database schema). @@ -90,9 +91,9 @@ def get_tables_info(self): relevance base_class """ - return [] + raise [] - def get_meta_attrs_info(self): + def get_meta_attrs_info(self) -> list[dict]: """ Info about meta attributes @@ -104,9 +105,9 @@ def get_meta_attrs_info(self): attr_name attr_value """ - raise NotImplementedError + raise [] - def get_meta_attr(self, ili_name): + def get_meta_attrs(self, ili_name: str) -> list[dict]: """ Info about meta attributes of a given ili element @@ -117,9 +118,9 @@ def get_meta_attr(self, ili_name): attr_name attr_value """ - return [] + raise [] - def get_fields_info(self, table_name): + def get_fields_info(self, table_name: str) -> list[dict]: """ Info about fields of a given table in the database. @@ -137,9 +138,9 @@ def get_fields_info(self, table_name): oid_domain fully_qualified_name """ - return [] + raise [] - def get_min_max_info(self, table_name): + def get_min_max_info(self, table_name: str) -> dict: """ Info about range constraints found in a given table. @@ -147,9 +148,9 @@ def get_min_max_info(self, table_name): Dictionary with keys corresponding to column names and values corresponding to tuples in the form (min_value, max_value) """ - return {} + raise {} - def get_value_map_info(self, table_name): + def get_value_map_info(self, table_name) -> dict: """ Info about value map constraints found in a given table. @@ -157,9 +158,9 @@ def get_value_map_info(self, table_name): Dictionary with keys corresponding to column names and values with lists of allowed values """ - return {} + raise {} - def get_t_type_map_info(self, table_name): + def get_t_type_map_info(self, table_name: str) -> dict: """ Info about available types of a given smart1-inherited table. @@ -167,9 +168,9 @@ def get_t_type_map_info(self, table_name): Dictionary with keys corresponding to column names and values with lists of allowed values """ - return {} + raise {} - def get_relations_info(self, filter_layer_list=[]): + def get_relations_info(self, filter_layer_list: list[str] = []) -> list[dict]: """ Info about relations found in a database (or database schema). @@ -187,9 +188,9 @@ def get_relations_info(self, filter_layer_list=[]): cardinality_max cardinality_min """ - return [] + raise [] - def get_bags_of_info(self): + def get_bags_of_info(self) -> list[dict]: """ Info about bags_of found in a database (or database schema). @@ -204,9 +205,9 @@ def get_bags_of_info(self): cardinality_min mapping_type """ - return [] + raise [] - def get_ignored_layers(self, ignore_basket_tables=True): + def get_ignored_layers(self, ignore_basket_tables=True) -> list[str]: """ The ignored layers according to the ignored schemas and ignored tables and the ignored ili elements listed in the config.py. @@ -261,42 +262,44 @@ def is_spatial_index_table(self, tablename=str) -> bool: """Note: Checks if the table is a technical table used for spatial indexing""" return False - def get_iliname_dbname_mapping(self, sqlnames=list()): + def get_iliname_dbname_mapping(self, sqlnames: list[str] = []) -> dict: """Note: the parameter sqlnames is only used for ili2db version 3 relation creation""" return {} - def get_classili_classdb_mapping(self, models_info, extended_classes): + def get_classili_classdb_mapping( + self, models_info: dict, extended_classes: dict + ) -> dict: """Used for ili2db version 3""" return {} - def get_attrili_attrdb_mapping(self, attrs_list): + def get_attrili_attrdb_mapping(self, attrs_list: list[str]) -> dict: """Used for ili2db version 3""" return {} - def get_attrili_attrdb_mapping_by_owner(self, owners): + def get_attrili_attrdb_mapping_by_owner(self, owners: list[str]) -> dict: """Used for ili2db version 3""" return {} - def get_models(self): + def get_models(self) -> dict: """ Returns the models in use, the ili-file content and the direct parents of the model. """ return {} - def ili_version(self): + def ili_version(self) -> str: """ Returns the version of the ili2db application that was used to create the schema. """ return None - def get_basket_handling(self): + def get_basket_handling(self) -> bool: """ Returns `True` if a basket handling is enabled according to the settings table. Means when the database has been created with `--createBasketCol`. """ return False - def get_baskets_info(self): + def get_baskets_info(self) -> list[dict]: """ Info about baskets found in the basket table and the related datasetname Return: @@ -312,7 +315,7 @@ def get_baskets_info(self): """ return {} - def get_datasets_info(self): + def get_datasets_info(self) -> list[dict]: """ Info about datasets found in the dataset table Return: @@ -324,19 +327,19 @@ def get_datasets_info(self): """ return {} - def create_dataset(self, datasetname): + def create_dataset(self, datasetname: str) -> tuple[bool, str]: """ Returns the state and the errormessage """ return False, None - def rename_dataset(self, tid, datasetname): + def rename_dataset(self, tid: str, datasetname: str) -> tuple[bool, str]: """ Returns the state and the errormessage """ return False, None - def get_topics_info(self): + def get_topics_info(self) -> dict: """ Returns all the topics found in the table t_ili2db_classname as long as they contain tables found in t_ili2db_table_prop and are there not defined as ENUM. This avoids to get structures back, containing enumerations and not being in a topic, having the structure ... @@ -351,7 +354,7 @@ def get_topics_info(self): """ return {} - def get_classes_relevance(self): + def get_classes_relevance(self) -> list[dict]: """ Returns the ili classes and it's sqlname and relevance. Compared to tables_info it returns the classes (and the sqlnames of tables that might not be existing) and not the existing tables. This is mainly used, when smart1 has been selected. @@ -362,7 +365,7 @@ def get_classes_relevance(self): """ return [] - def multiple_geometry_tables(self): + def multiple_geometry_tables(self) -> list[str]: """ Returns a list of tables having multiple geometry columns. It's only usefull on GeoPackage. @@ -370,8 +373,12 @@ def multiple_geometry_tables(self): return [] def create_basket( - self, dataset_tid, topic, tilitid_value=None, attachment_key="modelbaker" - ): + self, + dataset_tid: str, + topic: str, + tilitid_value: Optional[str] = None, + attachment_key: str = "modelbaker", + ) -> tuple[bool, str]: """ Returns the state and the errormessage """ @@ -392,32 +399,32 @@ def edit_basket(self, basket_config: dict) -> tuple[bool, str]: """ return False, None - def get_tid_handling(self): + def get_tid_handling(self) -> dict: """ Returns `True` if a tid handling is enabled according to the settings table (when the database has been created with `--createTidCol`). If t_ili_tids are used only because of a stable id definition in the model (with `OID as` in the topic or the class definition), this parameter is not set and this function will return `{}`. """ return {} - def get_ili2db_settings(self): + def get_ili2db_settings(self) -> dict: """ Returns the settings like they are without any name mapping etc. """ return {} - def get_ili2db_sequence_value(self): + def get_ili2db_sequence_value(self) -> str: """ Returns the current value of the sequence used for the t_id """ return None - def get_next_ili2db_sequence_value(self): + def get_next_ili2db_sequence_value(self) -> str: """ Increases and returns the value of the sequence used for the t_id """ return None - def set_ili2db_sequence_value(self, value): + def set_ili2db_sequence_value(self, value: str) -> tuple[bool, str]: """ Resets the current value of the sequence used for the t_id """ @@ -461,13 +468,13 @@ def get_available_languages( """ return [] - def get_domain_dispnames(self, tablename): + def get_domain_dispnames(self, tablename: str) -> list[dict]: """ Get the domain display names with consideration of the translation """ return [] - def get_schemas(self, ignore_system_schemas=True): + def get_schemas(self, ignore_system_schemas: bool = True) -> list[str]: result = [] all_schemas = self.get_all_schemas() @@ -485,7 +492,7 @@ def get_schemas(self, ignore_system_schemas=True): result.append(schema) return result - def get_all_schemas(self): + def get_all_schemas(self) -> list[str]: """ Get the schemas from PostgreSQL. Otherwise empty. """ diff --git a/modelbaker/dbconnector/gpkg_connector.py b/modelbaker/dbconnector/gpkg_connector.py index f4a82167..69dc762b 100644 --- a/modelbaker/dbconnector/gpkg_connector.py +++ b/modelbaker/dbconnector/gpkg_connector.py @@ -16,6 +16,7 @@ import re import sqlite3 import uuid +from typing import Optional import qgis.utils from qgis.core import Qgis @@ -55,17 +56,13 @@ def __init__(self, uri, schema): self.basket_table_name = GPKG_BASKET_TABLE self.dataset_table_name = GPKG_DATASET_TABLE - def map_data_types(self, data_type): + def map_data_types(self, data_type: str) -> str: """GPKG date/time types correspond to QGIS date/time types""" return data_type.lower() - def db_or_schema_exists(self): + def db_or_schema_exists(self) -> bool: return os.path.isfile(self.uri) - def create_db_or_schema(self, usr): - """Create the DB (for GPKG).""" - raise NotImplementedError - def metadata_exists(self): return self._bMetadataTable @@ -493,7 +490,7 @@ def get_min_max_info(self, table_name): cursor.close() return constraint_mapping - def get_t_type_map_info(self, table_name): + def get_t_type_map_info(self, table_name: str) -> dict: if self.metadata_exists(): cursor = self.conn.cursor() cursor.execute( @@ -513,7 +510,7 @@ def get_t_type_map_info(self, table_name): return types_mapping return {} - def get_relations_info(self, filter_layer_list=[]): + def get_relations_info(self, filter_layer_list: list[str] = []) -> list[dict]: # We need to get the PK for each table, so first get tables_info # and then build something more searchable tables_info_dict = dict() @@ -615,7 +612,7 @@ def get_relations_info(self, filter_layer_list=[]): cursor.close() return complete_records - def get_bags_of_info(self): + def get_bags_of_info(self) -> list[dict]: bags_of_info = {} if self.metadata_exists(): cursor = self.conn.cursor() @@ -645,7 +642,7 @@ def is_spatial_index_table(self, tablename=str) -> bool: return True return False - def get_iliname_dbname_mapping(self, sqlnames=list()): + def get_iliname_dbname_mapping(self, sqlnames: list[str] = []) -> dict: """Note: the parameter sqlnames is only used for ili2db version 3 relation creation""" # Map domain ili name with its correspondent sql name if self.metadata_exists(): @@ -686,7 +683,7 @@ def get_classili_classdb_mapping(self, models_info, extended_classes): ) return cursor - def get_attrili_attrdb_mapping(self, attrs_list): + def get_attrili_attrdb_mapping(self, attrs_list: list[str]) -> dict: """Used for ili2db version 3 relation creation""" cursor = self.conn.cursor() attr_names = "'" + "','".join(attrs_list) + "'" @@ -700,7 +697,7 @@ def get_attrili_attrdb_mapping(self, attrs_list): ) return cursor - def get_attrili_attrdb_mapping_by_owner(self, owners): + def get_attrili_attrdb_mapping_by_owner(self, owners: list[str]) -> dict: """Used for ili2db version 3 relation creation""" cursor = self.conn.cursor() owner_names = "'" + "','".join(owners) + "'" @@ -714,7 +711,7 @@ def get_attrili_attrdb_mapping_by_owner(self, owners): ) return cursor - def get_models(self): + def get_models(self) -> dict: if not self._table_exists("T_ILI2DB_TRAFO"): return {} @@ -756,7 +753,7 @@ def get_models(self): cursor.close() return list_result - def ili_version(self): + def ili_version(self) -> str: cursor = self.conn.cursor() cursor.execute("""PRAGMA table_info(T_ILI2DB_ATTRNAME)""") table_info = cursor.fetchall() @@ -779,7 +776,7 @@ def ili_version(self): else: return 4 - def get_basket_handling(self): + def get_basket_handling(self) -> bool: if self._table_exists(GPKG_SETTINGS_TABLE): cursor = self.conn.cursor() cursor.execute( @@ -797,7 +794,7 @@ def get_basket_handling(self): return content[0] == "readWrite" return False - def get_baskets_info(self): + def get_baskets_info(self) -> list[dict]: if self._table_exists(GPKG_BASKET_TABLE): cursor = self.conn.cursor() cursor.execute( @@ -818,7 +815,7 @@ def get_baskets_info(self): return contents return {} - def get_datasets_info(self): + def get_datasets_info(self) -> list[dict]: if self._table_exists(GPKG_DATASET_TABLE): cursor = self.conn.cursor() cursor.execute( @@ -833,7 +830,7 @@ def get_datasets_info(self): return contents return {} - def create_dataset(self, datasetname): + def create_dataset(self, datasetname: str) -> tuple[bool, str]: if self._table_exists(GPKG_DATASET_TABLE): cursor = self.conn.cursor() try: @@ -894,7 +891,7 @@ def rename_dataset(self, tid, datasetname): ) return False, self.tr('Could not rename dataset to "{}".').format(datasetname) - def get_topics_info(self): + def get_topics_info(self) -> dict: if self._table_exists("T_ILI2DB_CLASSNAME") and self._table_exists( GPKG_METAATTRS_TABLE ): @@ -931,7 +928,7 @@ def get_topics_info(self): return contents return {} - def get_classes_relevance(self): + def get_classes_relevance(self) -> list[dict]: if self._table_exists("T_ILI2DB_CLASSNAME"): cursor = self.conn.cursor() cursor.execute( @@ -983,7 +980,7 @@ def get_classes_relevance(self): return contents return [] - def multiple_geometry_tables(self): + def multiple_geometry_tables(self) -> list[str]: tables = [] if self._table_exists("gpkg_geometry_columns"): cursor = self.conn.cursor() @@ -1003,8 +1000,12 @@ def multiple_geometry_tables(self): return tables def create_basket( - self, dataset_tid, topic, tilitid_value=None, attachment_key="modelbaker" - ): + self, + dataset_tid: str, + topic: str, + tilitid_value: Optional[str] = None, + attachment_key: str = "modelbaker", + ) -> tuple[bool, str]: if self._table_exists(GPKG_BASKET_TABLE): cursor = self.conn.cursor() cursor.execute( @@ -1104,7 +1105,7 @@ def edit_basket(self, basket_config: dict) -> tuple[bool, str]: 'Could not edit basket for topic "{}" and dataset "{}"' ).format(basket_config["topic"], basket_config["datasetname"]) - def get_tid_handling(self): + def get_tid_handling(self) -> dict: if self._table_exists(GPKG_SETTINGS_TABLE): cursor = self.conn.cursor() cursor.execute( @@ -1122,7 +1123,7 @@ def get_tid_handling(self): return content[0] == "property" return False - def get_ili2db_settings(self): + def get_ili2db_settings(self) -> dict: result = {} if self._table_exists(GPKG_SETTINGS_TABLE): cursor = self.conn.cursor() @@ -1193,7 +1194,7 @@ def _fetch_and_increment_key_object(self, field_name): ), ) - def get_ili2db_sequence_value(self): + def get_ili2db_sequence_value(self) -> str: if self._table_exists("T_KEY_OBJECT"): cursor = self.conn.cursor() cursor.execute( @@ -1209,7 +1210,7 @@ def get_ili2db_sequence_value(self): return content[0] return None - def get_next_ili2db_sequence_value(self): + def get_next_ili2db_sequence_value(self) -> str: ( status, next_id, @@ -1217,7 +1218,7 @@ def get_next_ili2db_sequence_value(self): ) = self._fetch_and_increment_key_object(self.tid) return next_id - def set_ili2db_sequence_value(self, value): + def set_ili2db_sequence_value(self, value: str) -> tuple[bool, str]: if self._table_exists("T_KEY_OBJECT"): try: cursor = self.conn.cursor() @@ -1257,7 +1258,7 @@ def set_ili2db_sequence_value(self, value): def get_translation_handling(self) -> tuple[bool, str]: return self._table_exists(GPKG_NLS_TABLE) and self._lang != "", self._lang - def get_translation_models(self): + def get_translation_models(self) -> list[str]: if not self._table_exists(GPKG_METAATTRS_TABLE): return [] @@ -1278,7 +1279,9 @@ def get_translation_models(self): cursor.close() return [record["ilielement"] for record in records] - def get_available_languages(self, irrelevant_models=[], relevant_models=[]): + def get_available_languages( + self, irrelevant_models: list[str], relevant_models: list[str] + ) -> list[str]: if not self._table_exists(GPKG_METAATTRS_TABLE): return [] @@ -1322,7 +1325,7 @@ def get_available_languages(self, irrelevant_models=[], relevant_models=[]): cursor.close() return [record["attr_value"] for record in records] - def get_domain_dispnames(self, tablename): + def get_domain_dispnames(self, tablename: str) -> list[dict]: if ( not self._table_exists or not self._table_exists(GPKG_NLS_TABLE) diff --git a/modelbaker/dbconnector/mssql_connector.py b/modelbaker/dbconnector/mssql_connector.py index 4a9a9c49..c47a28ab 100644 --- a/modelbaker/dbconnector/mssql_connector.py +++ b/modelbaker/dbconnector/mssql_connector.py @@ -13,6 +13,7 @@ import numbers import re +from typing import Optional import pyodbc from qgis.core import Qgis @@ -52,7 +53,7 @@ def __init__(self, uri, schema): self.basket_table_name = BASKET_TABLE self.dataset_table_name = DATASET_TABLE - def map_data_types(self, data_type): + def map_data_types(self, data_type: str) -> str: result = data_type.lower() if "timestamp" in data_type: result = self.QGIS_DATE_TIME_TYPE @@ -63,7 +64,7 @@ def map_data_types(self, data_type): return result - def db_or_schema_exists(self): + def db_or_schema_exists(self) -> bool: if self.schema: cur = self.conn.cursor() cur.execute( @@ -611,7 +612,7 @@ def get_min_max_info(self, table_name): return result - def get_t_type_map_info(self, table_name): + def get_t_type_map_info(self, table_name: str) -> dict: if self.schema and self.metadata_exists(): cur = self.conn.cursor() cur.execute( @@ -633,7 +634,7 @@ def get_t_type_map_info(self, table_name): return types_mapping return {} - def get_relations_info(self, filter_layer_list=[]): + def get_relations_info(self, filter_layer_list: list[str] = []) -> list[dict]: result = [] if self.schema: @@ -737,7 +738,7 @@ def get_relations_info(self, filter_layer_list=[]): return result - def get_iliname_dbname_mapping(self, sqlnames=list()): + def get_iliname_dbname_mapping(self, sqlnames: list[str] = []) -> dict: """Note: the parameter sqlnames is only used for ili2db version 3 relation creation""" result = {} # Map domain ili name with its correspondent mssql name @@ -762,7 +763,7 @@ def get_iliname_dbname_mapping(self, sqlnames=list()): return result - def get_models(self): + def get_models(self) -> dict: if not self._table_exists("t_ili2db_trafo"): return {} @@ -829,7 +830,7 @@ def get_classili_classdb_mapping(self, models_info, extended_classes): result = self._get_dict_result(cur) return result - def get_attrili_attrdb_mapping(self, attrs_list): + def get_attrili_attrdb_mapping(self, attrs_list: list[str]) -> dict: result = {} if self.schema: cur = self.conn.cursor() @@ -846,7 +847,7 @@ def get_attrili_attrdb_mapping(self, attrs_list): result = self._get_dict_result(cur) return result - def get_attrili_attrdb_mapping_by_owner(self, owners): + def get_attrili_attrdb_mapping_by_owner(self, owners: list[str]) -> dict: result = {} if self.schema: cur = self.conn.cursor() @@ -872,7 +873,7 @@ def _get_dict_result(self, cur): return res - def ili_version(self): + def ili_version(self) -> str: cur = self.conn.cursor() cur.execute( """SELECT count(COLUMN_NAME) @@ -894,7 +895,7 @@ def ili_version(self): else: return 4 - def get_basket_handling(self): + def get_basket_handling(self) -> bool: if self.schema and self._table_exists(SETTINGS_TABLE): cur = self.conn.cursor() cur.execute( @@ -911,7 +912,7 @@ def get_basket_handling(self): return content[0] == "readWrite" return False - def get_baskets_info(self): + def get_baskets_info(self) -> list[dict]: result = {} if self.schema and self._table_exists(BASKET_TABLE): cur = self.conn.cursor() @@ -933,7 +934,7 @@ def get_baskets_info(self): result = self._get_dict_result(cur) return result - def get_datasets_info(self): + def get_datasets_info(self) -> list[dict]: result = {} if self.schema and self._table_exists(DATASET_TABLE): cur = self.conn.cursor() @@ -947,7 +948,7 @@ def get_datasets_info(self): result = self._get_dict_result(cur) return result - def create_dataset(self, datasetname): + def create_dataset(self, datasetname: str) -> tuple[bool, str]: if self.schema and self._table_exists(DATASET_TABLE): cur = self.conn.cursor() try: @@ -996,7 +997,7 @@ def rename_dataset(self, tid, datasetname): ) return False, self.tr('Could not create dataset "{}".').format(datasetname) - def get_topics_info(self): + def get_topics_info(self) -> dict: result = {} if ( self.schema @@ -1022,7 +1023,7 @@ def get_topics_info(self): result = self._get_dict_result(cur) return result - def get_classes_relevance(self): + def get_classes_relevance(self) -> list[dict]: result = [] if self.schema and self._table_exists("t_ili2db_classname"): cur = self.conn.cursor() @@ -1087,8 +1088,12 @@ def get_classes_relevance(self): return result def create_basket( - self, dataset_tid, topic, tilitid_value=None, attachment_key="modelbaker" - ): + self, + dataset_tid: str, + topic: str, + tilitid_value: Optional[str] = None, + attachment_key: str = "modelbaker", + ) -> tuple[bool, str]: if self.schema and self._table_exists(BASKET_TABLE): cur = self.conn.cursor() cur.execute( @@ -1179,7 +1184,7 @@ def edit_basket(self, basket_config: dict) -> tuple[bool, str]: 'Could not edit basket for topic "{}" and dataset "{}"' ).format(basket_config["topic"], basket_config["datasetname"]) - def get_tid_handling(self): + def get_tid_handling(self) -> dict: if self.schema and self._table_exists(SETTINGS_TABLE): cur = self.conn.cursor() cur.execute( @@ -1196,7 +1201,7 @@ def get_tid_handling(self): return content[0] == "property" return False - def get_ili2db_settings(self): + def get_ili2db_settings(self) -> dict: result = {} if self._table_exists(SETTINGS_TABLE): cur = self.conn.cursor() @@ -1210,11 +1215,11 @@ def get_ili2db_settings(self): result = self._get_dict_result(cur) return result - def get_ili2db_sequence_value(self): + def get_ili2db_sequence_value(self) -> str: # not implemented, return the next one return self.get_next_ili2db_sequence_value() - def get_next_ili2db_sequence_value(self): + def get_next_ili2db_sequence_value(self) -> str: if self.schema: cur = self.conn.cursor() cur.execute( @@ -1229,7 +1234,7 @@ def get_next_ili2db_sequence_value(self): return content[0] return None - def set_ili2db_sequence_value(self, value): + def set_ili2db_sequence_value(self, value: str) -> tuple[bool, str]: if self.schema: cur = self.conn.cursor() try: @@ -1255,7 +1260,7 @@ def set_ili2db_sequence_value(self, value): def get_translation_handling(self) -> tuple[bool, str]: return self._table_exists(NLS_TABLE) and self._lang != "", self._lang - def get_translation_models(self): + def get_translation_models(self) -> list[str]: if self.schema and self._table_exists(METAATTRS_TABLE): cur = self.conn.cursor() cur.execute( @@ -1272,7 +1277,9 @@ def get_translation_models(self): return [row.ilielement for row in cur.fetchall()] return [] - def get_available_languages(self, irrelevant_models=[], relevant_models=[]): + def get_available_languages( + self, irrelevant_models: list[str], relevant_models: list[str] + ) -> list[str]: if self.schema and self._table_exists(METAATTRS_TABLE): white_list_restriction = "" diff --git a/modelbaker/dbconnector/pg_connector.py b/modelbaker/dbconnector/pg_connector.py index 3fb3d2d5..267cfd2f 100644 --- a/modelbaker/dbconnector/pg_connector.py +++ b/modelbaker/dbconnector/pg_connector.py @@ -13,6 +13,7 @@ import logging import re +from typing import Optional import psycopg2 import psycopg2.extras @@ -50,7 +51,7 @@ def __init__(self, uri, schema): self.basket_table_name = PG_BASKET_TABLE self.dataset_table_name = PG_DATASET_TABLE - def map_data_types(self, data_type): + def map_data_types(self, data_type: str) -> str: if not data_type: data_type = "" data_type = data_type.lower() @@ -76,7 +77,7 @@ def _postgis_exists(self): return bool(cur.fetchone()[0]) - def db_or_schema_exists(self): + def db_or_schema_exists(self) -> bool: if self.schema: cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur.execute( @@ -90,7 +91,7 @@ def db_or_schema_exists(self): return False - def create_db_or_schema(self, usr): + def create_db_or_schema(self, usr: str) -> bool: cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) if usr: authorization_string = sql.SQL("AUTHORIZATION") + sql.Identifier(usr) @@ -650,7 +651,7 @@ def get_min_max_info(self, table_name): _ValueMapRegExp = re.compile(".*'(.*)'::.*") - def get_value_map_info(self, table_name): + def get_value_map_info(self, table_name) -> dict: if self.schema: constraints_cur = self.conn.cursor( cursor_factory=psycopg2.extras.DictCursor @@ -681,7 +682,7 @@ def get_value_map_info(self, table_name): return {} - def get_t_type_map_info(self, table_name): + def get_t_type_map_info(self, table_name: str) -> dict: if self.schema and self.metadata_exists(): cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur.execute( @@ -704,7 +705,7 @@ def get_t_type_map_info(self, table_name): return types_mapping return {} - def get_relations_info(self, filter_layer_list=[]): + def get_relations_info(self, filter_layer_list: list[str] = []) -> list[dict]: if self.schema: cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) schema_where1 = "AND KCU1.CONSTRAINT_SCHEMA = '{}'".format(self.schema) @@ -793,7 +794,7 @@ def get_relations_info(self, filter_layer_list=[]): return [] - def get_bags_of_info(self): + def get_bags_of_info(self) -> list[dict]: if self.schema and self.metadata_exists(): cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur.execute( @@ -820,7 +821,7 @@ def get_bags_of_info(self): return cur return [] - def get_iliname_dbname_mapping(self, sqlnames=list()): + def get_iliname_dbname_mapping(self, sqlnames: list[str] = []) -> dict: """Note: the parameter sqlnames is only used for ili2db version 3 relation creation""" # Map domain ili name with its correspondent pg name if self.schema and self.metadata_exists(): @@ -870,7 +871,7 @@ def get_classili_classdb_mapping(self, models_info, extended_classes): return {} - def get_attrili_attrdb_mapping(self, attrs_list): + def get_attrili_attrdb_mapping(self, attrs_list: list[str]) -> dict: """Used for ili2db version 3 relation creation""" if self.schema: cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) @@ -892,7 +893,7 @@ def get_attrili_attrdb_mapping(self, attrs_list): return {} - def get_attrili_attrdb_mapping_by_owner(self, owners): + def get_attrili_attrdb_mapping_by_owner(self, owners: list[str]) -> dict: """Used for ili2db version 3 relation creation""" if self.schema: cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) @@ -914,7 +915,7 @@ def get_attrili_attrdb_mapping_by_owner(self, owners): return {} - def get_models(self): + def get_models(self) -> dict: if not self._table_exists("t_ili2db_trafo"): return {} @@ -965,7 +966,7 @@ def get_models(self): return list_result return {} - def ili_version(self): + def ili_version(self) -> str: cur = self.conn.cursor() cur.execute( """ @@ -986,7 +987,7 @@ def ili_version(self): else: return 4 - def get_basket_handling(self): + def get_basket_handling(self) -> bool: if self.schema and self._table_exists(PG_SETTINGS_TABLE): cur = self.conn.cursor() cur.execute( @@ -1006,7 +1007,7 @@ def get_basket_handling(self): return content[0] == "readWrite" return False - def get_baskets_info(self): + def get_baskets_info(self) -> list[dict]: if self.schema and self._table_exists(PG_BASKET_TABLE): cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur.execute( @@ -1029,7 +1030,7 @@ def get_baskets_info(self): return cur.fetchall() return {} - def get_datasets_info(self): + def get_datasets_info(self) -> list[dict]: if self.schema and self._table_exists(PG_DATASET_TABLE): cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur.execute( @@ -1043,7 +1044,7 @@ def get_datasets_info(self): return cur.fetchall() return {} - def create_dataset(self, datasetname): + def create_dataset(self, datasetname: str) -> tuple[bool, str]: if self.schema and self._table_exists(PG_DATASET_TABLE): cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) try: @@ -1092,7 +1093,7 @@ def rename_dataset(self, tid, datasetname): ) return False, self.tr('Could not rename dataset "{}".').format(datasetname) - def get_topics_info(self): + def get_topics_info(self) -> dict: if ( self.schema and self._table_exists("t_ili2db_classname") @@ -1131,7 +1132,7 @@ def get_topics_info(self): return {} - def get_classes_relevance(self): + def get_classes_relevance(self) -> list[dict]: if self.schema and self._table_exists("t_ili2db_classname"): cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur.execute( @@ -1179,8 +1180,12 @@ def get_classes_relevance(self): return [] def create_basket( - self, dataset_tid, topic, tilitid_value=None, attachment_key="modelbaker" - ): + self, + dataset_tid: str, + topic: str, + tilitid_value: Optional[str] = None, + attachment_key: str = "modelbaker", + ) -> tuple[bool, str]: if self.schema and self._table_exists(PG_BASKET_TABLE): cur = self.conn.cursor() cur.execute( @@ -1277,7 +1282,7 @@ def edit_basket(self, basket_config: dict) -> tuple[bool, str]: 'Could not edit basket for topic "{}" and dataset "{}"' ).format(basket_config["topic"], basket_config["datasetname"]) - def get_tid_handling(self): + def get_tid_handling(self) -> dict: if self.schema and self._table_exists(PG_SETTINGS_TABLE): cur = self.conn.cursor() cur.execute( @@ -1297,7 +1302,7 @@ def get_tid_handling(self): return content[0] == "property" return False - def get_ili2db_settings(self): + def get_ili2db_settings(self) -> dict: result = {} if self._table_exists(PG_SETTINGS_TABLE): cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) @@ -1312,7 +1317,7 @@ def get_ili2db_settings(self): result = cur.fetchall() return result - def get_ili2db_sequence_value(self): + def get_ili2db_sequence_value(self) -> str: if self.schema: cur = self.conn.cursor() cur.execute( @@ -1327,7 +1332,7 @@ def get_ili2db_sequence_value(self): return content[0] return None - def get_next_ili2db_sequence_value(self): + def get_next_ili2db_sequence_value(self) -> str: if self.schema: cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) @@ -1344,7 +1349,7 @@ def get_next_ili2db_sequence_value(self): return content[0] return None - def set_ili2db_sequence_value(self, value): + def set_ili2db_sequence_value(self, value: str) -> tuple[bool, str]: if self.schema: cur = self.conn.cursor() try: @@ -1370,7 +1375,7 @@ def set_ili2db_sequence_value(self, value): return False, self.tr("Could not reset sequence") - def get_all_schemas(self): + def get_all_schemas(self) -> list[str]: cursor = self.conn.cursor() try: cursor.execute( @@ -1392,7 +1397,7 @@ def get_all_schemas(self): def get_translation_handling(self) -> tuple[bool, str]: return self._table_exists(PG_NLS_TABLE) and self._lang != "", self._lang - def get_translation_models(self): + def get_translation_models(self) -> list[str]: if self.schema and self._table_exists(PG_METAATTRS_TABLE): cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur.execute( @@ -1411,7 +1416,9 @@ def get_translation_models(self): return [row["ilielement"] for row in cur.fetchall()] return [] - def get_available_languages(self, irrelevant_models=[], relevant_models=[]): + def get_available_languages( + self, irrelevant_models: list[str], relevant_models: list[str] + ) -> list[str]: if self.schema and self._table_exists(PG_METAATTRS_TABLE): white_list_placeholders = sql.SQL("") @@ -1461,7 +1468,7 @@ def get_available_languages(self, irrelevant_models=[], relevant_models=[]): return [row["attr_value"] for row in cur.fetchall()] return [] - def get_domain_dispnames(self, tablename): + def get_domain_dispnames(self, tablename: str) -> list[dict]: if ( self.schema and self._table_exists diff --git a/modelbaker/generator/domain_relations_generator.py b/modelbaker/generator/domain_relations_generator.py index c9c78ceb..1ecce34a 100644 --- a/modelbaker/generator/domain_relations_generator.py +++ b/modelbaker/generator/domain_relations_generator.py @@ -12,6 +12,7 @@ """ import re +from typing import Optional from ..dataobjects.relations import Relation @@ -24,7 +25,7 @@ def __init__(self, db_connector, inheritance): self.inheritance = inheritance self.debug = False - def get_domain_relations_info(self, layers): + def get_domain_relations_info(self, layers: list) -> tuple[list[Relation], dict]: domains = [layer.name for layer in layers if layer.is_domain] if self.debug: print("domains:", domains) @@ -317,7 +318,9 @@ def get_domain_relations_info(self, layers): return (relations, bags_of_enum) - def parse_model(self, model_content, domains): + def parse_model( + self, model_content: str, domains: list[str] + ) -> tuple[dict, dict, dict]: re_comment = re.compile(r"\s*/\*") # /* comment re_end_comment = re.compile(r"\s*\*/") # comment */ re_oneline_comment = re.compile(r"\s*/\*.*\*/") # /* comment */ @@ -867,8 +870,8 @@ def parse_model(self, model_content, domains): return [models_info, extended_classes, bags_of_enum] def extract_local_names_from_domains( - self, domains, current_model, current_topic="" - ): + self, domains: list[str], current_model: str, current_topic: str = "" + ) -> dict: """ ili files may contain fully qualified domains assigned to attributes, but if domains are local (domain or topic-wise), domains might be assigned only @@ -897,8 +900,13 @@ def extract_local_names_from_domains( return local_names def make_full_qualified( - self, name, level, current_model, current_topic, current_class=None - ): + self, + name: str, + level: str, + current_model: str, + current_topic: str, + current_class: Optional[str] = None, + ) -> str: parents = [current_model, current_topic, current_class] len_parents = len(parents) name_parts = name.split(".") @@ -908,7 +916,9 @@ def make_full_qualified( return ".".join(name_parts) - def get_ext_dom_attrs(self, iliclass, models_info, extended_classes, inheritance): + def get_ext_dom_attrs( + self, iliclass: str, models_info: dict, extended_classes: dict, inheritance: str + ) -> dict: if inheritance == "smart1": # Use smart 2 first to get domain attributes from parents (we # really need them) and only then use smart 1 @@ -933,7 +943,9 @@ def get_ext_dom_attrs(self, iliclass, models_info, extended_classes, inheritance else: # No smart inheritance? return {} - def get_ext_dom_attrs_smart1(self, iliclass, models_info, extended_classes): + def get_ext_dom_attrs_smart1( + self, iliclass: str, models_info: dict, extended_classes: dict + ) -> dict: """ Returns a dict for input iliclass with its original attr:domain pairs plus all attr:domain pairs from children classes @@ -964,7 +976,9 @@ def get_ext_dom_attrs_smart1(self, iliclass, models_info, extended_classes): all_attrs[children_domain_attr] = domain return all_attrs - def get_ext_dom_attrs_smart2(self, iliclass, models_info, extended_classes): + def get_ext_dom_attrs_smart2( + self, iliclass: str, models_info: dict, extended_classes: dict + ) -> dict: """ Returns a dict for input iliclass with its original attr:domain pairs plus all inherited attr:domain pairs @@ -995,22 +1009,24 @@ def get_ext_dom_attrs_smart2(self, iliclass, models_info, extended_classes): return all_attrs - def _get_iliname_dbname_mapping(self, sqlnames): + def _get_iliname_dbname_mapping(self, sqlnames: list) -> dict: return self._db_connector.get_iliname_dbname_mapping(sqlnames) - def _get_models(self): + def _get_models(self) -> list: return self._db_connector.get_models() - def _get_meta_attrs(self, ilielement): + def _get_meta_attrs(self, ilielement: str) -> dict: return self._db_connector.get_meta_attrs(ilielement) - def _get_classili_classdb_mapping(self, models_info, extended_classes): + def _get_classili_classdb_mapping( + self, models_info: dict, extended_classes: dict + ) -> dict: return self._db_connector.get_classili_classdb_mapping( models_info, extended_classes ) - def _get_attrili_attrdb_mapping(self, models_info_with_ext): + def _get_attrili_attrdb_mapping(self, models_info_with_ext: dict) -> dict: return self._db_connector.get_attrili_attrdb_mapping(models_info_with_ext) - def _get_attrili_attrdb_mapping_by_owner(self, owners): + def _get_attrili_attrdb_mapping_by_owner(self, owners: list) -> dict: return self._db_connector.get_attrili_attrdb_mapping_by_owner(owners) diff --git a/modelbaker/generator/generator.py b/modelbaker/generator/generator.py index 2715056c..32e67231 100644 --- a/modelbaker/generator/generator.py +++ b/modelbaker/generator/generator.py @@ -14,9 +14,9 @@ from __future__ import annotations import re -from typing import Optional +from typing import Callable, Optional -from qgis.core import QgsApplication, QgsRelation, QgsWkbTypes +from qgis.core import Qgis, QgsApplication, QgsRelation, QgsWkbTypes from qgis.PyQt.QtCore import QCoreApplication, QLocale, QObject, pyqtSignal from ..dataobjects.fields import Field @@ -44,7 +44,7 @@ def __init__( inheritance: str, schema: Optional[str] = None, pg_estimated_metadata: bool = False, - parent: QObject = None, + parent: Optional[QObject] = None, mgmt_uri: Optional[str] = None, consider_basket_handling: bool = False, optimize_strategy: OptimizeStrategy = OptimizeStrategy.NONE, @@ -90,7 +90,7 @@ def print_messages(self) -> None: self.new_message.emit(message["level"], message["text"]) self.collected_print_messages.clear() - def append_print_message(self, level, text) -> None: + def append_print_message(self, level: Qgis.MessageLevel, text: str) -> None: message = {"level": level, "text": text} if message not in self.collected_print_messages: @@ -509,7 +509,9 @@ def layers(self, filter_layer_list: list = []) -> list[Layer]: return layers - def _rename_ambiguous_layers(self, layers, second_pass=False): + def _rename_ambiguous_layers( + self, layers: list[Layer], second_pass: bool = False + ) -> None: # rename ambiguous layers with topic (on not second_pass) or model (on second_pass) prefix # on irrelevant layers only if we don't ride OptimizeStrategy.HIDE or we do but on smart1 aliases = [ @@ -530,7 +532,9 @@ def _rename_ambiguous_layers(self, layers, second_pass=False): + layer.alias ) - def relations(self, layers, filter_layer_list=[]): + def relations( + self, layers, filter_layer_list: list[str] = [] + ) -> tuple[list[Relation], dict]: relations_info = self.get_relations_info(filter_layer_list) layer_map = dict() for layer in layers: @@ -661,7 +665,9 @@ def relations(self, layers, filter_layer_list=[]): return (relations, bags_of_enum) @staticmethod - def suppress_catalogue_reference_layers(available_layers, relations, bags_of_enum): + def suppress_catalogue_reference_layers( + available_layers: list[Layer], relations: list[Relation], bags_of_enum: dict + ) -> tuple[list[Layer], list[Relation]]: # Check for catalogue items and reference layers catalogue_items = [] # List of dicts catalogue_refs = [] # List of dicts @@ -730,7 +736,7 @@ def suppress_catalogue_reference_layers(available_layers, relations, bags_of_enu return available_layers, relations - def generate_node(self, layers, node_name, item_properties): + def generate_node(self, layers: list[Layer], node_name: str, item_properties: dict): if item_properties.get("group"): node = LegendGroup( QCoreApplication.translate("LegendGroup", node_name), @@ -741,7 +747,12 @@ def generate_node(self, layers, node_name, item_properties): layers.append(node) return node - def full_node(self, layers, item, path_resolver=lambda path: path): + def full_node( + self, + layers: list[Layer], + item: dict, + path_resolver: Callable[[str], str] = lambda path: path, + ) -> Layer | LegendGroup: current_node = None if item and isinstance(item, dict): current_node_name = next(iter(item)) @@ -842,12 +853,12 @@ def full_node(self, layers, item, path_resolver=lambda path: path): def legend( self, - layers, - ignore_node_names=None, - layertree_structure=None, - path_resolver=lambda path: path, - hide_systemlayers=False, - ): + layers: list[Layer], + ignore_node_names: bool = False, + layertree_structure: bool = False, + path_resolver: Callable[[str], str] = lambda path: path, + hide_systemlayers: bool = False, + ) -> LegendGroup: legend = LegendGroup( QCoreApplication.translate("LegendGroup", "root"), ignore_node_names=ignore_node_names, @@ -960,7 +971,11 @@ def legend( return legend - def _separated_legend_layers(self, layers): + def _separated_legend_layers( + self, layers: list[Layer] + ) -> tuple[ + list[Layer], list[Layer], list[Layer], list[Layer], list[Layer], list[Layer] + ]: domain_layers = [] table_layers = [] system_layers = [] @@ -1000,9 +1015,9 @@ def _separated_legend_layers(self, layers): def resolved_layouts( self, - layouts={}, - path_resolver=lambda path: path, - ): + layouts: dict = {}, + path_resolver: Callable[[str], str] = lambda path: path, + ) -> dict: resolved_layouts = {} for layout_name in layouts.keys(): resolved_layouts[layout_name] = {} @@ -1011,34 +1026,36 @@ def resolved_layouts( ) return resolved_layouts - def db_or_schema_exists(self): + def db_or_schema_exists(self) -> bool: return self._db_connector.db_or_schema_exists() - def metadata_exists(self): + def metadata_exists(self) -> bool: return self._db_connector.metadata_exists() - def set_additional_ignored_layers(self, layer_list): + def set_additional_ignored_layers(self, layer_list: list[str]) -> None: self._additional_ignored_layers = layer_list - def get_ignored_layers(self, ignore_basket_tables=True): + def get_ignored_layers(self, ignore_basket_tables: bool = True) -> list[str]: return ( self._db_connector.get_ignored_layers(ignore_basket_tables) + self._additional_ignored_layers ) - def get_tables_info(self): + def get_tables_info(self) -> list[dict]: return self._db_connector.get_tables_info() - def get_meta_attrs_info(self): + def get_meta_attrs_info(self) -> list[dict]: return self._db_connector.get_meta_attrs_info() - def get_meta_attrs(self, ili_name): + def get_meta_attrs(self, ili_name: str) -> list[dict]: return self._db_connector.get_meta_attrs(ili_name) - def get_fields_info(self, table_name): + def get_fields_info(self, table_name: str) -> list[dict]: return self._db_connector.get_fields_info(table_name) - def get_tables_info_without_ignored_tables(self, ignore_basket_tables=True): + def get_tables_info_without_ignored_tables( + self, ignore_basket_tables: bool = True + ) -> list[dict]: tables_info = self.get_tables_info() ignored_layers = self.get_ignored_layers(ignore_basket_tables) new_tables_info = [] @@ -1054,13 +1071,13 @@ def get_tables_info_without_ignored_tables(self, ignore_basket_tables=True): return new_tables_info - def get_min_max_info(self, table_name): + def get_min_max_info(self, table_name: str) -> dict: return self._db_connector.get_min_max_info(table_name) - def get_value_map_info(self, table_name): + def get_value_map_info(self, table_name: str) -> dict: return self._db_connector.get_value_map_info(table_name) - def get_tables_relevance(self): + def get_tables_relevance(self) -> dict: """ Returns a dict with relevance info per sqlname of class. """ @@ -1073,20 +1090,20 @@ def get_tables_relevance(self): return tables_relevance - def get_t_type_map_info(self, table_name): + def get_t_type_map_info(self, table_name: str) -> dict: return self._db_connector.get_t_type_map_info(table_name) - def get_relations_info(self, filter_layer_list=[]): + def get_relations_info(self, filter_layer_list: list[str] = []) -> list[dict]: return self._db_connector.get_relations_info(filter_layer_list) - def get_bags_of_info(self): + def get_bags_of_info(self) -> list[dict]: return self._db_connector.get_bags_of_info() - def get_iliname_dbname_mapping(self): + def get_iliname_dbname_mapping(self) -> list[dict]: return self._db_connector.get_iliname_dbname_mapping() - def get_basket_handling(self): + def get_basket_handling(self) -> bool: return self._db_connector.get_basket_handling() - def get_domain_dispnames(self, tablename): + def get_domain_dispnames(self, tablename: str) -> dict: return self._db_connector.get_domain_dispnames(tablename) diff --git a/modelbaker/ilitoppingmaker/ilidata.py b/modelbaker/ilitoppingmaker/ilidata.py index 0b7b0ba7..13432674 100644 --- a/modelbaker/ilitoppingmaker/ilidata.py +++ b/modelbaker/ilitoppingmaker/ilidata.py @@ -17,6 +17,7 @@ import uuid import xml.dom.minidom as minidom import xml.etree.ElementTree as ET +from typing import Optional from .ilitarget import IliTarget @@ -28,15 +29,15 @@ class DatasetMetadata: def __init__( self, - dataset_version: str = None, - publishing_date: str = None, - owner: str = None, - project_name: str = None, - id: str = None, - file_type: str = None, - file_path: str = None, + dataset_version: Optional[str] = None, + publishing_date: Optional[str] = None, + owner: Optional[str] = None, + project_name: Optional[str] = None, + id: Optional[str] = None, + file_type: Optional[str] = None, + file_path: Optional[str] = None, linking_models: list = [], - preferred_datasource: str = None, + preferred_datasource: Optional[str] = None, ): self.id = id self.file_type = file_type @@ -54,14 +55,14 @@ def __init__( self.short_description = f"QGIS {self.file_type} file for {self.project_name} - {os.path.splitext(os.path.basename(self.file_path))}" self.file_mimetype = self._file_mime_type(self.file_path) - def _file_mime_type(self, file_path: str = None) -> str: + def _file_mime_type(self, file_path: Optional[str] = None) -> str: mimetype = mimetypes.guess_type(file_path) if mimetype[0] is None: # ugly fallback return "text/plain" return mimetype[0] - def make_xml_element(self, element): + def make_xml_element(self, element: ET.Element) -> None: """ Generates the content of an element of DatasetIdx16.DataIndex.DatasetMetadata. """ @@ -136,7 +137,7 @@ def generate_file( self, target: IliTarget, linking_models: list = [], - preferred_datasource: str = None, + preferred_datasource: Optional[str] = None, ): """ Generates the ilidata.xml file containing all the toppingfile listed in the targets toppingfileinfo_list and writes it to the targets folders. diff --git a/modelbaker/ilitoppingmaker/iliprojecttopping.py b/modelbaker/ilitoppingmaker/iliprojecttopping.py index 4c49b3d1..1ef09b3f 100644 --- a/modelbaker/ilitoppingmaker/iliprojecttopping.py +++ b/modelbaker/ilitoppingmaker/iliprojecttopping.py @@ -11,6 +11,7 @@ (at your option) any later version. """ +from typing import Optional from qgis.core import Qgis, QgsExpressionContextUtils, QgsProject @@ -47,22 +48,22 @@ def __init__( self.preferred_datasource = None @property - def models(self): + def models(self) -> list: return self.metaconfig.ili2db_settings.models @property - def referencedata_paths(self): + def referencedata_paths(self) -> list: return self.metaconfig.referencedata_paths @models.setter - def models(self, models: list): + def models(self, models: list) -> None: self.metaconfig.ili2db_settings.models = models @referencedata_paths.setter - def referencedata_paths(self, paths: list): + def referencedata_paths(self, paths: list) -> None: self.metaconfig.referencedata_paths = paths - def makeit(self, project: QgsProject = None): + def makeit(self, project: Optional[QgsProject] = None) -> str: """ Creates everything - generates all the files. Returns the path to the ilidata.xml file. @@ -105,7 +106,7 @@ def makeit(self, project: QgsProject = None): return ilidata_path - def append_iliproperties(self, project): + def append_iliproperties(self, project: QgsProject) -> None: # append ilispecific properties like the optimize_strategy to the properties object optimize_strategy = QgsExpressionContextUtils.projectScope(project).variable( "optimize_strategy" diff --git a/modelbaker/ilitoppingmaker/ilitarget.py b/modelbaker/ilitoppingmaker/ilitarget.py index 97236be9..d4a271c9 100644 --- a/modelbaker/ilitoppingmaker/ilitarget.py +++ b/modelbaker/ilitoppingmaker/ilitarget.py @@ -15,6 +15,7 @@ import datetime import os import pathlib +from typing import Optional from ..libs.toppingmaker import Target from ..libs.toppingmaker.utils import slugify @@ -29,8 +30,8 @@ class IliTarget(Target): def __init__( self, projectname: str = "project", - main_dir: str = None, - sub_dir: str = None, + main_dir: Optional[str] = None, + sub_dir: Optional[str] = None, path_resolver=None, owner="owner", publishing_date=None, @@ -46,7 +47,7 @@ def __init__( self.default_version = version or datetime.datetime.now().strftime("%Y-%m-%d") @staticmethod - def ilidata_path_resolver(target, name, type): + def ilidata_path_resolver(target: Target, name: str, type: str) -> str: """ A path_resolver adding an id to the toppingfile in the toppingfile_list. @@ -67,7 +68,7 @@ def ilidata_path_resolver(target, name, type): return f"ilidata:{id}" @staticmethod - def unique_id_in_target_scope(target, id): + def unique_id_in_target_scope(target: Target, id: str) -> str: for toppingfileinfo in target.toppingfileinfo_list: if "id" in toppingfileinfo and toppingfileinfo["id"] == id: iterator = int(id[-3:]) diff --git a/modelbaker/ilitoppingmaker/metaconfig.py b/modelbaker/ilitoppingmaker/metaconfig.py index 67bdd0d0..c07ddc0b 100644 --- a/modelbaker/ilitoppingmaker/metaconfig.py +++ b/modelbaker/ilitoppingmaker/metaconfig.py @@ -14,7 +14,6 @@ import configparser import os -from typing import Union from ..libs.toppingmaker import ProjectTopping, Target from ..libs.toppingmaker.utils import slugify @@ -39,15 +38,15 @@ def __init__(self): self.metaconfigparamsonly = False self.ili2db_settings = Ili2dbSettings() - def update_referencedata_paths(self, value: Union[list, bool]): + def update_referencedata_paths(self, value: list | str | bool) -> None: if isinstance(value, str): value = [value] self.referencedata_paths.extend(value) - def update_projecttopping_path(self, value: str): + def update_projecttopping_path(self, value: str) -> None: self.projecttopping_path = value - def generate_files(self, target: Target): + def generate_files(self, target: Target) -> str: """ Example content: @@ -134,7 +133,7 @@ def generate_files(self, target: Target): return target.path_resolver(target, metaconfig_slug, MetaConfig.METACONFIG_TYPE) - def _generate_toppingfile_link(self, target: Target, type, path): + def _generate_toppingfile_link(self, target: Target, type: str, path: str) -> str: if not os.path.isfile(path): # it's already an id pointing to somewhere, no toppingfile needs to be created return path diff --git a/modelbaker/iliwrapper/ili2dbargs.py b/modelbaker/iliwrapper/ili2dbargs.py index 4e91f0ee..de561457 100644 --- a/modelbaker/iliwrapper/ili2dbargs.py +++ b/modelbaker/iliwrapper/ili2dbargs.py @@ -17,10 +17,12 @@ from ..utils.db_utils import get_authconfig_map from .globals import DbIliMode -from .ili2dbconfig import SchemaImportConfiguration +from .ili2dbconfig import Ili2DbCommandConfiguration, SchemaImportConfiguration -def get_ili2db_args(configuration, hide_password=False): +def get_ili2db_args( + configuration: Ili2DbCommandConfiguration, hide_password: bool = False +) -> list: """Gets a complete list of ili2db arguments in order to execute the app. Args: @@ -36,7 +38,9 @@ def get_ili2db_args(configuration, hide_password=False): return configuration.to_ili2db_args(db_args) -def _get_db_args(configuration, hide_password=False): +def _get_db_args( + configuration: Ili2DbCommandConfiguration, hide_password: bool = False +) -> list: su = configuration.db_use_super_login # Boolean db_args = list() @@ -133,7 +137,7 @@ def _get_db_args(configuration, hide_password=False): return db_args -def _get_schema_import_args(tool): +def _get_schema_import_args(tool: DbIliMode) -> list: args = list() if tool == DbIliMode.ili2pg: args += ["--setupPgExt"] diff --git a/modelbaker/iliwrapper/ili2dbconfig.py b/modelbaker/iliwrapper/ili2dbconfig.py index 92227b09..3d726bff 100644 --- a/modelbaker/iliwrapper/ili2dbconfig.py +++ b/modelbaker/iliwrapper/ili2dbconfig.py @@ -12,6 +12,7 @@ """ from qgis.core import QgsNetworkAccessManager +from qgis.PyQt.QtCore import QSettings from qgis.PyQt.QtNetwork import QNetworkProxy from .globals import DbIliMode @@ -31,7 +32,7 @@ def __init__(self): self.debugging_enabled = False - def save(self, settings): + def save(self, settings: QSettings) -> None: settings.setValue("SuperUser", self.super_pg_user) settings.setValue("SuperPassword", self.super_pg_password) settings.setValue("CustomDbParameters", self.dbparam_map) @@ -43,7 +44,7 @@ def save(self, settings): settings.setValue("LogfilePath", self.logfile_path) settings.setValue("DebuggingEnabled", self.debugging_enabled) - def restore(self, settings): + def restore(self, settings: QSettings) -> None: self.super_pg_user = settings.value("SuperUser", "postgres", str) self.super_pg_password = settings.value("SuperPassword", "postgres", str) self.dbparam_map = settings.value("CustomDbParameters", {}, dict) @@ -57,7 +58,9 @@ def restore(self, settings): self.debugging_enabled = settings.value("DebuggingEnabled", False, bool) self.logfile_path = settings.value("LogfilePath", "", str) - def to_ili2db_args(self, with_modeldir=True, with_usabilityhub_repo=False): + def to_ili2db_args( + self, with_modeldir: bool = True, with_usabilityhub_repo: bool = False + ) -> list: """ Create an ili2db command line argument string from this configuration """ @@ -85,7 +88,7 @@ def to_ili2db_args(self, with_modeldir=True, with_usabilityhub_repo=False): return args @property - def model_directories(self): + def model_directories(self) -> list: dirs = list() if self.custom_model_directories_enabled and self.custom_model_directories: dirs = self.custom_model_directories.split(";") @@ -99,7 +102,7 @@ def model_directories(self): return dirs @property - def ilidata_directories(self): + def ilidata_directories(self) -> list: dirs = list() if self.custom_model_directories_enabled and self.custom_model_directories: dirs = self.custom_model_directories.split(";") @@ -139,7 +142,13 @@ def __init__(self, other=None): # We got an 'other' object from which we'll get parameters self.__dict__ = other.__dict__.copy() - def append_args(self, args, values, consider_metaconfig=False, force_append=False): + def append_args( + self, + args: list[str], + values: list[str], + consider_metaconfig: bool = False, + force_append: bool = False, + ) -> None: """ Usually, there's no metaconfig, so we just add the value to the command's arguments. But if there is a metaconfig and the parameter isn't forced (i.e., it's not a technical parameter), we check: @@ -164,8 +173,7 @@ def append_args(self, args, values, consider_metaconfig=False, force_append=Fals return args += values - def to_ili2db_args(self): - + def to_ili2db_args(self) -> list: # Valid ili file, don't pass --modeldir (it can cause ili2db errors) with_modeldir = not self.ilifile @@ -201,7 +209,7 @@ def to_ili2db_args(self): class ExportConfiguration(Ili2DbCommandConfiguration): - def __init__(self, other: Ili2DbCommandConfiguration = None): + def __init__(self, other: Optional[Ili2DbCommandConfiguration] = None): super().__init__(other) self.xtffile = "" self.with_exporttid = False @@ -209,7 +217,9 @@ def __init__(self, other: Ili2DbCommandConfiguration = None): self.dataset = "" self.baskets = list() - def to_ili2db_args(self, extra_args=[], with_action=True): + def to_ili2db_args( + self, extra_args: list[str] = [], with_action: bool = True + ) -> list: args = list() self.append_args(args, extra_args) @@ -244,7 +254,7 @@ def to_ili2db_args(self, extra_args=[], with_action=True): class SchemaImportConfiguration(Ili2DbCommandConfiguration): - def __init__(self, other: Ili2DbCommandConfiguration = None): + def __init__(self, other: Optional[Ili2DbCommandConfiguration] = None): super().__init__(other) self.inheritance = "smart1" self.create_basket_col = False @@ -257,7 +267,9 @@ def __init__(self, other: Ili2DbCommandConfiguration = None): self.post_script = "" self.name_lang = "" - def to_ili2db_args(self, extra_args=[], with_action=True): + def to_ili2db_args( + self, extra_args: list[str] = [], with_action: bool = True + ) -> list: """ Create an ili2db argument array, with the password masked with ****** and optionally with the ``action`` argument (--schemaimport) removed. @@ -363,7 +375,7 @@ def to_ili2db_args(self, extra_args=[], with_action=True): class ImportDataConfiguration(SchemaImportConfiguration): - def __init__(self, other: Ili2DbCommandConfiguration = None): + def __init__(self, other: Optional[Ili2DbCommandConfiguration] = None): super().__init__(other) self.xtffile = "" self.delete_data = False @@ -375,7 +387,9 @@ def __init__(self, other: Ili2DbCommandConfiguration = None): # requires sqlEnableNull on schema: self.skip_reference_errors = False - def to_ili2db_args(self, extra_args=[], with_action=True): + def to_ili2db_args( + self, extra_args: list[str] = [], with_action: bool = True + ) -> list: args = list() if with_action: @@ -426,7 +440,7 @@ def to_ili2db_args(self, extra_args=[], with_action=True): class UpdateDataConfiguration(Ili2DbCommandConfiguration): - def __init__(self, other: Ili2DbCommandConfiguration = None): + def __init__(self, other: Optional[Ili2DbCommandConfiguration] = None): super().__init__(other) self.xtffile = "" self.dataset = "" @@ -436,7 +450,7 @@ def __init__(self, other: Ili2DbCommandConfiguration = None): # requires sqlEnableNull on schema: self.skip_reference_errors = False - def to_ili2db_args(self, extra_args=[], with_action=True): + def to_ili2db_args(self, extra_args: list[str] = [], with_action: bool = True): args = list() if with_action: @@ -470,7 +484,7 @@ def to_ili2db_args(self, extra_args=[], with_action=True): class ValidateConfiguration(Ili2DbCommandConfiguration): - def __init__(self, other: Ili2DbCommandConfiguration = None): + def __init__(self, other: Optional[Ili2DbCommandConfiguration] = None): super().__init__(other) self.ilimodels = "" self.topics = "" @@ -485,7 +499,7 @@ def __init__(self, other: Ili2DbCommandConfiguration = None): self.xtffile = "" self.plugins_dir = "" - def to_ili2db_args(self, extra_args=[], with_action=True): + def to_ili2db_args(self, extra_args: list[str] = [], with_action: bool = True): args = list() if with_action: @@ -539,12 +553,12 @@ def to_ili2db_args(self, extra_args=[], with_action=True): class DeleteConfiguration(Ili2DbCommandConfiguration): - def __init__(self, other: Ili2DbCommandConfiguration = None): + def __init__(self, other: Optional[Ili2DbCommandConfiguration] = None): super().__init__(other) self.dataset = "" self.baskets = "" - def to_ili2db_args(self, extra_args=[], with_action=True): + def to_ili2db_args(self, extra_args: list[str] = [], with_action: bool = True): args = list() if with_action: @@ -564,11 +578,11 @@ def to_ili2db_args(self, extra_args=[], with_action=True): class ExportMetaConfigConfiguration(Ili2DbCommandConfiguration): - def __init__(self, other: Ili2DbCommandConfiguration = None): + def __init__(self, other: Optional[Ili2DbCommandConfiguration] = None): super().__init__(other) self.metaconfigoutputfile = "" - def to_ili2db_args(self, extra_args=[], with_action=True): + def to_ili2db_args(self, extra_args: list[str] = [], with_action: bool = True): args = list() if with_action: diff --git a/modelbaker/iliwrapper/ili2dbtools.py b/modelbaker/iliwrapper/ili2dbtools.py index f792e677..07391efc 100644 --- a/modelbaker/iliwrapper/ili2dbtools.py +++ b/modelbaker/iliwrapper/ili2dbtools.py @@ -14,7 +14,7 @@ from .globals import DbIliMode -def get_tool_version(tool, db_ili_version): +def get_tool_version(tool, db_ili_version: int) -> str: if tool == DbIliMode.ili2gpkg: if db_ili_version == 3: return "3.11.3" @@ -34,7 +34,7 @@ def get_tool_version(tool, db_ili_version): return "0" -def get_tool_url(tool, db_ili_version): +def get_tool_url(tool: DbIliMode, db_ili_version: int) -> str: if tool == DbIliMode.ili2gpkg: return "https://downloads.interlis.ch/ili2gpkg/ili2gpkg-{version}.zip".format( version=get_tool_version(tool, db_ili_version) diff --git a/modelbaker/iliwrapper/ili2dbutils.py b/modelbaker/iliwrapper/ili2dbutils.py index 45fbe072..629a9c95 100644 --- a/modelbaker/iliwrapper/ili2dbutils.py +++ b/modelbaker/iliwrapper/ili2dbutils.py @@ -17,15 +17,18 @@ import subprocess import tempfile import zipfile +from typing import Callable, Optional -from qgis.PyQt.QtCore import QCoreApplication +from qgis.PyQt.QtCore import QCoreApplication, pyqtSignal from ..utils.qt_utils import NetworkError, download_file from .globals import DbIliMode -from .ili2dbtools import get_tool_url, get_tool_version +from .ili2dbtools import BaseConfiguration, get_tool_url, get_tool_version -def get_ili2db_bin(tool, db_ili_version, stdout, stderr): +def get_ili2db_bin( + tool: DbIliMode, db_ili_version: int, stdout: pyqtSignal, stderr: pyqtSignal +) -> Optional[str]: if tool not in DbIliMode or tool == DbIliMode.ili: raise RuntimeError("Tool {} not found".format(tool)) @@ -119,7 +122,9 @@ def get_ili2db_bin(tool, db_ili_version, stdout, stderr): return ili2db_file -def get_all_modeldir_in_path(path, lambdafunction=None): +def get_all_modeldir_in_path( + path: str, lambdafunction: Optional[Callable[[str], None]] = None +): all_subdirs = [path[0] for path in os.walk(path)] # include path # Make sure path is included, it can be a special string like `%XTF_DIR` modeldirs = [path] @@ -134,7 +139,7 @@ def get_all_modeldir_in_path(path, lambdafunction=None): return ";".join(modeldirs) -def get_java_path(base_configuration): +def get_java_path(base_configuration: BaseConfiguration) -> str: """ Delivers the path to a Java 8 installation or raises a JavaNotFoundError @@ -242,11 +247,11 @@ def getenv_system(varname, default=""): def is_version_valid( - current_version, - min_required_version, + current_version: str, + min_required_version: str, exact_required_version=False, - module_tested="", -): + module_tested: str = "", +) -> bool: """ Generic one, it helps us to validate whether a current version is greater or equal to a min_required_version or, if exact_required_version, if a current version is exactly the required one. @@ -316,14 +321,14 @@ def __init__(self, java_version=None): self.java_version = None @property - def html_java_version(self): + def html_java_version(self) -> str: if self.java_version: return "
".join(self.java_version.splitlines()) else: return "" @property - def error_string(self): + def error_string(self) -> str: if self.java_version: return QCoreApplication.translate( "ili2dbutils", diff --git a/modelbaker/iliwrapper/ilicache.py b/modelbaker/iliwrapper/ilicache.py index ec6a2b05..8bdfd109 100644 --- a/modelbaker/iliwrapper/ilicache.py +++ b/modelbaker/iliwrapper/ilicache.py @@ -18,6 +18,7 @@ import urllib.parse import xml.etree.ElementTree as ET from enum import Enum +from typing import Optional from qgis.core import Qgis, QgsMessageLog from qgis.PyQt.QtCore import ( @@ -32,6 +33,7 @@ from qgis.PyQt.QtWidgets import QGridLayout, QItemDelegate, QLabel, QStyle, QWidget from ..utils.qt_utils import download_file +from .ili2dbconfig import BaseConfiguration from .ili2dbutils import get_all_modeldir_in_path @@ -42,7 +44,9 @@ class IliCache(QObject): CACHE_PATH = os.path.expanduser("~/.ilicache") - def __init__(self, configuration, single_ili_file=None): + def __init__( + self, configuration: BaseConfiguration, single_ili_file: Optional[str] = None + ): QObject.__init__(self) self.information_file = "ilimodels.xml" self.repositories = dict() @@ -63,11 +67,11 @@ def __init__(self, configuration, single_ili_file=None): lambda: self.model.set_repositories(self.repositories) ) - def set_repositories_to_model(self): + def set_repositories_to_model(self) -> None: # hold refresh back self.modelReposTimer.start(500) - def refresh(self): + def refresh(self) -> None: if not self.directories is None: for directory in self.directories: self.process_model_directory(directory) @@ -76,7 +80,7 @@ def refresh(self): if os.path.exists(self.single_ili_file): self.process_single_ili_file() - def process_model_directory(self, path): + def process_model_directory(self, path: str) -> None: if path[0] == "%": pass else: @@ -87,14 +91,14 @@ def process_model_directory(self, path): # additional recursive search of paths containing ili files (without ilimodel.xml) get_all_modeldir_in_path(path, self.process_local_ili_folder) - def process_single_ili_file(self): + def process_single_ili_file(self) -> None: models = self.process_ili_file(self.single_ili_file) self.repositories["no_repo"] = sorted( models, key=lambda m: m["version"], reverse=True ) self.set_repositories_to_model() - def file_url(self, url, file): + def file_url(self, url: str, file: str) -> str: if url is None: return file elif os.path.isdir(url): @@ -102,7 +106,7 @@ def file_url(self, url, file): else: return urllib.parse.urljoin(url + "/", file) - def file_path(self, netloc, url, file): + def file_path(self, netloc: str, url: str, file: str) -> str: if url is None: return file elif os.path.isdir(url): @@ -111,7 +115,7 @@ def file_path(self, netloc, url, file): netloc = "" if netloc is None else netloc return os.path.join(self.CACHE_PATH, netloc, file) - def download_repository(self, url): + def download_repository(self, url: str) -> None: """ Downloads the informationfile (default: ilimodels.xml) and ilisite.xml files from the provided url and updates the local cache. @@ -170,13 +174,13 @@ def download_repository(self, url): ) @classmethod - def clear_cache(cls): + def clear_cache(cls) -> None: if not QDir().exists(cls.CACHE_PATH): return shutil.rmtree(cls.CACHE_PATH, ignore_errors=False, onerror=None) - def _process_ilisite(self, file): + def _process_ilisite(self, file: str) -> None: """ Parses the ilisite.xml provided in ``file`` and recursively downloads any subidiary sites. """ @@ -205,7 +209,7 @@ def _process_ilisite(self, file): if value: self.download_repository(value) - def _process_informationfile(self, file, netloc, url): + def _process_informationfile(self, file: str, netloc: str, url: str) -> None: """ Parses ilimodels.xml provided in ``file`` and updates the local repositories cache. """ @@ -267,7 +271,7 @@ def _process_informationfile(self, file, netloc, url): self.set_repositories_to_model() - def process_local_ili_folder(self, path): + def process_local_ili_folder(self, path: str) -> None: """ Parses all .ili files in the given ``path`` (non-recursively) """ @@ -283,7 +287,7 @@ def process_local_ili_folder(self, path): self.set_repositories_to_model() - def process_ili_file(self, ilifile): + def process_ili_file(self, ilifile: str) -> list: fileModels = list() try: fileModels = self.parse_ili_file(ilifile, "utf-8") @@ -319,7 +323,7 @@ def process_ili_file(self, ilifile): return fileModels - def parse_ili_file(self, ilipath, encoding): + def parse_ili_file(self, ilipath: str, encoding: str) -> list: """ Parses an ili file returning models and version data """ @@ -352,14 +356,14 @@ def parse_ili_file(self, ilipath, encoding): return models @property - def model_names(self): + def model_names(self) -> list: names = list() for repo in self.repositories.values(): for model in repo: names.append(model["name"]) return names - def get_element_text(self, element): + def get_element_text(self, element: ET.Element) -> str: if element is not None: return element.text return None @@ -376,7 +380,7 @@ def __int__(self): def __init__(self, parent=None): super().__init__(0, 1, parent) - def set_repositories(self, repositories): + def set_repositories(self, repositories: dict) -> None: self.clear() names = list() @@ -454,7 +458,13 @@ class IliDataCache(IliCache): CACHE_PATH = os.path.expanduser("~/.ilidatacache") - def __init__(self, configuration, type="metaconfig", models=None, datasources=[]): + def __init__( + self, + configuration: BaseConfiguration, + type: str = "metaconfig", + models: Optional[str] = None, + datasources: list[str] = [], + ): IliCache.__init__(self, configuration) self.information_file = "ilidata.xml" @@ -473,11 +483,11 @@ def __init__(self, configuration, type="metaconfig", models=None, datasources=[] ) self.datasources = datasources - def process_model_directory(self, path): + def process_model_directory(self, path: str) -> None: # download remote and local repositories self.download_repository(path) - def _process_informationfile(self, file, netloc, url): + def _process_informationfile(self, file: str, netloc: str, url: str) -> None: """ Parses ilidata.xml provided in ``file`` and updates the local repositories cache. """ @@ -683,7 +693,9 @@ def _process_informationfile(self, file, netloc, url): self.set_repositories_to_model() - def download_file(self, netloc, url, file, dataset_id=None): + def download_file( + self, netloc: str, url: str, file: str, dataset_id: Optional[str] = None + ) -> str: """ Downloads the given file from the given url to the local cache. passes the local file path or the id (for information) to signals. @@ -739,10 +751,10 @@ class Roles(Enum): def __int__(self): return self.value - def __init__(self, parent=None): + def __init__(self, parent=None) -> None: super().__init__(0, 1, parent) - def set_repositories(self, repositories): + def set_repositories(self, repositories: dict) -> None: self.beginResetModel() self.clear() ids = list() @@ -856,7 +868,12 @@ class IliToppingFileCache(IliDataCache): CACHE_PATH = os.path.expanduser("~/.ilitoppingfilescache") - def __init__(self, configuration, file_ids=None, tool_dir=None): + def __init__( + self, + configuration: BaseConfiguration, + file_ids: list[str] = [], + tool_dir: Optional[str] = None, + ): IliDataCache.__init__(self, configuration) self.model = IliToppingFileItemModel() self.sorted_model.setSourceModel(self.model) @@ -876,7 +893,7 @@ def __init__(self, configuration, file_ids=None, tool_dir=None): ) self.model.rowsInserted.connect(lambda: self.on_download_status(None)) - def refresh(self): + def refresh(self) -> None: if not self.directories is None: for directory in self.directories: self.process_model_directory(directory) @@ -913,7 +930,7 @@ def refresh(self): self.repositories[netloc] = repo_files self.set_repositories_to_model() - def on_download_status(self, dataset_id): + def on_download_status(self, dataset_id: str) -> None: # here we could add some more logic if dataset_id is not None: self.downloaded_files.append(dataset_id) @@ -921,7 +938,7 @@ def on_download_status(self, dataset_id): if len(self.downloaded_files) == len(self.file_ids) == self.model.rowCount(): self.download_finished_and_model_fresh.emit() - def _process_informationfile(self, file, netloc, url): + def _process_informationfile(self, file: str, netloc: str, url: str) -> None: """ Parses ilidata.xml provided in ``file`` and updates the local repositories cache. """ @@ -1010,7 +1027,7 @@ def __int__(self): def __init__(self, parent=None): super().__init__(0, 1, parent) - def set_repositories(self, repositories): + def set_repositories(self, repositories: dict) -> None: self.clear() ids = list() diff --git a/modelbaker/iliwrapper/iliexecutable.py b/modelbaker/iliwrapper/iliexecutable.py index c758bd5b..923c1e29 100644 --- a/modelbaker/iliwrapper/iliexecutable.py +++ b/modelbaker/iliwrapper/iliexecutable.py @@ -14,6 +14,7 @@ import locale import re from abc import abstractmethod +from typing import Optional from qgis.PyQt.QtCore import QEventLoop, QObject, QProcess, pyqtSignal @@ -61,10 +62,10 @@ def _create_config(self) -> Ili2DbCommandConfiguration: Returns: ili2db configuration""" - def _get_ili2db_version(self): + def _get_ili2db_version(self) -> int: return self.configuration.db_ili_version - def _args(self, hide_password): + def _args(self, hide_password: bool) -> list: """Gets the list of ili2db arguments from configuration. Args: @@ -76,7 +77,7 @@ def _args(self, hide_password): return get_ili2db_args(self.configuration, hide_password) - def _ili2db_jar_arg(self): + def _ili2db_jar_arg(self) -> list: ili2db_bin = get_ili2db_bin( self.tool, self._get_ili2db_version(), self.stdout, self.stderr ) @@ -84,14 +85,14 @@ def _ili2db_jar_arg(self): return self.ILI2DB_NOT_FOUND return ["-jar", ili2db_bin] - def _escaped_arg(self, argument): + def _escaped_arg(self, argument=str) -> str: if '"' in argument: argument = argument.replace('"', '"""') if " " in argument: argument = '"' + argument + '"' return argument - def command(self, hide_password): + def command(self, hide_password: bool = False) -> str: ili2db_jar_arg = self._ili2db_jar_arg() if ili2db_jar_arg == self.ILI2DB_NOT_FOUND: return "ili2db tool not found!" @@ -109,7 +110,7 @@ def command(self, hide_password): return command - def command_with_password(self, edited_command): + def command_with_password(self, edited_command: str) -> str: if "--dbpwd ******" in edited_command: args = self._args(False) i = args.index("--dbpwd") @@ -118,7 +119,7 @@ def command_with_password(self, edited_command): ) return edited_command - def command_without_password(self, edited_command=None): + def command_without_password(self, edited_command: Optional[str] = None) -> str: if not edited_command: return self.command(True) regex = re.compile("--dbpwd [^ ]*") @@ -127,7 +128,7 @@ def command_without_password(self, edited_command=None): edited_command = edited_command.replace(match.group(1), "--dbpwd ******") return edited_command - def run(self, edited_command=None): + def run(self, edited_command: Optional[str] = None) -> int: proc = QProcess() self.cancel_process.connect(proc.terminate) proc.readyReadStandardError.connect( @@ -164,7 +165,7 @@ def run(self, edited_command=None): self.process_finished.emit(proc.exitCode(), self.__result) return self.__result - def stderr_ready(self, proc): + def stderr_ready(self, proc: QProcess) -> None: text = bytes(proc.readAllStandardError()).decode(self.encoding) if self.__done_pattern.search(text): @@ -172,6 +173,6 @@ def stderr_ready(self, proc): self.stderr.emit(text) - def stdout_ready(self, proc): + def stdout_ready(self, proc: QProcess) -> None: text = bytes(proc.readAllStandardOutput()).decode(self.encoding) self.stdout.emit(text) diff --git a/modelbaker/iliwrapper/iliexporter.py b/modelbaker/iliwrapper/iliexporter.py index 23bfc314..c84fc1f7 100644 --- a/modelbaker/iliwrapper/iliexporter.py +++ b/modelbaker/iliwrapper/iliexporter.py @@ -22,10 +22,10 @@ def __init__(self, parent=None): def _create_config(self) -> Ili2DbCommandConfiguration: return ExportConfiguration() - def _get_ili2db_version(self): + def _get_ili2db_version(self) -> int: return self.version - def _args(self, hide_password): + def _args(self, hide_password: bool = False) -> list[str]: args = super()._args(hide_password) if self.version == 3 and "--export3" in args: diff --git a/modelbaker/iliwrapper/iliupdater.py b/modelbaker/iliwrapper/iliupdater.py index ebd9a8d0..1596fbef 100644 --- a/modelbaker/iliwrapper/iliupdater.py +++ b/modelbaker/iliwrapper/iliupdater.py @@ -22,5 +22,5 @@ class Updater(IliExecutable): def __init__(self, parent=None): super().__init__(parent) - def _create_config(self): + def _create_config(self) -> UpdateDataConfiguration: return UpdateDataConfiguration() diff --git a/modelbaker/iliwrapper/ilivalidator.py b/modelbaker/iliwrapper/ilivalidator.py index c65b887a..9795a9e0 100644 --- a/modelbaker/iliwrapper/ilivalidator.py +++ b/modelbaker/iliwrapper/ilivalidator.py @@ -26,13 +26,13 @@ def __init__(self, parent=None): super().__init__(parent) self.version = 4 - def _create_config(self): + def _create_config(self) -> ValidateConfiguration: return ValidateConfiguration() - def _get_ili2db_version(self): + def _get_ili2db_version(self) -> int: return self.version - def _args(self, hide_password): + def _args(self, hide_password: bool = False) -> list[str]: args = super()._args(hide_password) if self.version == 3 and "--export3" in args: @@ -71,12 +71,12 @@ def __init__(self): self.configuration = ValidateConfiguration() self.valid = False - def get_element_text(self, element): + def get_element_text(self, element: CET.Element) -> str: if element is not None: return element.text return None - def reload(self): + def reload(self) -> None: self.beginResetModel() if self.configuration.xtflog: try: diff --git a/modelbaker/utils/db_utils.py b/modelbaker/utils/db_utils.py index 9f1cc99f..f64a5374 100644 --- a/modelbaker/utils/db_utils.py +++ b/modelbaker/utils/db_utils.py @@ -15,18 +15,23 @@ from qgis.core import ( QgsApplication, QgsAuthMethodConfig, + QgsDataProvider, QgsDataSourceUri, QgsMessageLog, ) from ..db_factory.db_simple_factory import DbSimpleFactory from ..dbconnector.db_connector import DBConnectorError +from ..dbconnector.gpkg_connector import GPKGConnector +from ..dbconnector.mssql_connector import MssqlConnector +from ..dbconnector.pg_connector import PGConnector from ..iliwrapper.globals import DbIliMode +from ..iliwrapper.ili2dbconfig import Ili2DbCommandConfiguration from ..libs import pgserviceparser from .qt_utils import slugify -def get_schema_identificator_from_sourceprovider(provider): +def get_schema_identificator_from_sourceprovider(provider: QgsDataProvider) -> str: if provider.name() == "postgres" or provider.name() == "mssql": layer_source = QgsDataSourceUri(provider.dataSourceUri()) return slugify( @@ -37,7 +42,9 @@ def get_schema_identificator_from_sourceprovider(provider): return "" -def get_schema_identificator_from_configuration(configuration): +def get_schema_identificator_from_configuration( + configuration: Ili2DbCommandConfiguration, +) -> str: if configuration.tool == DbIliMode.pg or configuration.tool == DbIliMode.mssql: return slugify( f"{configuration.dbhost}_{configuration.database}_{configuration.dbschema}" @@ -47,7 +54,7 @@ def get_schema_identificator_from_configuration(configuration): return "" -def get_authconfig_map(authconfigid): +def get_authconfig_map(authconfigid: str) -> dict: # to get username and password from the authconfig auth_mgr = QgsApplication.authManager() auth_cfg = QgsAuthMethodConfig() @@ -55,7 +62,9 @@ def get_authconfig_map(authconfigid): return auth_cfg.configMap() -def get_configuration_from_sourceprovider(provider, configuration): +def get_configuration_from_sourceprovider( + provider: QgsDataProvider, configuration: Ili2DbCommandConfiguration +) -> tuple[bool, DbIliMode]: """ Determines the connection parameters from a layer source provider. On service in postgres it preferences the static parameters over the ones in the service file if available. @@ -109,7 +118,9 @@ def get_configuration_from_sourceprovider(provider, configuration): return valid, mode -def get_db_connector(configuration): +def get_db_connector( + configuration: Ili2DbCommandConfiguration, +) -> GPKGConnector | PGConnector | MssqlConnector: db_simple_factory = DbSimpleFactory() schema = configuration.dbschema @@ -140,7 +151,7 @@ def get_db_connector(configuration): return None -def db_ili_version(configuration): +def db_ili_version(configuration: Ili2DbCommandConfiguration) -> int: """ Returns the ili2db version the database has been created with or None if the database could not be detected as a ili2db database @@ -150,7 +161,7 @@ def db_ili_version(configuration): return db_connector.ili_version() -def get_service_names(): +def get_service_names() -> tuple[list[str], str]: """ Provides the names of the available services in the PostgreSQL connection service file. """ @@ -163,7 +174,7 @@ def get_service_names(): ) -def get_service_config(servicename: str): +def get_service_config(servicename: str) -> tuple[dict[str, str], str]: """ Provides the service configuration of a given service from the PostgreSQL connection service file. """ diff --git a/modelbaker/utils/globals.py b/modelbaker/utils/globals.py index 393504c9..a4913abf 100644 --- a/modelbaker/utils/globals.py +++ b/modelbaker/utils/globals.py @@ -108,7 +108,7 @@ class LogLevel(IntEnum): TOPPING = 4 -def default_log_function(text, level=LogLevel.INFO, silent=False): +def default_log_function(text, level=LogLevel.INFO, silent: bool = False) -> None: if silent: return if level == LogLevel.INFO: diff --git a/modelbaker/utils/ili2db_utils.py b/modelbaker/utils/ili2db_utils.py index 202993c1..5d63e0de 100644 --- a/modelbaker/utils/ili2db_utils.py +++ b/modelbaker/utils/ili2db_utils.py @@ -20,6 +20,7 @@ Ili2DbCommandConfiguration, ) from ..iliwrapper.ili2dbutils import JavaNotFoundError +from ..iliwrapper.iliexecutable import IliExecutable from ..utils.qt_utils import OverrideCursor @@ -41,7 +42,7 @@ def __init__(self): def delete_baskets( self, baskets: str, configuration: Ili2DbCommandConfiguration = None - ): + ) -> tuple[bool, str]: """ Args: @@ -78,7 +79,7 @@ def delete_baskets( def delete_dataset( self, dataset: str, configuration: Ili2DbCommandConfiguration = None - ): + ) -> tuple[bool, str]: """ Args: @@ -115,7 +116,7 @@ def delete_dataset( def export_metaconfig( self, ini_file: str, configuration: Ili2DbCommandConfiguration = None - ): + ) -> tuple[bool, str]: """ Args: @@ -153,7 +154,7 @@ def export_metaconfig( return res, msg - def _connect_ili_executable_signals(self, ili_executable): + def _connect_ili_executable_signals(self, ili_executable: IliExecutable) -> None: ili_executable.process_started.connect(self.process_started) ili_executable.stderr.connect(self.stderr) ili_executable.stdout.connect(self.stdout) @@ -162,7 +163,7 @@ def _connect_ili_executable_signals(self, ili_executable): ili_executable.process_started.connect(self._log_on_process_started) ili_executable.stderr.connect(self._log_on_stderr) - def _disconnect_ili_executable_signals(self, ili_executable): + def _disconnect_ili_executable_signals(self, ili_executable: IliExecutable) -> None: ili_executable.process_started.disconnect(self.process_started) ili_executable.stderr.disconnect(self.stderr) ili_executable.stdout.disconnect(self.stdout) @@ -171,8 +172,8 @@ def _disconnect_ili_executable_signals(self, ili_executable): ili_executable.process_started.disconnect(self._log_on_process_started) ili_executable.stderr.disconnect(self._log_on_stderr) - def _log_on_process_started(self, command): + def _log_on_process_started(self, command: str) -> None: self._log += command + "\n" - def _log_on_stderr(self, text): + def _log_on_stderr(self, text: str) -> None: self._log += text diff --git a/modelbaker/utils/qgis_utils.py b/modelbaker/utils/qgis_utils.py index 1bce5f21..9d632ca3 100644 --- a/modelbaker/utils/qgis_utils.py +++ b/modelbaker/utils/qgis_utils.py @@ -12,6 +12,8 @@ """ +from typing import Optional + from qgis.core import ( Qgis, QgsAttributeEditorContainer, @@ -19,6 +21,7 @@ QgsDefaultValue, QgsExpressionContextUtils, QgsFieldConstraints, + QgsLayerTreeGroup, QgsLayerTreeLayer, QgsLayerTreeNode, QgsMapLayer, @@ -36,14 +39,13 @@ ] # Anything else like geometry collections or plugin layers -def get_first_index_for_layer_type(layer_type, group, ignore_node_names=None): +def get_first_index_for_layer_type( + layer_type: str, group: QgsLayerTreeGroup, ignore_node_names: list = [str] +) -> int: """ Finds the first index (from top to bottom) in the layer tree where a specific layer type is found. This function works only for the given group. """ - if ignore_node_names is None: - ignore_node_names = [] - tree_nodes = group.children() for current, tree_node in enumerate(tree_nodes): @@ -73,7 +75,9 @@ def get_first_index_for_layer_type(layer_type, group, ignore_node_names=None): return None -def get_suggested_index_for_layer(layer, group, ignore_node_names=None): +def get_suggested_index_for_layer( + layer: QgsMapLayer, group: QgsLayerTreeGroup, ignore_node_names: list[str] = [] +) -> int: """ Returns the index where a layer can be inserted, taking other layer types into account. For instance, if a line layer is given, this function will @@ -100,7 +104,7 @@ def get_suggested_index_for_layer(layer, group, ignore_node_names=None): return index -def get_layer_type(layer): +def get_layer_type(layer: QgsMapLayer) -> str: """ To deal with all layer types, map their types to known values """ @@ -118,7 +122,9 @@ def get_layer_type(layer): return "unknown" -def get_group_non_recursive(group, group_name): +def get_group_non_recursive( + group: QgsLayerTreeGroup, group_name: str +) -> QgsLayerTreeGroup: groups = ( group.findGroups(False) if Qgis.QGIS_VERSION_INT >= 31800 @@ -132,7 +138,7 @@ def get_group_non_recursive(group, group_name): class QgisProjectUtils: - def __init__(self, project: QgsProject = None): + def __init__(self, project: Optional[QgsProject] = None): self.project = project def get_oid_settings(self): diff --git a/modelbaker/utils/qt_utils.py b/modelbaker/utils/qt_utils.py index ead40fb3..83091d26 100644 --- a/modelbaker/utils/qt_utils.py +++ b/modelbaker/utils/qt_utils.py @@ -16,6 +16,7 @@ import unicodedata from abc import ABCMeta from functools import partial +from typing import Callable, Optional from qgis.core import QgsNetworkAccessManager from qgis.PyQt.QtCore import ( @@ -28,10 +29,12 @@ QUrl, ) from qgis.PyQt.QtNetwork import QNetworkReply, QNetworkRequest -from qgis.PyQt.QtWidgets import QApplication, QFileDialog +from qgis.PyQt.QtWidgets import QApplication, QFileDialog, QLineEdit -def selectFileName(line_edit_widget, title, file_filter, parent): +def selectFileName( + line_edit_widget: QLineEdit, title: str, file_filter: str, parent +) -> None: filename, matched_filter = QFileDialog.getOpenFileName( parent, title, line_edit_widget.text(), file_filter ) @@ -39,11 +42,11 @@ def selectFileName(line_edit_widget, title, file_filter, parent): def make_file_selector( - widget, - title=QCoreApplication.translate("modelbaker", "Open File"), - file_filter=QCoreApplication.translate("modelbaker", "Any file (*)"), + widget: QLineEdit, + title: str = QCoreApplication.translate("modelbaker", "Open File"), + file_filter: str = QCoreApplication.translate("modelbaker", "Any file (*)"), parent=None, -): +) -> Callable: return partial( selectFileName, line_edit_widget=widget, @@ -54,14 +57,14 @@ def make_file_selector( def selectFileNameToSave( - line_edit_widget, - title, - file_filter, + line_edit_widget: QLineEdit, + title: str, + file_filter: str, parent, - extension, - extensions, - dont_confirm_overwrite, -): + extension: str, + extensions: list[str], + dont_confirm_overwrite: bool, +) -> None: filename, matched_filter = QFileDialog.getSaveFileName( parent, title, @@ -86,14 +89,14 @@ def selectFileNameToSave( def make_save_file_selector( - widget, - title=QCoreApplication.translate("modelbaker", "Open File"), - file_filter=QCoreApplication.translate("modelbaker", "Any file(*)"), + widget: QLineEdit, + title: str = QCoreApplication.translate("modelbaker", "Open File"), + file_filter: str = QCoreApplication.translate("modelbaker", "Any file(*)"), parent=None, - extension="", - extensions=None, - dont_confirm_overwrite=False, -): + extension: str = "", + extensions: list[str] = [], + dont_confirm_overwrite: bool = False, +) -> Callable: return partial( selectFileNameToSave, line_edit_widget=widget, @@ -106,7 +109,7 @@ def make_save_file_selector( ) -def selectFolder(line_edit_widget, title, parent): +def selectFolder(line_edit_widget: QLineEdit, title: str, parent) -> None: foldername = QFileDialog.getExistingDirectory( parent, title, line_edit_widget.text() ) @@ -114,10 +117,10 @@ def selectFolder(line_edit_widget, title, parent): def make_folder_selector( - widget, - title=QCoreApplication.translate("modelbaker", "Open Folder"), + widget: QLineEdit, + title: str = QCoreApplication.translate("modelbaker", "Open Folder"), parent=None, -): +) -> Callable: return partial(selectFolder, line_edit_widget=widget, title=title, parent=parent) @@ -141,8 +144,13 @@ def __init__(self, error_code, msg): def download_file( - url, filename, on_progress=None, on_finished=None, on_error=None, on_success=None -): + url: str, + filename: str, + on_progress: Optional[Callable[[int, int], None]] = None, + on_finished: Optional[Callable[[], None]] = None, + on_error: Optional[Callable[[str, str], None]] = None, + on_success: Optional[Callable[[], None]] = None, +) -> str: """ Will download the file from url to a local filename. The method will only return once it's finished.