qgis_deployment_toolbelt.profiles.rules_context module

Rules context.

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

class qgis_deployment_toolbelt.profiles.rules_context.QdtRulesContext(only_prefixed_variables: bool = True, variables_prefix: list[str] | None = None)

Bases: object

__init__(only_prefixed_variables: bool = True, variables_prefix: list[str] | None = None) None

Initialize a QDT rules context object.

Parameters:
  • only_prefixed_variables (bool, optional) – Option to only list prefixed

  • True. (variables. Defaults to)

  • variables_prefix (list[str] | None, optional) – List of allowed prefixes.

  • None. (Defaults to)

property _context_date: dict

Returns a context dictionary with date informations that can be used in QDT various places: rules…

Returns:

dict with current date informations

Return type:

dict

property _context_env: dict[str, str] | _Environ[str]
Returns a dictionary containing environment variables that can be used in

QDT various places: rules…

The environment variables can be filtered based on self.only_prefixed_variables and self.variables_prefix settings.

Returns:

dict with environment variables to use in rules

Return type:

dict[str, str] | _Environ[str]

property _context_environment: dict
Returns a dictionary containing some environment information (computer, network,

platform) that can be used in QDT various places: rules…

Returns:

dict with some environment metadata to use in rules.

Return type:

dict

property _context_user: dict
Returns a dictionary containing user informations that can be used in QDT Rules

context.

Returns:

dict user information.

Return type:

dict

to_dict() dict

Convert object into dictionary.

Returns:

object as dictionary

Return type:

dict

to_json(**kwargs: Any) str

Supersedes json.dumps using the dictionary returned by to_dict(). kwargs are passed to json.dumps.

Returns:

object serialized as JSON string

Return type:

str

Example

from pathlib import Path

rules_context = QdtRulesContext()

# write into the file passing extra parameters to json.dumps
with Path("qdt_rules_context.json").open("w", encoding="UTF8") as wf:
    wf.write(rules_context.to_json(indent=4, sort_keys=True))