From d830b92233b2f2c4a78d85fef357a831b72f9c39 Mon Sep 17 00:00:00 2001 From: Julien Date: Thu, 18 Apr 2024 18:59:47 +0200 Subject: [PATCH] wip --- qgis_deployment_toolbelt/jobs/generic_job.py | 8 +++-- .../jobs/job_plugins_downloader.py | 29 +++++++++++++++++-- .../jobs/job_splash_screen.py | 15 ++++++++-- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/qgis_deployment_toolbelt/jobs/generic_job.py b/qgis_deployment_toolbelt/jobs/generic_job.py index ef7207a9..cdb66bae 100644 --- a/qgis_deployment_toolbelt/jobs/generic_job.py +++ b/qgis_deployment_toolbelt/jobs/generic_job.py @@ -14,6 +14,7 @@ # Standard library import logging from collections.abc import Iterable +from functools import lru_cache from os import getenv from pathlib import Path @@ -146,13 +147,14 @@ def filter_profiles_folder( logger.error("No QGIS profile found in the downloaded folder.") return None + @lru_cache(maxsize=1024) def filter_profiles_on_rules( - self, li_downloaded_profiles: Iterable[QdtProfile] + self, li_qdt_profiles: Iterable[QdtProfile] ) -> tuple[list[QdtProfile], list[QdtProfile]]: """Evaluate profile regarding to its deployment rules. Args: - li_downloaded_profiles (Iterable[QdtProfile]): input list of QDT profiles + li_qdt_profiles (Iterable[QdtProfile]): input list of QDT profiles Returns: tuple[list[QdtProfile], list[QdtProfile]]: tuple of profiles that matched @@ -162,7 +164,7 @@ def filter_profiles_on_rules( li_profiles_unmatched = [] context_object = {"environment": environment_dict()} - for profile in li_downloaded_profiles: + for profile in li_qdt_profiles: if profile.rules is None: logger.debug(f"No rules to apply to {profile.name}") li_profiles_matched.append(profile) diff --git a/qgis_deployment_toolbelt/jobs/job_plugins_downloader.py b/qgis_deployment_toolbelt/jobs/job_plugins_downloader.py index 785edd44..8d3a114d 100644 --- a/qgis_deployment_toolbelt/jobs/job_plugins_downloader.py +++ b/qgis_deployment_toolbelt/jobs/job_plugins_downloader.py @@ -17,6 +17,8 @@ from pathlib import Path from shutil import copy2 +from git import Optional + # package from qgis_deployment_toolbelt.__about__ import __title_clean__ from qgis_deployment_toolbelt.jobs.generic_job import GenericJob @@ -79,7 +81,7 @@ def run(self) -> None: qdt_referenced_plugins = self.list_referenced_plugins( parent_folder=self.qdt_downloaded_repositories ) - if not len(qdt_referenced_plugins): + if qdt_referenced_plugins is None or not len(qdt_referenced_plugins): logger.info( f"No plugin found in profile.json files within {self.qdt_working_folder}" ) @@ -276,7 +278,9 @@ def download_remote_plugins( return downloaded_plugins, failed_plugins - def list_referenced_plugins(self, parent_folder: Path) -> list[QgisPlugin]: + def list_referenced_plugins( + self, parent_folder: Path + ) -> Optional[list[QgisPlugin]]: """Return a list of plugins referenced in profile.json files found within a \ parent folder and sorted by unique id with version. @@ -289,6 +293,27 @@ def list_referenced_plugins(self, parent_folder: Path) -> list[QgisPlugin]: unique_profiles_identifiers: list = [] all_profiles: list[QgisPlugin] = [] + # check of there are some profiles folders within the downloaded folder + profiles_folders = self.list_downloaded_profiles() + if profiles_folders is None: + logger.error("No QGIS profile found in the downloaded folder.") + return + + # filter out profiles that do not match the rules + profiles_matched, profiles_unmatched = self.filter_profiles_on_rules( + li_downloaded_profiles=self.list_downloaded_profiles() + ) + if not len(profiles_matched): + logger.debug( + "None of the downloaded profiles meet the deployment requirements." + ) + return + + logger.info( + f"Of the {len(self.list_downloaded_profiles())} profiles downloaded, " + f"{len(profiles_unmatched)} do not meet the conditions for deployment." + ) + profile_json_counter: int = 0 for profile_json in parent_folder.glob("**/*/profile.json"): # increment counter diff --git a/qgis_deployment_toolbelt/jobs/job_splash_screen.py b/qgis_deployment_toolbelt/jobs/job_splash_screen.py index 4df5c6fb..d0d665f4 100644 --- a/qgis_deployment_toolbelt/jobs/job_splash_screen.py +++ b/qgis_deployment_toolbelt/jobs/job_splash_screen.py @@ -73,13 +73,22 @@ def run(self) -> None: """Execute job logic.""" # check of there are some profiles folders within the downloaded folder downloaded_profiles = self.list_downloaded_profiles() - if downloaded_profiles is None or not len(downloaded_profiles): + + # filter out profiles that do not match the rules + profiles_matched, profiles_unmatched = self.filter_profiles_on_rules( + li_downloaded_profiles=downloaded_profiles + ) + if not len(profiles_matched): logger.warning( - f"Job {self.ID} ran successfully but that's because no QGIS profile has " - "been found in the QDT downloaded folder. Was the expected behavior?" + "None of the downloaded profiles meet the deployment requirements." ) return + logger.info( + f"Of the {len(downloaded_profiles)} profiles downloaded, " + f"{len(profiles_unmatched)} do not meet the conditions for deployment." + ) + # iterate over downloaded profiles for profile_downloaded in downloaded_profiles: logger.debug(