diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..3558f42 --- /dev/null +++ b/config/__init__.py @@ -0,0 +1 @@ +from .config import Config \ No newline at end of file diff --git a/config/config.py b/config/config.py new file mode 100644 index 0000000..14ba493 --- /dev/null +++ b/config/config.py @@ -0,0 +1,110 @@ +from typing import Optional + +import omegaconf + +class Config: + _config: Optional[omegaconf.DictConfig] = None + + def __init__(self, config_path: str): + """ + Loads the configuration file and stores it for future access. + + Args: + config_path (str): Path to the YAML configuration file. + """ + self._config = omegaconf.OmegaConf.load(config_path) + + @property + def institution_name(self)->str: + if self._config is None: + raise RuntimeError("Configuration not loaded") + return self._config.institution_name + @institution_name.setter + def institution_name(self, value: str): + if self._config is None: + raise RuntimeError("Configuration not loaded") + self._config.institution_name = value + @property + def loan_duration(self)->int: + if self._config is None: + raise RuntimeError("Configuration not loaded") + return self._config.default_loan_duration + @loan_duration.setter + def loan_duration(self, value: int): + if self._config is None: + raise RuntimeError("Configuration not loaded") + self._config.default_loan_duration = value + @property + def delete_inactive_user_duration(self)->int: + if self._config is None: + raise RuntimeError("Configuration not loaded") + return self._config.inactive_user_deletion + @delete_inactive_user_duration.setter + def delete_inactive_user_duration(self, value: int): + if self._config is None: + raise RuntimeError("Configuration not loaded") + self._config.inactive_user_deletion = value + @property + def catalogue(self)->bool: + if self._config is None: + raise RuntimeError("Configuration not loaded") + return self._config.catalogue + @catalogue.setter + def catalogue(self, value: bool): + if self._config is None: + raise RuntimeError("Configuration not loaded") + self._config.catalogue = value + @property + def database(self)->omegaconf.DictConfig: + if self._config is None: + raise RuntimeError("Configuration not loaded") + return self._config.database + @database.setter + def database(self, value: omegaconf.DictConfig): + if self._config is None: + raise RuntimeError("Configuration not loaded") + self._config.database = value + @property + def report(self)->omegaconf.DictConfig: + if self._config is None: + raise RuntimeError("Configuration not loaded") + return self._config.report + @report.setter + def report(self, value: omegaconf.DictConfig): + if self._config is None: + raise RuntimeError("Configuration not loaded") + self._config.report = value + @property + def debug(self)->bool: + if self._config is None: + raise RuntimeError("Configuration not loaded") + return self._config.debug + @debug.setter + def debug(self, value: bool): + if self._config is None: + raise RuntimeError("Configuration not loaded") + self._config.debug = value + @property + def log_debug(self)->bool: + if self._config is None: + raise RuntimeError("Configuration not loaded") + return self._config.log_debug + @log_debug.setter + def log_debug(self, value: bool): + if self._config is None: + raise RuntimeError("Configuration not loaded") + self._config.log_debug = value + def save(self): + if self._config is None: + raise RuntimeError("Configuration not loaded") + omegaconf.OmegaConf.save(self._config, "config/settings.yaml") + + + +if __name__ == "__main__": + cfg = Config("config/settings.yaml") + print(cfg.database.path) + cfg.database.path = "nopathhere" + print(cfg.database.path) + cfg.save() + #cfg.updateValue("database.path", "Test") \ No newline at end of file