refactor(ConfigManager): allow to take in any config file

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2023-12-03 23:10:43 +01:00
parent 57f34b07c6
commit de20f0c412
3 changed files with 7 additions and 16 deletions

View File

@@ -9,6 +9,7 @@
# This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= #
from os.path import dirname, abspath
from os.path import join, dirname, abspath
APPLICATION_ROOT = dirname(dirname(abspath(__file__)))
KIAUH_CFG = join(APPLICATION_ROOT, "kiauh.cfg")

View File

@@ -9,19 +9,16 @@
# This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= #
import os
import configparser
from pathlib import Path
from typing import Union
from kiauh import APPLICATION_ROOT
from kiauh.utils.logger import Logger
# noinspection PyMethodMayBeStatic
class ConfigManager:
def __init__(self):
self.config_file = self._get_cfg_location()
def __init__(self, cfg_file: str):
self.config_file = cfg_file
self.config = configparser.ConfigParser()
def read_config(self) -> None:
@@ -56,11 +53,3 @@ class ConfigManager:
def set_value(self, section: str, key: str, value: str):
self.config.set(section, key, value)
def check_config_exist(self) -> bool:
return True if self._get_cfg_location() else False
def _get_cfg_location(self) -> str:
cfg_path = os.path.join(APPLICATION_ROOT, "kiauh.cfg")
return cfg_path if Path(cfg_path).exists() else None

View File

@@ -14,6 +14,7 @@ import subprocess
from pathlib import Path
from typing import List, Union
from kiauh import KIAUH_CFG
from kiauh.core.backup_manager.backup_manager import BackupManager
from kiauh.core.config_manager.config_manager import ConfigManager
from kiauh.core.instance_manager.instance_manager import InstanceManager
@@ -135,7 +136,7 @@ def install_klipper(
def setup_klipper_prerequesites() -> None:
cm = ConfigManager()
cm = ConfigManager(cfg_file=KIAUH_CFG)
cm.read_config()
repo = str(cm.get_value("klipper", "repository_url") or DEFAULT_KLIPPER_REPO_URL)
@@ -255,7 +256,7 @@ def update_klipper() -> None:
if not get_confirm("Update Klipper now?"):
return
cm = ConfigManager()
cm = ConfigManager(cfg_file=KIAUH_CFG)
cm.read_config()
if cm.get_value("kiauh", "backup_before_update"):