This commit is contained in:
WorldTeacher
2024-09-13 16:02:36 +02:00
parent a8c2277870
commit a071f70059
7 changed files with 369 additions and 5 deletions

View File

@@ -4,7 +4,7 @@ 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.
@@ -94,17 +94,33 @@ class Config:
if self._config is None:
raise RuntimeError("Configuration not loaded")
self._config.log_debug = value
@property
def ic_logging(self)->bool:
if self._config is None:
raise RuntimeError("Configuration not loaded")
return self._config.ic_logging
@ic_logging.setter
def ic_logging(self, value:bool):
if self._config is None:
raise RuntimeError("Configuration not loaded")
self._config.ic_logging = value
def save(self):
if self._config is None:
raise RuntimeError("Configuration not loaded")
omegaconf.OmegaConf.save(self._config, "config/settings.yaml")
def apply_options(options:list):
if self._config is None:
raise RuntimeError("Configuration not loaded")
for option in options:
if option in self._config:
self._config[option] = True
else:
raise KeyError(f"Option {option} not found in configuration")
if __name__ == "__main__":
cfg = Config("config/settings.yaml")
print(cfg.database.path)
#print(cfg.database.path)
cfg.database.path = "nopathhere"
print(cfg.database.path)
#print(cfg.database.path)
cfg.save()
#cfg.updateValue("database.path", "Test")