Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Apr 19, 2024
1 parent 8936eb1 commit d830b92
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
8 changes: 5 additions & 3 deletions qgis_deployment_toolbelt/jobs/generic_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
29 changes: 27 additions & 2 deletions qgis_deployment_toolbelt/jobs/job_plugins_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
)
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
15 changes: 12 additions & 3 deletions qgis_deployment_toolbelt/jobs/job_splash_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d830b92

Please sign in to comment.