qgis_deployment_toolbelt.jobs.job_qgis_installation_finder module

Tools to find installed QGIS version

Author: Jean-Marie KERLOCH (https://github.com/jmkerloch)

class qgis_deployment_toolbelt.jobs.job_qgis_installation_finder.JobQgisInstallationFinder(options: dict)

Bases: GenericJob

Class to find installed QGIS version

CACHE_DETECTED_QGIS_VERSION: str | None = None
ID: str = 'qgis-installation-finder'
OPTIONS_SCHEMA: dict = {'if_not_found': {'condition': 'in', 'default': 'warning', 'possible_values': ('warning', 'error'), 'required': False, 'type': <class 'str'>}, 'search_paths': {'condition': None, 'default': ('%PROGRAMFILES%', 'C:\\OSGeo4W'), 'possible_values': None, 'required': False, 'type': (<class 'list'>, <class 'str'>)}, 'version_priority': {'condition': None, 'default': None, 'possible_values': None, 'required': False, 'type': (<class 'list'>, <class 'str'>)}}
__init__(options: dict) None

Instantiate the class.

Parameters:

options (dict) – job options

_export_qgis_version(version_str: str) None

Export the detected QGIS version as an environment variable.

Parameters:

version_str (str) – QGIS version, typically a SemVer string like 3.40.1.

static _get_latest_matching_version_path(found_versions: dict[str, str], version: str) str | None

Get latest version path matching a wanted version.

Parameters:
  • found_versions (dict[str, str]) – dict of found versions

  • version (str) – wanted version

Returns:

latest matching version path, None if not found

Return type:

str | None

static _get_latest_version_from_list(versions: list[str]) str | None

Get latest version from a list.

Parameters:

versions (list[str]) – list of found version

Returns:

latest version, None if no version provided

Return type:

str | None

_get_linux_installed_qgis_path() dict[str, str]

Get install qgis path for linux operating system with which

Returns:

dict of QGIS version and QGIS bin path

Return type:

dict[str, str]

static _get_qgis_bin_version(qgis_bin: str) str | None

Get QGIS bin version with –version.

See:

Parameters:

qgis_bin (str) – QGIS bin executable path

Returns:

SemVer version, None if version not found

Return type:

str | None

static _get_qgis_found_version_dict_from_search_paths(search_paths: list[str], search_patterns: list[str]) dict[str, str]

Define qgis found version dict from a list of search path.

If identical version are found in multiple path, the first version found in search_path is used.

Parameters:
  • search_paths (list[str]) – list of search paths

  • search_patterns (list[str]) – list of search pattern for qgis binary

Returns:

dict of qgis binary path for qgis version

Return type:

dict[str, str]

static _get_qgis_versions_in_dir(search_dir: str, search_patterns: list[str], found_version: dict[str, str]) None

Get QGIS binary path from an install directory.

Parameters:
  • install_dir (str) – install directory

  • search_patterns (list[str]) – list of search pattern for qgis binary

  • found_version (dict[str, str]) – updated dict of qgis binary path and version

_get_search_paths_with_environment_variable() list[str]

Get search_paths option with environment variable update.

Returns:

search_paths

Return type:

list[str]

static _get_windows_hide_console_startupinfo() dict

Build extra kwargs to hide a console window newly created on Windows.

Returns:

empty on non-Windows platforms, otherwise a single

startupinfo entry ready to unpack into subprocess.run.

Return type:

dict

_get_windows_installed_qgis_path() dict[str, str]

Get dict of installed QGIS version in common install directory.

Returns:

dict of QGIS version and QGIS bin path

Return type:

dict[str, str]

static _search_qgis_version_and_add_to_dict(qgis_bin: str, found_version: dict[str, str]) None

Search qgis version from qgis binary and add to found_version dict if found

Parameters:
  • qgis_bin (str) – qgis binary path

  • found_version (dict[str, str]) – updated dict of qgis binary path and version

static _version_sort_key(version_str: str) Version

Transforn a version string into a sortable and comparable Version object.

Parameters:

version_str (str) – version string to parse, typically X.Y.Z.

Returns:

parsed version, or Version(“0”) if parsing failed.

Return type:

Version

get_installed_qgis_path() str | None

Get the path to the installed QGIS executable best matching job options.

Returns:

installed qgis path

Return type:

str | None

get_installed_qgis_version_and_path() tuple[str, str] | None

Get the installed QGIS version and executable path best matching job options.

Returns:

(version, path) tuple, or None if no QGIS

installation is found.

Return type:

tuple[str, str] | None

run() None

Define QDT_QGIS_EXE_PATH and QDT_QGIS_VERSION for version-dependent jobs, like Shortcuts manager.

run_needed() bool

Check if running the job is needed.

Returns:

return True if job must be run, False otherwise

Return type:

bool