refactor(BackupManager): backup_file method only takes in single files now

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-02-10 11:38:23 +01:00
parent 3bef6ecb85
commit 34ebe5d15e
3 changed files with 23 additions and 23 deletions

View File

@@ -37,9 +37,9 @@ def backup_config_json(is_temp=False) -> None:
bm = BackupManager()
if is_temp:
fn = Path.home().joinpath("config.json.kiauh.bak")
bm.backup_file([MAINSAIL_CONFIG_JSON], custom_filename=fn)
bm.backup_file(MAINSAIL_CONFIG_JSON, custom_filename=fn)
else:
bm.backup_file([MAINSAIL_CONFIG_JSON])
bm.backup_file(MAINSAIL_CONFIG_JSON)
def restore_config_json() -> None:

View File

@@ -42,13 +42,13 @@ class BackupManager:
self._ignore_folders = value
def backup_file(
self, files: List[Path] = None, target: Path = None, custom_filename=None
self, file: Path = None, target: Path = None, custom_filename=None
):
if not files:
raise ValueError("Parameter 'files' cannot be None or an empty List!")
if not file:
raise ValueError("Parameter 'file' cannot be None!")
target = self.backup_root_dir if target is None else target
for file in files:
Logger.print_status(f"Creating backup of {file} ...")
if Path(file).is_file():
date = get_current_date().get("date")
@@ -58,9 +58,9 @@ class BackupManager:
try:
Path(target).mkdir(exist_ok=True)
shutil.copyfile(file, target.joinpath(filename))
Logger.print_ok("Backup successfull!")
except OSError as e:
Logger.print_error(f"Unable to backup '{file}':\n{e}")
continue
else:
Logger.print_info(f"File '{file}' not found ...")
@@ -79,11 +79,11 @@ class BackupManager:
target.joinpath(f"{name.lower()}-{date}-{time}"),
ignore=self.ignore_folders_func,
)
Logger.print_ok("Backup successfull!")
except OSError as e:
Logger.print_error(f"Unable to backup directory '{source}':\n{e}")
return
Logger.print_ok("Backup successfull!")
def ignore_folders_func(self, dirpath, filenames):
return (

View File

@@ -24,7 +24,7 @@ from kiauh.extensions.gcode_shell_cmd import (
KLIPPER_DIR,
EXAMPLE_CFG_SRC,
KLIPPER_EXTRAS,
)
)
from kiauh.utils.filesystem_utils import check_file_exist
from kiauh.utils.input_utils import get_confirm
from kiauh.utils.logger import Logger
@@ -109,7 +109,7 @@ class GcodeShellCmdExtension(BaseExtension):
bm = BackupManager()
for instance in instances:
bm.backup_file(
[instance.cfg_file],
instance.cfg_file,
custom_filename=f"{instance.suffix}.printer.cfg",
)