From f6524b84f18157c1ba68139871e7445b2a12d699 Mon Sep 17 00:00:00 2001 From: dw-0 Date: Fri, 28 Jun 2024 22:54:45 +0200 Subject: [PATCH] refactor: add force flag to git_clone_wrapper Signed-off-by: Dominik Willner --- kiauh/components/octoeverywhere/octoeverywhere_setup.py | 4 +++- kiauh/extensions/obico/moonraker_obico_extension.py | 4 +++- kiauh/utils/git_utils.py | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/kiauh/components/octoeverywhere/octoeverywhere_setup.py b/kiauh/components/octoeverywhere/octoeverywhere_setup.py index 26ea678..13634d1 100644 --- a/kiauh/components/octoeverywhere/octoeverywhere_setup.py +++ b/kiauh/components/octoeverywhere/octoeverywhere_setup.py @@ -54,6 +54,7 @@ def install_octoeverywhere() -> None: if not moonraker_exists(): return + force_clone = False oe_im = InstanceManager(Octoeverywhere) oe_instances: List[Octoeverywhere] = oe_im.instances if oe_instances: @@ -72,6 +73,7 @@ def install_octoeverywhere() -> None: return else: Logger.print_status("Re-Installing OctoEverywhere for Klipper ...") + force_clone = True mr_im = InstanceManager(Moonraker) mr_instances: List[Moonraker] = mr_im.instances @@ -99,7 +101,7 @@ def install_octoeverywhere() -> None: return try: - git_clone_wrapper(OE_REPO, OE_DIR) + git_clone_wrapper(OE_REPO, OE_DIR, force=force_clone) for moonraker in mr_instances: oe_im.current_instance = Octoeverywhere(suffix=moonraker.suffix) diff --git a/kiauh/extensions/obico/moonraker_obico_extension.py b/kiauh/extensions/obico/moonraker_obico_extension.py index c010041..e07b842 100644 --- a/kiauh/extensions/obico/moonraker_obico_extension.py +++ b/kiauh/extensions/obico/moonraker_obico_extension.py @@ -57,6 +57,7 @@ class ObicoExtension(BaseExtension): # if obico is already installed, ask if the user wants to repair an # incomplete installation or link to the obico server + force_clone = False obico_im = InstanceManager(MoonrakerObico) obico_instances: List[MoonrakerObico] = obico_im.instances if obico_instances: @@ -74,6 +75,7 @@ class ObicoExtension(BaseExtension): return else: Logger.print_status("Re-Installing Obico for Klipper ...") + force_clone = True # let the user confirm installation kl_im = InstanceManager(Klipper) @@ -89,7 +91,7 @@ class ObicoExtension(BaseExtension): return try: - git_clone_wrapper(OBICO_REPO, OBICO_DIR) + git_clone_wrapper(OBICO_REPO, OBICO_DIR, force=force_clone) self._install_dependencies() # ask the user for the obico server url diff --git a/kiauh/utils/git_utils.py b/kiauh/utils/git_utils.py index d06a2d8..98dead9 100644 --- a/kiauh/utils/git_utils.py +++ b/kiauh/utils/git_utils.py @@ -14,7 +14,7 @@ from utils.logger import Logger def git_clone_wrapper( - repo: str, target_dir: Path, branch: Optional[str] = None + repo: str, target_dir: Path, branch: Optional[str] = None, force: bool = False ) -> None: """ Clones a repository from the given URL and checks out the specified branch if given. @@ -22,6 +22,7 @@ def git_clone_wrapper( :param repo: The URL of the repository to clone. :param branch: The branch to check out. If None, the default branch will be checked out. :param target_dir: The directory where the repository will be cloned. + :param force: Force the cloning of the repository even if it already exists. :return: None """ log = f"Cloning repository from '{repo}'" @@ -29,7 +30,7 @@ def git_clone_wrapper( try: if Path(target_dir).exists(): question = f"'{target_dir}' already exists. Overwrite?" - if not get_confirm(question, default_choice=False): + if not force and not get_confirm(question, default_choice=False): Logger.print_info("Skip cloning of repository ...") return shutil.rmtree(target_dir)