feat(BackupManager): implement simple backup manager

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2023-11-14 21:28:13 +01:00
parent 1392ca9f82
commit a4a3d5eecb
7 changed files with 133 additions and 10 deletions

View File

@@ -14,6 +14,7 @@ import configparser
from pathlib import Path
from typing import Union
from kiauh import APPLICATION_ROOT
from kiauh.utils.logger import Logger
@@ -34,7 +35,7 @@ class ConfigManager:
with open(self.config_file, "w") as cfg:
self.config.write(cfg)
def get_value(self, section: str, key: str) -> Union[str, None]:
def get_value(self, section: str, key: str) -> Union[str, bool, None]:
if not self.config.has_section(section):
log = f"Section not defined. Unable to read section: [{section}]."
Logger.print_error(log)
@@ -45,17 +46,21 @@ class ConfigManager:
Logger.print_error(log)
return None
return self.config.get(section, key)
value = self.config.get(section, key)
if value == "True" or value == "true":
return True
elif value == "False" or value == "false":
return False
else:
return value
def set_value(self, section: str, key: str, value: str):
self.config.set(section, key, value)
def check_config_exists(self) -> bool:
def check_config_exist(self) -> bool:
return True if self._get_cfg_location() else False
def _get_cfg_location(self) -> str:
current_dir = os.path.dirname(os.path.abspath(__file__))
project_dir = os.path.dirname(os.path.dirname(current_dir))
cfg_path = os.path.join(project_dir, "kiauh.cfg")
cfg_path = os.path.join(APPLICATION_ROOT, "kiauh.cfg")
return cfg_path if Path(cfg_path).exists() else None