From 99bca2c467cb9e352a0819ced37ec5dc4f959d3d Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Mon, 14 Jul 2025 18:14:33 +0900 Subject: [PATCH] Allow settings block to not exist via call setting --- src/corelibs/config_handling/settings_loader.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/corelibs/config_handling/settings_loader.py b/src/corelibs/config_handling/settings_loader.py index c796fbf..f4f7528 100644 --- a/src/corelibs/config_handling/settings_loader.py +++ b/src/corelibs/config_handling/settings_loader.py @@ -66,7 +66,12 @@ class SettingsLoader: self._check_settings_abort: bool = False # MARK: load settings - def load_settings(self, config_id: str, config_validate: dict[str, list[str]]) -> dict[str, str]: + def load_settings( + self, + config_id: str, + config_validate: dict[str, list[str]], + allow_not_exist: bool = False + ) -> dict[str, str]: """ neutral settings loader @@ -86,7 +91,8 @@ class SettingsLoader: Args: config_id (str): what block to load - config_allowed (list[str]): list of allowed entries sets + config_validate (dict[str, list[str]]): list of allowed entries sets + allow_not_exist (bool): If set to True, does not throw an error, but returns empty set Returns: dict[str, str]: key = value list @@ -99,6 +105,8 @@ class SettingsLoader: # load all data as is, validation is done afterwards settings[config_id] = dict(self.config_parser[config_id]) except KeyError as e: + if allow_not_exist is True: + return {} self.__print( f"[!] Cannot read [{config_id}] block in the {self.config_file}: {e}", 'CRITICAL', raise_exception=True