mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 08:43:36 +05:00
refactor(ConfigManager): allow to take in any config file
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
# 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__)))
|
APPLICATION_ROOT = dirname(dirname(abspath(__file__)))
|
||||||
|
KIAUH_CFG = join(APPLICATION_ROOT, "kiauh.cfg")
|
||||||
|
|||||||
@@ -9,19 +9,16 @@
|
|||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
|
||||||
import os
|
|
||||||
import configparser
|
import configparser
|
||||||
from pathlib import Path
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from kiauh import APPLICATION_ROOT
|
|
||||||
from kiauh.utils.logger import Logger
|
from kiauh.utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyMethodMayBeStatic
|
# noinspection PyMethodMayBeStatic
|
||||||
class ConfigManager:
|
class ConfigManager:
|
||||||
def __init__(self):
|
def __init__(self, cfg_file: str):
|
||||||
self.config_file = self._get_cfg_location()
|
self.config_file = cfg_file
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
|
|
||||||
def read_config(self) -> None:
|
def read_config(self) -> None:
|
||||||
@@ -56,11 +53,3 @@ class ConfigManager:
|
|||||||
|
|
||||||
def set_value(self, section: str, key: str, value: str):
|
def set_value(self, section: str, key: str, value: str):
|
||||||
self.config.set(section, key, value)
|
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
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import subprocess
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
|
from kiauh import KIAUH_CFG
|
||||||
from kiauh.core.backup_manager.backup_manager import BackupManager
|
from kiauh.core.backup_manager.backup_manager import BackupManager
|
||||||
from kiauh.core.config_manager.config_manager import ConfigManager
|
from kiauh.core.config_manager.config_manager import ConfigManager
|
||||||
from kiauh.core.instance_manager.instance_manager import InstanceManager
|
from kiauh.core.instance_manager.instance_manager import InstanceManager
|
||||||
@@ -135,7 +136,7 @@ def install_klipper(
|
|||||||
|
|
||||||
|
|
||||||
def setup_klipper_prerequesites() -> None:
|
def setup_klipper_prerequesites() -> None:
|
||||||
cm = ConfigManager()
|
cm = ConfigManager(cfg_file=KIAUH_CFG)
|
||||||
cm.read_config()
|
cm.read_config()
|
||||||
|
|
||||||
repo = str(cm.get_value("klipper", "repository_url") or DEFAULT_KLIPPER_REPO_URL)
|
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?"):
|
if not get_confirm("Update Klipper now?"):
|
||||||
return
|
return
|
||||||
|
|
||||||
cm = ConfigManager()
|
cm = ConfigManager(cfg_file=KIAUH_CFG)
|
||||||
cm.read_config()
|
cm.read_config()
|
||||||
|
|
||||||
if cm.get_value("kiauh", "backup_before_update"):
|
if cm.get_value("kiauh", "backup_before_update"):
|
||||||
|
|||||||
Reference in New Issue
Block a user