refactor(crowsnest): allow backup before update for crowsnest

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-05-05 19:23:09 +02:00
parent 72663ef71c
commit 3b2bc05746
2 changed files with 15 additions and 1 deletions

View File

@@ -9,5 +9,8 @@
from pathlib import Path
from core.backup_manager import BACKUP_ROOT_DIR
CROWSNEST_DIR = Path.home().joinpath("crowsnest")
CROWSNEST_REPO = "https://github.com/mainsail-crew/crowsnest.git"
CROWSNEST_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("crowsnest-backups")

View File

@@ -14,9 +14,11 @@ from pathlib import Path
from subprocess import run, CalledProcessError
from typing import List, Dict, Literal, Union
from components.crowsnest import CROWSNEST_REPO, CROWSNEST_DIR
from components.crowsnest import CROWSNEST_REPO, CROWSNEST_DIR, CROWSNEST_BACKUP_DIR
from components.klipper.klipper import Klipper
from core.backup_manager.backup_manager import BackupManager
from core.instance_manager.instance_manager import InstanceManager
from core.settings.kiauh_settings import KiauhSettings
from utils.common import get_install_status, check_install_dependencies
from utils.constants import COLOR_CYAN, RESET_FORMAT, CURRENT_USER
from utils.git_utils import (
@@ -105,6 +107,15 @@ def update_crowsnest() -> None:
else:
Logger.print_status("Updating Crowsnest ...")
settings = KiauhSettings()
if settings.get("kiauh", "backup_before_update"):
bm = BackupManager()
bm.backup_directory(
"crowsnest",
source=CROWSNEST_DIR,
target=CROWSNEST_BACKUP_DIR,
)
git_pull_wrapper(CROWSNEST_REPO, CROWSNEST_DIR)
script = CROWSNEST_DIR.joinpath("tools/install.sh")