qgis_deployment_toolbelt.profiles.qgis_ini_handler module¶
Read and write QGIS configuration files.
Author: Julien Moura (https://github.com/guts)
- class qgis_deployment_toolbelt.profiles.qgis_ini_handler.QgisIniHelper(ini_filepath: Path, ini_type: Literal['profile_settings', 'profile_customization', 'plugin_metadata', None] = None, strict: bool = False, enable_environment_variables_interpolation: bool = True, qgis_version_major: Literal[3, 4] | None = None)¶
Bases:
objectHelper to manipulate QGIS configuration files (*.ini).
- SUPPORTED_INI_TYPES: tuple[str, str, str] = ('plugin_metadata', 'profile_settings', 'profile_customization')¶
- __init__(ini_filepath: Path, ini_type: Literal['profile_settings', 'profile_customization', 'plugin_metadata', None] = None, strict: bool = False, enable_environment_variables_interpolation: bool = True, qgis_version_major: Literal[3, 4] | None = None) None¶
Instanciation.
- Parameters:
ini_filepath (Path) – path to the QGIS settings file (QGIS3.ini, QGIS4.ini…)
ini_type (Literal['profile_settings', 'profile_customization', 'plugin_metadata', None ], optional) – type of ini file. None enables autodetection. Defaults to None.
strict (bool, optional) – strict mode applied to ConfigParser. Defaults to False.
enable_environment_variables_interpolation (bool, optional) – if enabled, values matching environment variables are interepreted. Defaults to True.
qgis_version_major (SupportedQgisMajorVersion | None, optional) – QGIS major version, used to name the profile settings file. If None, it’s deduced from the input file name when possible, then from the installed QGIS. Defaults to None.
- static _backup_section(config_dest: CustomConfigParser, config_src: CustomConfigParser, section_src: str, dst: Path) None¶
Backup a INI section for with updated values
- Parameters:
config_dest (CustomConfigParser) – destination INI content
config_src (CustomConfigParser) – source INI content
section_src (str) – section to backup
dst (Path) – destination file
- static _copy_section(config_dest: CustomConfigParser, config_src: CustomConfigParser, section_src: str) None¶
Copy section from an INI config to another INI config
- Parameters:
config_dest (CustomConfigParser) – destination INI content
config_src (CustomConfigParser) – source INI content
section_src (str) – section to copy
- static _resolve_qgis_version_major(ini_filepath: Path, qgis_version_major: Literal[3, 4] | None = None) Literal[3, 4]¶
Determine which QGIS major version the handled ini file belongs to.
- Parameters:
ini_filepath (Path) – path to the handled ini file.
qgis_version_major (SupportedQgisMajorVersion | None, optional) – explicitly passed major version, which always wins. Defaults to None.
- Returns:
QGIS major version to use.
- Return type:
SupportedQgisMajorVersion
- cfg_parser() CustomConfigParser¶
Return config parser with options for QGIS ini files.
- Returns:
config parser
- Return type:
- has_other_customizations_than_splash_screen(ini_file: Path | None = None) bool¶
Determine if the customization file defines more than the splash screen.
- Parameters:
ini_file (Path | None, optional) – customization file to check. If None, self.profile_customization_path is used. Defaults to None.
- Returns:
True if any option other than the splash screen path is set.
- Return type:
- is_splash_screen_set(ini_file: CustomConfigParser | Path | None = None) bool | None¶
Determine if a custom splash screen is set or not.
- Parameters:
ini_file (Union[CustomConfigParser, Path]) – input ini file to check. A warning is raised if the filename is not QGISCUSTOMIZATION3.ini. If None, self.profile_customization_path is used.
- Returns:
True if a splash is set
- Return type:
- is_ui_customization_enabled(ini_file: CustomConfigParser | Path | None = None) bool | None¶
Determine if UI customization is enabled.
- Parameters:
ini_file (Union[CustomConfigParser, Path]) – input ini file to check. A warning is raised if the filename is not a QGIS profile settings file (QGIS3.ini, QGIS4.ini…). If None, self.profile_config_path is used.
- Returns:
True if customization is enabled
- Return type:
- merge_to(dst: QgisIniHelper) None¶
Merge INI file to another INI file. If the destination file exists a merge is done: - all available sections are kept - if a section is available in both INI files, keep updated parameters in a backup section If environnement variable interpolation is enabled, value are written with current environnement values
- Parameters:
dst (QgisIniHelper) – destination ini file
- set_splash_screen(ini_file: CustomConfigParser | Path | None = None, splash_screen_filepath: Path | None = None, switch: bool = True) bool¶
Add/remove splash screen path to the QGISCUSTOMIZATION3.ini file.
- Parameters:
ini_file (Union[CustomConfigParser, Path]) – input ini file to check. A warning is raised if the filename is not QGISCUSTOMIZATION3.ini. If None, self.profile_customization_path is used.
splash_screen_filepath (Path, optional) – path to the folder containing the splash.png file, defaults to None. Defaults to None.
switch (bool, optional) – True to add, False to remove, defaults to True. Defaults to True.
- Returns:
True is the splash folder is present. False is absent.
- Return type: