Source code for AutoArchive._infrastructure.configuration._configuration

# _configuration.py
#
# Project: AutoArchive
# License: GNU GPLv3
#
# Copyright (C) 2003 - 2025 Róbert Čerňanský



__all__ = ["_Configuration"]



from . import ConfigurationBase, OptionsUtils, Option
from ._option_value import _OptionValue



[docs] class _Configuration(ConfigurationBase): """Application's configuration. Provides access to application's configuration. All configuration options that can be accessed via this class are defined as static attributes of :class:`.Options`. After construction, all options are added and initialized to ``None``. It is expected that concrete values will be added using the :meth:`_addOrReplaceOption()` method.""" def __init__(self): super().__init__() self.__populateWithNones()
[docs] def _addOrReplaceOption(self, optionName: str, value: str): """Adds an *option* and its *value* replacing the *value* if already exists. String representation of the *value* is expected. It will be converted to a proper type defined by the *option*. :param optionName: Option that will be added or replaced. :type optionName: ``str`` :param value: Value of passed *option* with name ``optionName``. :type value: ``str`` :raise KeyError: If *option* with name ``optionName`` does not exist. :raise ValueError: If *option's* *value* is not correct.""" option = OptionsUtils.getOption(optionName) self.__setitem__(option, OptionsUtils.strToOptionType(option, value))
def _setDefault(self, option: Option, value: str): self.options_[option] = _OptionValue(self.options_[option].value, OptionsUtils.strToOptionType(option, value)) def __populateWithNones(self): for option in OptionsUtils.getAllOptions(): self.options_[option] = _OptionValue(None, None)