From c96801ee0e9cb69aeb611d16a8d64300eeeba8cf Mon Sep 17 00:00:00 2001 From: dw-0 Date: Fri, 28 Jun 2024 22:31:53 +0200 Subject: [PATCH] refactor: use update.sh script of OctoEverywhere for updating Signed-off-by: Dominik Willner --- kiauh/components/octoeverywhere/__init__.py | 1 + .../components/octoeverywhere/octoeverywhere.py | 10 ++++++++++ .../octoeverywhere/octoeverywhere_setup.py | 16 +++++++--------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/kiauh/components/octoeverywhere/__init__.py b/kiauh/components/octoeverywhere/__init__.py index ac8b838..a816526 100644 --- a/kiauh/components/octoeverywhere/__init__.py +++ b/kiauh/components/octoeverywhere/__init__.py @@ -20,6 +20,7 @@ OE_STORE_DIR = OE_DIR.joinpath("octoeverywhere-store") OE_REQ_FILE = OE_DIR.joinpath("requirements.txt") OE_DEPS_JSON_FILE = OE_DIR.joinpath("moonraker-system-dependencies.json") OE_INSTALL_SCRIPT = OE_DIR.joinpath("install.sh") +OE_UPDATE_SCRIPT = OE_DIR.joinpath("update.sh") # filenames OE_CFG_NAME = "octoeverywhere.conf" diff --git a/kiauh/components/octoeverywhere/octoeverywhere.py b/kiauh/components/octoeverywhere/octoeverywhere.py index 3adcfe8..5c8ad53 100644 --- a/kiauh/components/octoeverywhere/octoeverywhere.py +++ b/kiauh/components/octoeverywhere/octoeverywhere.py @@ -19,6 +19,7 @@ from components.octoeverywhere import ( OE_LOG_NAME, OE_STORE_DIR, OE_SYS_CFG_NAME, + OE_UPDATE_SCRIPT, ) from core.instance_manager.base_instance import BaseInstance from utils.logger import Logger @@ -61,6 +62,15 @@ class Octoeverywhere(BaseInstance): Logger.print_error(f"Error creating instance: {e}") raise + @staticmethod + def update(): + try: + run(str(OE_UPDATE_SCRIPT), check=True, shell=True, cwd=OE_DIR) + + except CalledProcessError as e: + Logger.print_error(f"Error updating OctoEverywhere for Klipper: {e}") + raise + def delete(self) -> None: service_file = self.get_service_file_name(extension=True) service_file_path = self.get_service_file_path() diff --git a/kiauh/components/octoeverywhere/octoeverywhere_setup.py b/kiauh/components/octoeverywhere/octoeverywhere_setup.py index 8f28f18..be556dd 100644 --- a/kiauh/components/octoeverywhere/octoeverywhere_setup.py +++ b/kiauh/components/octoeverywhere/octoeverywhere_setup.py @@ -32,7 +32,7 @@ from utils.config_utils import ( remove_config_section, ) from utils.fs_utils import run_remove_routines -from utils.git_utils import git_clone_wrapper, git_pull_wrapper +from utils.git_utils import git_clone_wrapper from utils.input_utils import get_confirm from utils.logger import DialogType, Logger from utils.sys_utils import ( @@ -122,14 +122,12 @@ def install_octoeverywhere() -> None: def update_octoeverywhere() -> None: Logger.print_status("Updating OctoEverywhere for Klipper ...") try: - oe_im = InstanceManager(Octoeverywhere) - oe_im.stop_all_instance() - - git_pull_wrapper(OE_REPO, OE_DIR) - install_oe_dependencies() - - oe_im.start_all_instance() - Logger.print_ok("OctoEverywhere for Klipper successfully updated!") + Octoeverywhere.update() + Logger.print_dialog( + DialogType.SUCCESS, + ["OctoEverywhere for Klipper successfully updated!"], + center_content=True, + ) except Exception as e: Logger.print_error(f"Error during OctoEverywhere for Klipper update:\n{e}")