refactor(ConfigManager): logging can be silenced

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2023-12-17 18:03:42 +01:00
parent 30b4414469
commit b83f642a13

View File

@@ -32,13 +32,15 @@ class ConfigManager:
with open(self.config_file, "w") as cfg: with open(self.config_file, "w") as cfg:
self.config.write(cfg) self.config.write(cfg)
def get_value(self, section: str, key: str) -> Union[str, bool, None]: def get_value(self, section: str, key: str, silent=False) -> Union[str, bool, None]:
if not self.config.has_section(section): if not self.config.has_section(section):
if not silent:
log = f"Section not defined. Unable to read section: [{section}]." log = f"Section not defined. Unable to read section: [{section}]."
Logger.print_error(log) Logger.print_error(log)
return None return None
if not self.config.has_option(section, key): if not self.config.has_option(section, key):
if not silent:
log = f"Option not defined in section [{section}]. Unable to read option: '{key}'." log = f"Option not defined in section [{section}]. Unable to read option: '{key}'."
Logger.print_error(log) Logger.print_error(log)
return None return None