qgis_deployment_toolbelt.jobs.generic_job module¶
Base of QDT jobs.
Author: Julien Moura (https://github.com/guts)
- class qgis_deployment_toolbelt.jobs.generic_job.GenericJob¶
Bases:
ABCAbstract base for QDT jobs.
It provides the shared context (QDT working folders, QGIS profiles folder, operating system configuration, rules context) and helpers to list profiles and validate options. A concrete job must define:
ID, the identifier used in theuseskey of a scenario step;OPTIONS, the options accepted in thewithkey: aJobOptionssubclass (pydantic model), which validates them and applies their default values. Jobs not migrated yet define the legacyOPTIONS_SCHEMAdict instead, checked byvalidate_options();run(), called by the deployment command once the job is instantiated.
IDis declared as an abstract property so that a plain class attribute in the subclass implements it. A job declaring neitherOPTIONSnorOPTIONS_SCHEMAcan’t be instantiated.Example
class ExampleOptions(JobOptions): mode: Literal["fast", "safe"] = "safe" class JobExample(GenericJob): ID: str = "example-job" OPTIONS = ExampleOptions def __init__(self, options: dict) -> None: super().__init__() self.options = ExampleOptions.from_dict(options, job_id=self.ID) def run(self) -> None: ...
- OPTIONS: type[JobOptions] | None = None¶
Options accepted in the
withkey of a scenario step, validated withOPTIONS.from_dict. ReplacesOPTIONS_SCHEMA, being migrated job by job.
- OPTIONS_SCHEMA: dict[str, dict[str, Any]] | None = None¶
legacy declaration of the options, validated by
validate_options().
- __init__() None¶
Object instanciation.
- Raises:
TypeError – if the job declares neither
OPTIONSnorOPTIONS_SCHEMA
- _abc_impl = <_abc._abc_data object>¶
- _ensure_folder_exists(folder_path: Path, log_label: str | None = None) None¶
Create folder and its parents when it does not exist yet.
- Parameters:
folder_path (Path) – pat to directory to create if absent.
log_label (str | None, optional) – human-readable name used in the log message. Defaults to None
- _evaluate_profile_rules(profile: QdtProfile) bool | None¶
Evaluate the deployment rules of a profile against the rules context.
- Parameters:
profile (QdtProfile) – profile with rules to evaluate
- Returns:
- True if every rule matches, False otherwise. None if the
rules could not be evaluated, or are not met while some facts of the rules context are unavailable.
- Return type:
bool | None
- classmethod clear_profiles_cache(folder_path: Path | None = None) None¶
Invalidate the profiles-folder scan cache to make subsequent jobs re-scan the directory instead of returning cached data.
- Parameters:
folder_path (Path | None, optional) – specific cached folder to clear. If None, the entire cache is cleared. Defaults to None.
- filter_profiles_folder(start_parent_folder: Path, cached: bool = True, quiet: bool = False) tuple[QdtProfile, ...] | None¶
Parse a folder structure to filter on QGIS profiles folders.
- Parameters:
start_parent_folder (Path) – root directory to scan for profile.json files.
cached (bool, optional) – return the previously computed result when available. Defaults to True.
quiet (bool, optional) – if True, log the “no profile found” case as debug instead of error. Set this when an empty folder is an expected outcome rather than a failure condition for the calling job. Defaults to False.
- Returns:
- tuple of profiles objects matching criteria or
None if no profile folder found
- Return type:
tuple[QdtProfile, …] | None
- filter_profiles_on_deprecated_flag(tup_qdt_profiles: tuple[QdtProfile, ...]) tuple[list[QdtProfile], list[QdtProfile]]¶
Evaluate profiles against their optional deprecated attribute.
- Parameters:
tup_qdt_profiles (tuple[QdtProfile, ...]) – input tuple of QDT profiles
- Returns:
tuple of profiles that are active (not deprecated) and those which are deprecated
- Return type:
- filter_profiles_on_qdt_version(tup_qdt_profiles: tuple[QdtProfile, ...]) tuple[list[QdtProfile], list[QdtProfile]]¶
Evaluate profiles against their optional qdtMinVersion attribute.
- Parameters:
tup_qdt_profiles (tuple[QdtProfile, ...]) – input tuple of QDT profiles
- Returns:
tuple of profiles that are compatible with the running QDT version and those which are not
- Return type:
- filter_profiles_on_qgis_version(tup_qdt_profiles: tuple[QdtProfile, ...], qgis_version: str | None = None) tuple[list[QdtProfile], list[QdtProfile]]¶
Evaluate profiles against their optional qgisMinimumVersion and qgisMaximumVersion attributes.
- Parameters:
tup_qdt_profiles (tuple[QdtProfile, ...]) – input tuple of QDT profiles
qgis_version (str | None, optional) – targeted QGIS version. If None, the QDT_QGIS_VERSION environment variable (set by the job qgis-installation-finder) is used. Defaults to None.
- Returns:
tuple of profiles that are compatible with the targeted QGIS version (or could not be evaluated) and those which are not
- Return type:
- filter_profiles_on_rules(tup_qdt_profiles: tuple[QdtProfile, ...], cached: bool = True) tuple[list[QdtProfile], list[QdtProfile]]¶
Evaluate profiles regarding to their deployment rules.
Results stored in the class
RULES_FILTER_CACHEattribute, keyed by the serialized rules to be shared between jobs. A profile whose rules changed on disk is evaluated again.- Parameters:
tup_qdt_profiles (tuple[QdtProfile, ...]) – input tuple of QDT profiles
cached (bool, optional) – using previously computed value if not None. Defaults to True.
- Returns:
- profiles that matched and
those which did not match their deployment rules. Profiles whose rules could not be evaluated are in none of them.
- Return type:
- get_matching_profile_from_name(li_profiles: list[QdtProfile], profile_name: str) QdtProfile | None¶
Get a profile from list of profiles using a profile’s name to match.
- Parameters:
li_profiles (list[QdtProfile]) – list of profile to look into
profile_name (str) – profile name
- Returns:
matching profile object
- Return type:
- list_downloaded_profiles(quiet: bool = False) tuple[QdtProfile, ...] | None¶
- List downloaded QGIS profiles, i.e. a profile’s folder located into the QDT
working folder. Typically: ~/.cache/qgis-deployment-toolbelt/repositories/geotribu or %USERPROFILE%/.cache/qgis-deployment-toolbelt/repositories/geotribu).
- Parameters:
quiet (bool, optional) – if True, log the “no profile found” case as debug instead of error. Useful for lookups where an empty result is an expected outcome, not a failure. Defaults to False.
- Returns:
- tuple of profiles objects or None if no profile
folder listed
- Return type:
tuple[QdtProfile, …] | None
- list_installed_profiles(quiet: bool = False) tuple[QdtProfile, ...] | None¶
- List installed QGIS profiles, i.e. a profile’s folder located into the QGIS
profiles path and so accessible to the end-user through the QGIS interface. Typically: ~/.local/share/QGIS/QGIS4/profiles/geotribu or %APPDATA%/QGIS/QGIS3/profiles/geotribu).
- Parameters:
quiet (bool, optional) – if True, log the “no profile found” case as debug instead of error. Useful for lookups where an empty result is an expected outcome, not a failure. Defaults to False.
- Returns:
- tuple of profiles objects or None if no profile is
installed in the QGIS profiles folder
- Return type:
tuple[QdtProfile, …] | None
- property os_config: OSConfiguration¶
Get current operating system configuration.
- Returns:
object with settings regarding operating system and QGIS
- Return type:
- read_profiles_folder(start_parent_folder: Path) tuple[QdtProfile, ...]¶
- Read a folder structure to list every QGIS profile handled by QDT,
without applying any of the deployment filters (QDT version, deprecation, QGIS version, deployment rules).
- Parameters:
start_parent_folder (Path) – root directory to scan for profile.json files.
- Returns:
- tuple of profiles objects found under the
folder. Empty if the folder does not exist or contains no profile.
- Return type:
tuple[QdtProfile, …]
- abstractmethod run() CleanupReport | None¶
Execute the job logic. Must be implemented by every concrete job.
- validate_options(options: dict[str, Any]) dict[str, Any]¶
Validate job options against
OPTIONS_SCHEMA.- Parameters:
- Raises:
JobOptionBadNameError – if an option name is not in the schema
JobOptionBadValueError – if an option value fails its condition
JobOptionBadValueTypeError – if an option value has the wrong type
TypeError – if options is not a dict or if the job declares no
OPTIONS_SCHEMA(jobs declaringOPTIONSuseOPTIONS.from_dict)
- Returns:
unchanged when all checks pass
- Return type: