qgis_deployment_toolbelt.utils.win32utils module#

Utilities specific for Windows.

Author: Julien Moura (https://github.com/guts)

Inspired from py-setenv: <https://github.com/beliaev-maksim/py_setenv> (MIT)

qgis_deployment_toolbelt.utils.win32utils.delete_environment_variable(envvar_name: str, scope: str = 'user') bool#

Deletes environment variable.

Parameters:
  • envvar_name (str) – environment variable name (= key) to delete

  • scope (str, optional) – environment variable scope. Must be “user” or “system”, defaults to “user”. Defaults to “user”.

Returns:

True is the variable has been successfully deleted

Return type:

bool

qgis_deployment_toolbelt.utils.win32utils.get_environment_variable(envvar_name: str, scope: str = 'user') str | None#

Get environment variable from Windows registry.

Parameters:
  • envvar_name (str) – environment variable name (= key) to retrieve

  • scope (str, optional) – environment variable scope. Must be “user” or “system”, defaults to “user”. Defaults to “user”.

Returns:

environment variable value or None if not found

Return type:

Optional[str]

qgis_deployment_toolbelt.utils.win32utils.normalize_path(input_path: Path, add_trailing_slash_if_dir: bool = True) str#

Returns a path as normalized and fully escaped for Windows old-school file style.

Parameters:
  • input_path (Path) – path to normalize

  • add_trailing_slash_if_dir (bool) – add a trailing slash if the input is a folder,defaults to True

Return str:

normalized path as string

Example:

t = Path(r'C:\Users\risor\Documents\GitHub\Geotribu\qtribu\qtribu\resources\images')
print(normalize_path(t))
> C:\\Users\\risor\\Documents\\GitHub\\Geotribu\\qtribu\\qtribu\\resources\\images\\
qgis_deployment_toolbelt.utils.win32utils.refresh_environment() bool#

This ensures that changes to Windows registry are immediately propagated. Useful to refresh after have updated the environment variables.

A method by Geoffrey Faivre-Malloy and Ronny Lipshitz. Source: https://gist.github.com/apetrone/5937002

Returns:

True if the environment has been refreshed

Return type:

bool

qgis_deployment_toolbelt.utils.win32utils.set_environment_variable(envvar_name: str, envvar_value: str, scope: str = 'user') bool#

Creates/replaces environment variable.

Parameters:
  • envvar_name (str) – name (= key) of environment variable to set or replace.

  • envvar_value (str) – value to set for the environment variable

  • scope (str, optional) – environment variable scope. Must be “user” or “system”, defaults to “user”. Defaults to “user”.

Returns:

True is the variable has been successfully set

Return type:

bool