diff --git a/.docker/docker-compose.gh.yml b/.docker/docker-compose.gh.yml index 77a46a6..ee43a84 100644 --- a/.docker/docker-compose.gh.yml +++ b/.docker/docker-compose.gh.yml @@ -1,4 +1,3 @@ -version: '3' services: postgres13: image: postgis/postgis:13-3.4-alpine diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index 5f261d9..b06b6c7 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false # keep for now, since 3.22 and 3.28 have different bases than 3.34+ matrix: - qgis_version: [release-3_22, release-3_28, 3.34, latest] + qgis_version: [release-3_22, release-3_28, '3.34', '3.40', latest] env: QGIS_TEST_VERSION: ${{ matrix.qgis_version }} steps: diff --git a/modelbaker/dataobjects/fields.py b/modelbaker/dataobjects/fields.py index 1a695f2..6d5002f 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: 2017-04-12 + 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 1e3f699..2464165 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 b0c6fea..65bc120 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: 2016-11-14 + 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 @@ -46,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, @@ -73,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 f60a93e..b26e6b6 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 @@ -34,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: Optional[list[str]] = [], static_sorting: bool = False, ) -> None: self.name = name diff --git a/modelbaker/dataobjects/project.py b/modelbaker/dataobjects/project.py index dfd5837..86a3b1c 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 5994f64..4fbc138 100644 --- a/modelbaker/db_factory/db_command_config_manager.py +++ b/modelbaker/db_factory/db_command_config_manager.py @@ -1,23 +1,20 @@ """ -/*************************************************************************** - 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 +from typing import Optional from ..iliwrapper.ili2dbconfig import ( Ili2DbCommandConfiguration, @@ -30,55 +27,51 @@ class DbCommandConfigManager(ABC): 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 """ def __init__(self, configuration: Ili2DbCommandConfiguration) -> None: - """ - :param configuration: Configuration object that will be managed. - :type configuration: :class:`Ili2DbCommandConfiguration` - """ self.configuration = configuration @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`). + """Gets database uri (connection string) for db connectors (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: + su (bool): *True* to use super user credentials, *False* otherwise. + qgis (bool): *True* to use qgis specific credentials (e.g. authcfg), *False* otherwise. + fallback_user (str): a username as fallback most possibly used when you want to pass your os account name to connect the database + + Returns: + str: 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: @@ -90,14 +83,8 @@ def get_ili2db_args(self, hide_password: bool = False) -> list[str]: @abstractmethod def save_config_in_qsettings(self) -> None: - """Saves configuration values related to database in QSettings. - - :return: None - """ + """Saves configuration values related to database in QSettings.""" @abstractmethod def load_config_from_qsettings(self) -> None: - """Loads configuration values related to database from Qsettings. - - :return: None - """ + """Loads configuration values related to database from Qsettings.""" diff --git a/modelbaker/db_factory/db_factory.py b/modelbaker/db_factory/db_factory.py index 536bf93..6e8bda8 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 @@ -32,14 +28,14 @@ class DbFactory(ABC): @abstractmethod def get_db_connector(self, uri: str, schema: Optional[str]) -> DBConnector: - """Returns an instance of connector to database (:class:`DBConnector`). + """Returns an instance of connector to database (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: + tuple[bool, str]: Connector (DBConnector): A connector to specific database.""" @abstractmethod def get_db_command_config_manager( @@ -47,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 (Ili2DbCommandConfiguration): Configuration object that will be managed. + + Returns: + tuple[bool, str]: 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: + tuple[bool, str]: A object that provides layer uri.""" @abstractmethod def pre_generate_project( @@ -68,27 +65,29 @@ 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 (Ili2DbCommandConfiguration): Configuration parameters with which will be executed the operation of generate project. + + Returns: + tuple[bool, str]: *True* and an empty message if the called method was succeeded, *False* and a warning message otherwise.""" @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. - :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: + configuration (Ili2DbCommandConfiguration): 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: + tuple[bool, str]: *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 @@ -96,10 +95,9 @@ 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: + field (Field): The field that will be customized + data_type: The type of field """ diff --git a/modelbaker/db_factory/db_simple_factory.py b/modelbaker/db_factory/db_simple_factory.py index 82b046c..0e16800 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 @@ -45,15 +41,16 @@ class DbSimpleFactory: - """Provides a single point (simple factory) to create a database factory (:class:`DbFactory`).""" + """Provides a single point (simple factory) to create a database factory (DbFactory).""" def create_factory(self, ili_mode: DbIliMode) -> Optional[DbFactory]: - """Creates an instance of :class:`DbFactory` based on ili_mode parameter. + """Creates an instance of DbFactory based on ili_mode parameter. + + Args: + ili_mode (DbIliMode): Value specifying which factory will be instantiated. - :param ili_mode: Value specifying which factory will be instantiated. - :type ili_mode: :class:`DbIliMode` - :return: A database factory - """ + Returns: + DbFactory: A database factory""" if not ili_mode: return None @@ -73,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() @@ -95,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: + 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 245f8ce..269974f 100644 --- a/modelbaker/db_factory/gpkg_command_config_manager.py +++ b/modelbaker/db_factory/gpkg_command_config_manager.py @@ -1,22 +1,20 @@ """ -/*************************************************************************** - 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 typing import Optional + from qgis.PyQt.QtCore import QSettings from ..iliwrapper.ili2dbconfig import Ili2DbCommandConfiguration @@ -27,10 +25,7 @@ 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. - - :ivar configuration object that will be managed - """ + based on a object configuration.""" _settings_base_path = "ili2gpkg/" @@ -38,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 428b999..270fbec 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 @@ -46,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/gpkg_layer_uri.py b/modelbaker/db_factory/gpkg_layer_uri.py index ee828fe..8b98b73 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 - ***************************************************************************/ +Metadata: + Creation Date: 2019-04-30 + Copyright: (C) 2019 by Yesid Polania + Contact: 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. * - * * - ***************************************************************************/ +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 @@ -22,8 +18,6 @@ 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. - - :ivar str uri: Database uri. """ def __init__(self, uri: str) -> None: diff --git a/modelbaker/db_factory/layer_uri.py b/modelbaker/db_factory/layer_uri.py index 3626aa4..3b1766d 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 @@ -22,15 +18,13 @@ 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. - - :ivar str uri: Database uri. - :ivar 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 @@ -38,7 +32,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/mssql_command_config_manager.py b/modelbaker/db_factory/mssql_command_config_manager.py index 75b08b1..952c924 100644 --- a/modelbaker/db_factory/mssql_command_config_manager.py +++ b/modelbaker/db_factory/mssql_command_config_manager.py @@ -1,22 +1,20 @@ """ -/*************************************************************************** - 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 typing import Optional + from qgis.PyQt.QtCore import QSettings from ..iliwrapper.ili2dbconfig import Ili2DbCommandConfiguration @@ -31,7 +29,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 72a86eb..d3d92ae 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 @@ -45,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/mssql_layer_uri.py b/modelbaker/db_factory/mssql_layer_uri.py index 61d4a55..f7e58d2 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 04b74d0..fd8054e 100644 --- a/modelbaker/db_factory/pg_command_config_manager.py +++ b/modelbaker/db_factory/pg_command_config_manager.py @@ -1,22 +1,20 @@ """ -/*************************************************************************** - 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 typing import Optional + from qgis.PyQt.QtCore import QSettings from ..iliwrapper.ili2dbconfig import Ili2DbCommandConfiguration @@ -28,10 +26,7 @@ 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. - - :ivar configuration object that will be managed - """ + based on a object configuration.""" _settings_base_path = "ili2pg/" @@ -39,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 a00071f..124f54a 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 @@ -71,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/db_factory/pg_layer_uri.py b/modelbaker/db_factory/pg_layer_uri.py index def9798..f18dca1 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 @@ -22,8 +18,6 @@ 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. - - :ivar str uri: Database uri. """ def __init__(self, uri: str) -> None: diff --git a/modelbaker/dbconnector/config.py b/modelbaker/dbconnector/config.py index 1a0f6dc..f4e3d04 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 ed5f286..2e43a21 100644 --- a/modelbaker/dbconnector/db_connector.py +++ b/modelbaker/dbconnector/db_connector.py @@ -1,21 +1,18 @@ """ -/*************************************************************************** - 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 typing import Optional from qgis.PyQt.QtCore import QObject, pyqtSignal @@ -41,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. """ @@ -54,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 - 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 + return 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 + return 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 - def get_tables_info(self): + def get_tables_info(self) -> list[dict]: """ Info about tables found in the database (or database schema). @@ -96,7 +93,7 @@ def get_tables_info(self): """ return [] - def get_meta_attrs_info(self): + def get_meta_attrs_info(self) -> list[dict]: """ Info about meta attributes @@ -108,9 +105,9 @@ def get_meta_attrs_info(self): attr_name attr_value """ - raise NotImplementedError + return [] - 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 @@ -123,7 +120,7 @@ def get_meta_attr(self, ili_name): """ return [] - 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. @@ -143,7 +140,7 @@ def get_fields_info(self, table_name): """ return [] - 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. @@ -153,7 +150,7 @@ def get_min_max_info(self, table_name): """ return {} - 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. @@ -163,7 +160,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: """ Info about available types of a given smart1-inherited table. @@ -173,7 +170,7 @@ def get_t_type_map_info(self, table_name): """ return {} - 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). @@ -193,7 +190,7 @@ def get_relations_info(self, filter_layer_list=[]): """ return [] - 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). @@ -210,7 +207,7 @@ def get_bags_of_info(self): """ return [] - 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. @@ -265,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) -> list[dict]: """ Returns the models in use, the ili-file content and the direct parents of the model. """ - return {} + 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: @@ -316,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: @@ -328,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 ... @@ -355,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. @@ -366,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. @@ -374,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 """ @@ -396,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) -> bool: """ 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 {} + return False - 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 """ @@ -455,21 +458,23 @@ 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 [] - 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() @@ -487,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 520864d..e07bed5 100644 --- a/modelbaker/dbconnector/gpkg_connector.py +++ b/modelbaker/dbconnector/gpkg_connector.py @@ -1,25 +1,22 @@ """ -/*************************************************************************** - 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 import sqlite3 import uuid +from typing import Optional import qgis.utils from qgis.core import Qgis @@ -59,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 @@ -497,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( @@ -517,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() @@ -619,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() @@ -649,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(): @@ -690,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) + "'" @@ -704,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) + "'" @@ -718,9 +711,9 @@ def get_attrili_attrdb_mapping_by_owner(self, owners): ) return cursor - def get_models(self): + def get_models(self) -> list[dict]: if not self._table_exists("T_ILI2DB_TRAFO"): - return {} + return [] # Get MODELS cursor = self.conn.cursor() @@ -760,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() @@ -783,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( @@ -801,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( @@ -822,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( @@ -837,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: @@ -898,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 ): @@ -935,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( @@ -987,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() @@ -1007,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( @@ -1108,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) -> bool: if self._table_exists(GPKG_SETTINGS_TABLE): cursor = self.conn.cursor() cursor.execute( @@ -1126,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() @@ -1197,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( @@ -1213,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, @@ -1221,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() @@ -1261,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 [] @@ -1271,7 +1268,7 @@ def get_translation_models(self): SELECT DISTINCT ilielement FROM "{t_ili2db_meta_attrs}" - WHERE + WHERE attr_name = 'ili2db.ili.translationOf' ; """.format( @@ -1282,11 +1279,13 @@ 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 [] - white_list_restriction = '' + white_list_restriction = "" if len(relevant_models) > 0: white_list_restriction = """ AND @@ -1296,7 +1295,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 +1310,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} @@ -1326,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 a4f15a1..acd692f 100644 --- a/modelbaker/dbconnector/mssql_connector.py +++ b/modelbaker/dbconnector/mssql_connector.py @@ -1,23 +1,19 @@ """ -/*************************************************************************** - 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 import re +from typing import Optional import pyodbc from qgis.core import Qgis @@ -57,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 @@ -68,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( @@ -616,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( @@ -638,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: @@ -742,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 @@ -767,9 +763,9 @@ def get_iliname_dbname_mapping(self, sqlnames=list()): return result - def get_models(self): + def get_models(self) -> list[dict]: if not self._table_exists("t_ili2db_trafo"): - return {} + return [] # Get MODELS if self.schema: @@ -812,7 +808,7 @@ def get_models(self): list_result.append(result) result = dict() return list_result - return {} + return [] def get_classili_classdb_mapping(self, models_info, extended_classes): result = {} @@ -834,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() @@ -851,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() @@ -877,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) @@ -899,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( @@ -916,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() @@ -938,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() @@ -952,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: @@ -1001,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 @@ -1027,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() @@ -1092,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( @@ -1184,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) -> bool: if self.schema and self._table_exists(SETTINGS_TABLE): cur = self.conn.cursor() cur.execute( @@ -1201,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() @@ -1215,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( @@ -1234,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: @@ -1260,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( @@ -1268,7 +1268,7 @@ def get_translation_models(self): SELECT DISTINCT ilielement FROM {schema}.t_ili2db_meta_attrs - WHERE + WHERE attr_name = 'ili2db.ili.translationOf' """ ).format( @@ -1277,10 +1277,12 @@ 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 = '' + white_list_restriction = "" if len(relevant_models) > 0: white_list_restriction = """ AND @@ -1290,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 diff --git a/modelbaker/dbconnector/pg_connector.py b/modelbaker/dbconnector/pg_connector.py index 3b564c5..d90f021 100644 --- a/modelbaker/dbconnector/pg_connector.py +++ b/modelbaker/dbconnector/pg_connector.py @@ -1,23 +1,19 @@ """ -/*************************************************************************** - 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 +from typing import Optional import psycopg2 import psycopg2.extras @@ -55,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() @@ -81,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( @@ -95,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) @@ -655,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 @@ -686,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( @@ -709,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) @@ -798,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( @@ -825,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(): @@ -875,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) @@ -897,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) @@ -919,9 +915,9 @@ def get_attrili_attrdb_mapping_by_owner(self, owners): return {} - def get_models(self): + def get_models(self) -> list[dict]: if not self._table_exists("t_ili2db_trafo"): - return {} + return [] # Get MODELS if self.schema: @@ -968,9 +964,9 @@ def get_models(self): result = dict() return list_result - return {} + return [] - def ili_version(self): + def ili_version(self) -> str: cur = self.conn.cursor() cur.execute( """ @@ -991,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( @@ -1011,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( @@ -1034,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( @@ -1048,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: @@ -1097,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") @@ -1136,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( @@ -1184,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( @@ -1282,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) -> bool: if self.schema and self._table_exists(PG_SETTINGS_TABLE): cur = self.conn.cursor() cur.execute( @@ -1302,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) @@ -1317,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( @@ -1332,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) @@ -1349,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: @@ -1375,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( @@ -1397,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( @@ -1406,7 +1406,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 +1416,15 @@ 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('') + + 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 +1433,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,12 +1463,12 @@ 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 [] - 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 6513350..1ecce34 100644 --- a/modelbaker/generator/domain_relations_generator.py +++ b/modelbaker/generator/domain_relations_generator.py @@ -1,22 +1,18 @@ """ -/*************************************************************************** - 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 typing import Optional from ..dataobjects.relations import Relation @@ -29,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) @@ -322,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 */ @@ -872,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 @@ -902,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(".") @@ -913,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 @@ -938,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 @@ -969,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 @@ -1000,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 e66253f..88c9a69 100644 --- a/modelbaker/generator/generator.py +++ b/modelbaker/generator/generator.py @@ -1,27 +1,22 @@ """ -/*************************************************************************** - 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 -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 @@ -49,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, @@ -57,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 @@ -95,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: @@ -514,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 = [ @@ -535,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: @@ -666,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 @@ -735,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), @@ -746,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)) @@ -847,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: list[str] = [], + 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, @@ -965,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 = [] @@ -1005,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] = {} @@ -1016,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 = [] @@ -1059,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. """ @@ -1078,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/__init__.py b/modelbaker/ilitoppingmaker/__init__.py index 9e693e6..2e8535f 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 e34221f..5131aab 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 b4bbcd5..1343267 100644 --- a/modelbaker/ilitoppingmaker/ilidata.py +++ b/modelbaker/ilitoppingmaker/ilidata.py @@ -1,27 +1,23 @@ """ -/*************************************************************************** - ------------------- - 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 import xml.dom.minidom as minidom import xml.etree.ElementTree as ET +from typing import Optional from .ilitarget import IliTarget @@ -33,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 @@ -59,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. """ @@ -141,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 286c167..1ef09b3 100644 --- a/modelbaker/ilitoppingmaker/iliprojecttopping.py +++ b/modelbaker/ilitoppingmaker/iliprojecttopping.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. """ +from typing import Optional from qgis.core import Qgis, QgsExpressionContextUtils, QgsProject @@ -53,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. @@ -111,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 51bac2c..d4a271c 100644 --- a/modelbaker/ilitoppingmaker/ilitarget.py +++ b/modelbaker/ilitoppingmaker/ilitarget.py @@ -1,25 +1,21 @@ """ -/*************************************************************************** - ------------------- - 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 +from typing import Optional from ..libs.toppingmaker import Target from ..libs.toppingmaker.utils import slugify @@ -34,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, @@ -51,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. @@ -72,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 dfae78d..c07ddc0 100644 --- a/modelbaker/ilitoppingmaker/metaconfig.py +++ b/modelbaker/ilitoppingmaker/metaconfig.py @@ -1,25 +1,19 @@ """ -/*************************************************************************** - ------------------- - 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 from ..libs.toppingmaker import ProjectTopping, Target from ..libs.toppingmaker.utils import slugify @@ -44,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: @@ -139,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/globals.py b/modelbaker/iliwrapper/globals.py index 80e1101..b933512 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 eb23b98..de56145 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 @@ -23,16 +17,19 @@ 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. - :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: @@ -41,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() @@ -138,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 487d832..72c0345 100644 --- a/modelbaker/iliwrapper/ili2dbconfig.py +++ b/modelbaker/iliwrapper/ili2dbconfig.py @@ -1,23 +1,20 @@ """ -/*************************************************************************** - ------------------- - 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 typing import Optional + from qgis.core import QgsNetworkAccessManager +from qgis.PyQt.QtCore import QSettings from qgis.PyQt.QtNetwork import QNetworkProxy from .globals import DbIliMode @@ -37,7 +34,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) @@ -49,7 +46,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) @@ -63,7 +60,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 """ @@ -91,7 +90,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(";") @@ -105,7 +104,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(";") @@ -145,7 +144,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: @@ -170,8 +175,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 @@ -207,7 +211,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 @@ -215,7 +219,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) @@ -250,7 +256,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 @@ -263,7 +269,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. @@ -369,7 +377,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 @@ -381,7 +389,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: @@ -432,7 +442,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 = "" @@ -442,7 +452,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: @@ -476,7 +486,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 = "" @@ -491,7 +501,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: @@ -545,12 +555,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: @@ -570,11 +580,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 2d24754..07391ef 100644 --- a/modelbaker/iliwrapper/ili2dbtools.py +++ b/modelbaker/iliwrapper/ili2dbtools.py @@ -1,26 +1,20 @@ """ -/*************************************************************************** - ------------------- - 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 -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" @@ -40,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 de58d72..8108171 100644 --- a/modelbaker/iliwrapper/ili2dbutils.py +++ b/modelbaker/iliwrapper/ili2dbutils.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - ------------------- - 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. """ +from __future__ import annotations + import glob import os import platform @@ -23,15 +19,22 @@ import subprocess import tempfile import zipfile +from typing import TYPE_CHECKING, 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 +if TYPE_CHECKING: + # only needed for type checking to avoid circular imports + from .ili2dbconfig import BaseConfiguration + -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)) @@ -125,7 +128,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] @@ -140,7 +145,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 @@ -248,24 +253,25 @@ 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. + 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: + bool: Whether the current version is valid or not""" if current_version is None: return False @@ -321,14 +327,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 37856a1..9bfa546 100644 --- a/modelbaker/iliwrapper/ilicache.py +++ b/modelbaker/iliwrapper/ilicache.py @@ -1,21 +1,17 @@ """ -/*************************************************************************** - ------------------- - 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. """ +from __future__ import annotations + import glob import logging import os @@ -24,6 +20,7 @@ import urllib.parse import xml.etree.ElementTree as ET from enum import Enum +from typing import TYPE_CHECKING, Optional from qgis.core import Qgis, QgsMessageLog from qgis.PyQt.QtCore import ( @@ -40,6 +37,10 @@ from ..utils.qt_utils import download_file from .ili2dbutils import get_all_modeldir_in_path +if TYPE_CHECKING: + # only needed for type checking to avoid circular imports + from .ili2dbconfig import BaseConfiguration + class IliCache(QObject): ns = {"ili23": "http://www.interlis.ch/INTERLIS2.3"} @@ -48,7 +49,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() @@ -69,11 +72,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) @@ -82,7 +85,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: @@ -93,14 +96,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): @@ -108,7 +111,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): @@ -117,7 +120,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. @@ -176,13 +179,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. """ @@ -211,7 +214,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. """ @@ -273,7 +276,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) """ @@ -289,7 +292,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") @@ -325,7 +328,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 """ @@ -358,14 +361,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 @@ -382,7 +385,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() @@ -460,7 +463,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" @@ -479,11 +488,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. """ @@ -689,7 +698,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. @@ -745,10 +756,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() @@ -862,7 +873,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) @@ -882,7 +898,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) @@ -919,7 +935,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) @@ -927,7 +943,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. """ @@ -1016,7 +1032,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/ilideleter.py b/modelbaker/iliwrapper/ilideleter.py index 1f10bfa..7a24dbd 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 0839dc5..91986df 100644 --- a/modelbaker/iliwrapper/iliexecutable.py +++ b/modelbaker/iliwrapper/iliexecutable.py @@ -1,24 +1,20 @@ """ -/*************************************************************************** - 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 import re from abc import abstractmethod +from typing import Optional from qgis.PyQt.QtCore import QEventLoop, QObject, QProcess, pyqtSignal @@ -63,23 +59,25 @@ def __init__(self, parent=None): def _create_config(self) -> Ili2DbCommandConfiguration: """Creates the configuration that will be used by *run* method. - :return: ili2db configuration""" + Returns: + Ili2DbCommandConfiguration: 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. - :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) - 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 ) @@ -87,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!" @@ -112,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") @@ -121,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 [^ ]*") @@ -130,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( @@ -167,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): @@ -175,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 87677b8..c84fc1f 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 @@ -28,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/iliimporter.py b/modelbaker/iliwrapper/iliimporter.py index 3ed2849..6c46a92 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 25dba56..4d6979b 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 e6eea18..1596fbe 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. """ @@ -28,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 94781a5..9795a9e 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 @@ -32,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: @@ -77,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/processing/ili2db_exporting.py b/modelbaker/processing/ili2db_exporting.py index 5ef17d3..84aaf55 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 4af4882..bb50ffd 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 bb1ec0a..c2254fc 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 2977547..ba24b07 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 2579084..339b6e7 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 871b92a..d085369 100644 --- a/modelbaker/utils/db_utils.py +++ b/modelbaker/utils/db_utils.py @@ -1,24 +1,25 @@ """ -/*************************************************************************** - 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 __future__ import annotations + +from typing import TYPE_CHECKING + from qgis.core import ( QgsApplication, QgsAuthMethodConfig, + QgsDataProvider, QgsDataSourceUri, QgsMessageLog, ) @@ -29,8 +30,15 @@ from ..libs import pgserviceparser from .qt_utils import slugify +if TYPE_CHECKING: + # only needed for type checking to avoid circular imports + from ..dbconnector.gpkg_connector import GPKGConnector + from ..dbconnector.mssql_connector import MssqlConnector + from ..dbconnector.pg_connector import PGConnector + from ..iliwrapper.ili2dbconfig import Ili2DbCommandConfiguration + -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( @@ -41,7 +49,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}" @@ -51,7 +61,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() @@ -59,14 +69,15 @@ 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. + Gets a configuration (Ili2DbCommandConfiguration) with the determined parameters Returns: - valid (boolean): if the needed database connection parameters are determined - mode (DbIliMode): Kind of database like pg, gpkg or mssql - configuration (Ili2DbCommandConfiguration): config with the determined parameters + tuple[[bool, DbIliMode]: if the needed database connection parameters are determined and the kind of database like pg, gpkg or mssql """ mode = "" valid = False @@ -113,7 +124,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 @@ -144,7 +157,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 @@ -154,7 +167,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. """ @@ -167,7 +180,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 ffcf8d3..a4913ab 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 = [ @@ -113,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 bcc5bb0..8332dfa 100644 --- a/modelbaker/utils/ili2db_utils.py +++ b/modelbaker/utils/ili2db_utils.py @@ -1,21 +1,20 @@ """ -/*************************************************************************** - ------------------- - 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 __future__ import annotations + +from typing import TYPE_CHECKING + from qgis.PyQt.QtCore import QObject, Qt, pyqtSignal from ..iliwrapper import ilideleter, ilimetaconfigexporter @@ -27,6 +26,10 @@ from ..iliwrapper.ili2dbutils import JavaNotFoundError from ..utils.qt_utils import OverrideCursor +if TYPE_CHECKING: + # only needed for type checking to avoid circular imports + from ..iliwrapper.iliexecutable import IliExecutable + class Ili2DbUtils(QObject): """ @@ -46,12 +49,15 @@ def __init__(self): 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 + ) -> tuple[bool, str]: """ + + Args: + baskets: Semicolon-separated list of baskets to be deleted + configuration: Base Ili2DbCommandConfiguration object + + Returns: + tuple[bool, str]: Tuple with boolean result and optional message""" deleter = ilideleter.Deleter() deleter.tool = configuration.tool deleter.configuration = DeleteConfiguration(configuration) @@ -80,12 +86,15 @@ def delete_baskets( 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 + ) -> tuple[bool, str]: """ + + Args: + configuration: Base Ili2DbCommandConfiguration object + dataset: Dataset id to be deleted + + Returns: + tuple[bool, str]: Tuple with boolean result and optional message""" deleter = ilideleter.Deleter() deleter.tool = configuration.tool deleter.configuration = DeleteConfiguration(configuration) @@ -114,12 +123,15 @@ def delete_dataset( 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 + ) -> tuple[bool, str]: """ + + Args: + configuration: Base Ili2DbCommandConfiguration object + ini_file: Output file + + Returns: + tuple[bool, str]: Tuple with boolean result and optional message""" metaconfig_exporter = ilimetaconfigexporter.MetaConfigExporter() metaconfig_exporter.tool = configuration.tool metaconfig_exporter.configuration = ExportMetaConfigConfiguration(configuration) @@ -149,7 +161,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) @@ -158,7 +170,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) @@ -167,8 +179,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 9375382..ddc5948 100644 --- a/modelbaker/utils/qgis_utils.py +++ b/modelbaker/utils/qgis_utils.py @@ -1,21 +1,19 @@ """ -/*************************************************************************** - 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 typing import Optional + from qgis.core import ( Qgis, QgsAttributeEditorContainer, @@ -23,6 +21,7 @@ QgsDefaultValue, QgsExpressionContextUtils, QgsFieldConstraints, + QgsLayerTreeGroup, QgsLayerTreeLayer, QgsLayerTreeNode, QgsMapLayer, @@ -40,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): @@ -77,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 @@ -104,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 """ @@ -122,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 @@ -136,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 f176131..83091d2 100644 --- a/modelbaker/utils/qt_utils.py +++ b/modelbaker/utils/qt_utils.py @@ -1,26 +1,22 @@ """ -/*************************************************************************** - ------------------- - 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 from abc import ABCMeta from functools import partial +from typing import Callable, Optional from qgis.core import QgsNetworkAccessManager from qgis.PyQt.QtCore import ( @@ -33,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 ) @@ -44,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, @@ -59,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, @@ -91,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, @@ -111,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() ) @@ -119,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) @@ -146,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. diff --git a/tests/test_dataset_handling.py b/tests/test_dataset_handling.py index 505fec0..b02f024 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 db43673..fa097fd 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 dbed030..3099a6f 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 7a2e9f0..058bac2 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 47951b5..502aba4 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 f0ee41f..06e4545 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 30ff5e8..883bff2 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 e5befd6..a3d2352 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 c9b5466..0644856 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 fa3e8e6..9fd7d30 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 269297c..26e5983 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 e551b09..e0b1753 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 a31593b..d2eef07 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 0f560c7..9618252 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 4fbb8af..c235aa3 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 3461f0c..0fb1285 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 d198798..f07bb7b 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 f723e5e..b533c6a 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 e754a27..1a9e754 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 4b8262f..60c8b0d 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 7db687a..674713b 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 290d039..7a5c3d1 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 df77c29..70447bb 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 d5e69be..35846ee 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 cc703fe..9057774 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 b42925f..3b4de89 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 3e64ae9..a4f0c3a 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