refactor(Klipper): rework remove process
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -64,7 +64,7 @@ class InstallMenu(BaseMenu):
|
|||||||
print(menu, end="")
|
print(menu, end="")
|
||||||
|
|
||||||
def install_klipper(self):
|
def install_klipper(self):
|
||||||
klipper_setup.run_klipper_setup(install=True)
|
klipper_setup.install_klipper()
|
||||||
|
|
||||||
def install_moonraker(self):
|
def install_moonraker(self):
|
||||||
moonraker_setup.install_moonraker()
|
moonraker_setup.install_moonraker()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import textwrap
|
|||||||
|
|
||||||
from kiauh.core.menus import BACK_FOOTER
|
from kiauh.core.menus import BACK_FOOTER
|
||||||
from kiauh.core.menus.base_menu import BaseMenu
|
from kiauh.core.menus.base_menu import BaseMenu
|
||||||
from kiauh.modules.klipper import klipper_setup
|
from kiauh.modules.klipper.menus.klipper_remove_menu import KlipperRemoveMenu
|
||||||
from kiauh.modules.mainsail.menus.mainsail_remove_menu import MainsailRemoveMenu
|
from kiauh.modules.mainsail.menus.mainsail_remove_menu import MainsailRemoveMenu
|
||||||
from kiauh.modules.moonraker.menus.moonraker_remove_menu import MoonrakerRemoveMenu
|
from kiauh.modules.moonraker.menus.moonraker_remove_menu import MoonrakerRemoveMenu
|
||||||
from kiauh.utils.constants import COLOR_RED, RESET_FORMAT
|
from kiauh.utils.constants import COLOR_RED, RESET_FORMAT
|
||||||
@@ -25,7 +25,7 @@ class RemoveMenu(BaseMenu):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
header=True,
|
header=True,
|
||||||
options={
|
options={
|
||||||
1: self.remove_klipper,
|
1: KlipperRemoveMenu,
|
||||||
2: MoonrakerRemoveMenu,
|
2: MoonrakerRemoveMenu,
|
||||||
3: MainsailRemoveMenu,
|
3: MainsailRemoveMenu,
|
||||||
5: self.remove_fluidd,
|
5: self.remove_fluidd,
|
||||||
@@ -69,9 +69,6 @@ class RemoveMenu(BaseMenu):
|
|||||||
)[1:]
|
)[1:]
|
||||||
print(menu, end="")
|
print(menu, end="")
|
||||||
|
|
||||||
def remove_klipper(self):
|
|
||||||
klipper_setup.run_klipper_setup(install=False)
|
|
||||||
|
|
||||||
def remove_fluidd(self):
|
def remove_fluidd(self):
|
||||||
print("remove_fluidd")
|
print("remove_fluidd")
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class Klipper(BaseInstance):
|
|||||||
Logger.print_error(f"Error creating env file {env_file_target}: {e}")
|
Logger.print_error(f"Error creating env file {env_file_target}: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def delete(self, del_remnants: bool) -> None:
|
def delete(self) -> None:
|
||||||
service_file = self.get_service_file_name(extension=True)
|
service_file = self.get_service_file_name(extension=True)
|
||||||
service_file_path = self.get_service_file_path()
|
service_file_path = self.get_service_file_path()
|
||||||
|
|
||||||
@@ -89,9 +89,6 @@ class Klipper(BaseInstance):
|
|||||||
Logger.print_error(f"Error deleting service file: {e}")
|
Logger.print_error(f"Error deleting service file: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if del_remnants:
|
|
||||||
self._delete_klipper_remnants()
|
|
||||||
|
|
||||||
def write_service_file(
|
def write_service_file(
|
||||||
self,
|
self,
|
||||||
service_template_path: Path,
|
service_template_path: Path,
|
||||||
@@ -118,20 +115,6 @@ class Klipper(BaseInstance):
|
|||||||
env_file.write(env_file_content)
|
env_file.write(env_file_content)
|
||||||
Logger.print_ok(f"Env file created: {env_file_target}")
|
Logger.print_ok(f"Env file created: {env_file_target}")
|
||||||
|
|
||||||
def _delete_klipper_remnants(self) -> None:
|
|
||||||
try:
|
|
||||||
Logger.print_status(f"Delete {self.klipper_dir} ...")
|
|
||||||
shutil.rmtree(Path(self.klipper_dir))
|
|
||||||
Logger.print_status(f"Delete {self.env_dir} ...")
|
|
||||||
shutil.rmtree(Path(self.env_dir))
|
|
||||||
except FileNotFoundError:
|
|
||||||
Logger.print_status("Cannot delete Klipper directories. Not found.")
|
|
||||||
except PermissionError as e:
|
|
||||||
Logger.print_error(f"Error deleting Klipper directories: {e}")
|
|
||||||
raise
|
|
||||||
|
|
||||||
Logger.print_ok("Directories successfully deleted.")
|
|
||||||
|
|
||||||
def _prep_service_file(
|
def _prep_service_file(
|
||||||
self, service_template_path: Path, env_file_path: Path
|
self, service_template_path: Path, env_file_path: Path
|
||||||
) -> str:
|
) -> str:
|
||||||
|
|||||||
133
kiauh/modules/klipper/klipper_remove.py
Normal file
133
kiauh/modules/klipper/klipper_remove.py
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# ======================================================================= #
|
||||||
|
# Copyright (C) 2020 - 2023 Dominik Willner <th33xitus@gmail.com> #
|
||||||
|
# #
|
||||||
|
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||||
|
# https://github.com/dw-0/kiauh #
|
||||||
|
# #
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
|
# ======================================================================= #
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
from typing import List, Union
|
||||||
|
|
||||||
|
from kiauh.core.instance_manager.instance_manager import InstanceManager
|
||||||
|
from kiauh.modules.klipper import KLIPPER_DIR, KLIPPER_ENV_DIR
|
||||||
|
from kiauh.modules.klipper.klipper import Klipper
|
||||||
|
from kiauh.modules.klipper.klipper_dialogs import print_instance_overview
|
||||||
|
from kiauh.utils.filesystem_utils import remove_file
|
||||||
|
from kiauh.utils.input_utils import get_selection_input
|
||||||
|
from kiauh.utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
|
def run_klipper_removal(
|
||||||
|
remove_service: bool,
|
||||||
|
remove_dir: bool,
|
||||||
|
remove_env: bool,
|
||||||
|
delete_logs: bool,
|
||||||
|
) -> None:
|
||||||
|
im = InstanceManager(Klipper)
|
||||||
|
|
||||||
|
if remove_service:
|
||||||
|
Logger.print_status("Removing Klipper instances ...")
|
||||||
|
if im.instances:
|
||||||
|
instances_to_remove = select_instances_to_remove(im.instances)
|
||||||
|
remove_instances(im, instances_to_remove)
|
||||||
|
else:
|
||||||
|
Logger.print_info("No Klipper Services installed! Skipped ...")
|
||||||
|
|
||||||
|
im.find_instances()
|
||||||
|
if (remove_dir or remove_env) and im.instances:
|
||||||
|
Logger.print_warn("There are still other Klipper services installed!")
|
||||||
|
Logger.print_warn("Therefor the following parts cannot be removed:")
|
||||||
|
Logger.print_warn(
|
||||||
|
"""
|
||||||
|
● Klipper local repository
|
||||||
|
● Klipper Python environment
|
||||||
|
""",
|
||||||
|
False,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if remove_dir:
|
||||||
|
Logger.print_status("Removing Klipper local repository ...")
|
||||||
|
remove_klipper_dir()
|
||||||
|
if remove_env:
|
||||||
|
Logger.print_status("Removing Klipper Python environment ...")
|
||||||
|
remove_klipper_env()
|
||||||
|
|
||||||
|
# delete klipper logs of all instances
|
||||||
|
if delete_logs:
|
||||||
|
Logger.print_status("Removing all Klipper logs ...")
|
||||||
|
delete_klipper_logs(im.instances)
|
||||||
|
|
||||||
|
|
||||||
|
def select_instances_to_remove(
|
||||||
|
instances: List[Klipper],
|
||||||
|
) -> Union[List[Klipper], None]:
|
||||||
|
print_instance_overview(instances, True, True)
|
||||||
|
|
||||||
|
options = [str(i) for i in range(len(instances))]
|
||||||
|
options.extend(["a", "A", "b", "B"])
|
||||||
|
|
||||||
|
selection = get_selection_input("Select Klipper instance to remove", options)
|
||||||
|
|
||||||
|
instances_to_remove = []
|
||||||
|
if selection == "b".lower():
|
||||||
|
return None
|
||||||
|
elif selection == "a".lower():
|
||||||
|
instances_to_remove.extend(instances)
|
||||||
|
else:
|
||||||
|
instance = instances[int(selection)]
|
||||||
|
instances_to_remove.append(instance)
|
||||||
|
|
||||||
|
return instances_to_remove
|
||||||
|
|
||||||
|
|
||||||
|
def remove_instances(
|
||||||
|
instance_manager: InstanceManager,
|
||||||
|
instance_list: List[Klipper],
|
||||||
|
) -> None:
|
||||||
|
for instance in instance_list:
|
||||||
|
Logger.print_status(f"Removing instance {instance.get_service_file_name()} ...")
|
||||||
|
instance_manager.current_instance = instance
|
||||||
|
instance_manager.stop_instance()
|
||||||
|
instance_manager.disable_instance()
|
||||||
|
instance_manager.delete_instance()
|
||||||
|
|
||||||
|
instance_manager.reload_daemon()
|
||||||
|
|
||||||
|
|
||||||
|
def remove_klipper_dir() -> None:
|
||||||
|
if not KLIPPER_DIR.exists():
|
||||||
|
Logger.print_info(f"'{KLIPPER_DIR}' does not exist. Skipped ...")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
shutil.rmtree(KLIPPER_DIR)
|
||||||
|
except OSError as e:
|
||||||
|
Logger.print_error(f"Unable to delete '{KLIPPER_DIR}':\n{e}")
|
||||||
|
|
||||||
|
|
||||||
|
def remove_klipper_env() -> None:
|
||||||
|
if not KLIPPER_ENV_DIR.exists():
|
||||||
|
Logger.print_info(f"'{KLIPPER_ENV_DIR}' does not exist. Skipped ...")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
shutil.rmtree(KLIPPER_ENV_DIR)
|
||||||
|
except OSError as e:
|
||||||
|
Logger.print_error(f"Unable to delete '{KLIPPER_ENV_DIR}':\n{e}")
|
||||||
|
|
||||||
|
|
||||||
|
def delete_klipper_logs(instances: List[Klipper]) -> None:
|
||||||
|
all_logfiles = []
|
||||||
|
for instance in instances:
|
||||||
|
all_logfiles = list(instance.log_dir.glob("klippy.log*"))
|
||||||
|
if not all_logfiles:
|
||||||
|
Logger.print_info("No Klipper logs found. Skipped ...")
|
||||||
|
return
|
||||||
|
|
||||||
|
for log in all_logfiles:
|
||||||
|
Logger.print_status(f"Remove '{log}'")
|
||||||
|
remove_file(log)
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
# 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 subprocess
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
@@ -40,11 +39,7 @@ from kiauh.modules.klipper.klipper_utils import (
|
|||||||
create_example_printer_cfg,
|
create_example_printer_cfg,
|
||||||
)
|
)
|
||||||
from kiauh.core.repo_manager.repo_manager import RepoManager
|
from kiauh.core.repo_manager.repo_manager import RepoManager
|
||||||
from kiauh.utils.input_utils import (
|
from kiauh.utils.input_utils import get_confirm, get_number_input
|
||||||
get_confirm,
|
|
||||||
get_number_input,
|
|
||||||
get_selection_input,
|
|
||||||
)
|
|
||||||
from kiauh.utils.logger import Logger
|
from kiauh.utils.logger import Logger
|
||||||
from kiauh.utils.system_utils import (
|
from kiauh.utils.system_utils import (
|
||||||
parse_packages_from_file,
|
parse_packages_from_file,
|
||||||
@@ -55,85 +50,52 @@ from kiauh.utils.system_utils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_klipper_setup(install: bool) -> None:
|
def install_klipper() -> None:
|
||||||
instance_manager = InstanceManager(Klipper)
|
im = InstanceManager(Klipper)
|
||||||
instance_list = instance_manager.instances
|
|
||||||
instances_installed = len(instance_list)
|
|
||||||
|
|
||||||
is_klipper_installed = instances_installed > 0
|
add_additional = handle_existing_instances(im.instances)
|
||||||
if not install and not is_klipper_installed:
|
if len(im.instances) > 0 and not add_additional:
|
||||||
Logger.print_warn("Klipper not installed!")
|
|
||||||
return
|
|
||||||
|
|
||||||
if install:
|
|
||||||
add_additional = handle_existing_instances(instance_list)
|
|
||||||
if is_klipper_installed and not add_additional:
|
|
||||||
Logger.print_status(EXIT_KLIPPER_SETUP)
|
Logger.print_status(EXIT_KLIPPER_SETUP)
|
||||||
return
|
return
|
||||||
|
|
||||||
install_klipper(instance_manager, instance_list)
|
|
||||||
|
|
||||||
if not install:
|
|
||||||
if instances_installed == 1:
|
|
||||||
remove_single_instance(instance_manager, instance_list)
|
|
||||||
else:
|
|
||||||
remove_multi_instance(instance_manager, instance_list)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_existing_instances(instance_list: List[Klipper]) -> bool:
|
|
||||||
instance_count = len(instance_list)
|
|
||||||
|
|
||||||
if instance_count > 0:
|
|
||||||
print_instance_overview(instance_list)
|
|
||||||
if not get_confirm("Add new instances?", allow_go_back=True):
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def install_klipper(
|
|
||||||
instance_manager: InstanceManager, instance_list: List[Klipper]
|
|
||||||
) -> None:
|
|
||||||
print_select_instance_count_dialog()
|
print_select_instance_count_dialog()
|
||||||
question = f"Number of{' additional' if len(instance_list) > 0 else ''} Klipper instances to set up"
|
question = f"Number of{' additional' if len(im.instances) > 0 else ''} Klipper instances to set up"
|
||||||
install_count = get_number_input(question, 1, default=1, allow_go_back=True)
|
install_count = get_number_input(question, 1, default=1, allow_go_back=True)
|
||||||
if install_count is None:
|
if install_count is None:
|
||||||
Logger.print_status(EXIT_KLIPPER_SETUP)
|
Logger.print_status(EXIT_KLIPPER_SETUP)
|
||||||
return
|
return
|
||||||
|
|
||||||
instance_names = set_instance_suffix(instance_list, install_count)
|
instance_names = set_instance_suffix(im.instances, install_count)
|
||||||
if instance_names is None:
|
if instance_names is None:
|
||||||
Logger.print_status(EXIT_KLIPPER_SETUP)
|
Logger.print_status(EXIT_KLIPPER_SETUP)
|
||||||
return
|
return
|
||||||
|
|
||||||
create_example_cfg = get_confirm("Create example printer.cfg?")
|
create_example_cfg = get_confirm("Create example printer.cfg?")
|
||||||
|
|
||||||
if len(instance_list) < 1:
|
if len(im.instances) < 1:
|
||||||
setup_klipper_prerequesites()
|
setup_klipper_prerequesites()
|
||||||
|
|
||||||
convert_single_to_multi = (
|
convert_single_to_multi = (
|
||||||
len(instance_list) == 1
|
len(im.instances) == 1 and im.instances[0].suffix is None and install_count >= 1
|
||||||
and instance_list[0].suffix is None
|
|
||||||
and install_count >= 1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for name in instance_names:
|
for name in instance_names:
|
||||||
if convert_single_to_multi:
|
if convert_single_to_multi:
|
||||||
current_instance = handle_single_to_multi_conversion(instance_manager, name)
|
current_instance = handle_single_to_multi_conversion(im, name)
|
||||||
convert_single_to_multi = False
|
convert_single_to_multi = False
|
||||||
else:
|
else:
|
||||||
current_instance = Klipper(suffix=name)
|
current_instance = Klipper(suffix=name)
|
||||||
|
|
||||||
instance_manager.current_instance = current_instance
|
im.current_instance = current_instance
|
||||||
instance_manager.create_instance()
|
im.create_instance()
|
||||||
instance_manager.enable_instance()
|
im.enable_instance()
|
||||||
|
|
||||||
if create_example_cfg:
|
if create_example_cfg:
|
||||||
create_example_printer_cfg(current_instance)
|
create_example_printer_cfg(current_instance)
|
||||||
|
|
||||||
instance_manager.start_instance()
|
im.start_instance()
|
||||||
|
|
||||||
instance_manager.reload_daemon()
|
im.reload_daemon()
|
||||||
|
|
||||||
# step 4: check/handle conflicting packages/services
|
# step 4: check/handle conflicting packages/services
|
||||||
handle_disruptive_system_packages()
|
handle_disruptive_system_packages()
|
||||||
@@ -175,6 +137,17 @@ def install_klipper_packages(klipper_dir: Path) -> None:
|
|||||||
install_system_packages(packages)
|
install_system_packages(packages)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_existing_instances(instance_list: List[Klipper]) -> bool:
|
||||||
|
instance_count = len(instance_list)
|
||||||
|
|
||||||
|
if instance_count > 0:
|
||||||
|
print_instance_overview(instance_list)
|
||||||
|
if not get_confirm("Add new instances?", allow_go_back=True):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def set_instance_suffix(
|
def set_instance_suffix(
|
||||||
instance_list: List[Klipper], install_count: int
|
instance_list: List[Klipper], install_count: int
|
||||||
) -> List[Union[str, None]]:
|
) -> List[Union[str, None]]:
|
||||||
@@ -199,63 +172,6 @@ def set_instance_suffix(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def remove_single_instance(
|
|
||||||
instance_manager: InstanceManager, instance_list: List[Klipper]
|
|
||||||
) -> None:
|
|
||||||
question = f"Delete {KLIPPER_DIR} and {KLIPPER_ENV_DIR}?"
|
|
||||||
del_remnants = get_confirm(question, allow_go_back=True)
|
|
||||||
if del_remnants is None:
|
|
||||||
Logger.print_status("Exiting Klipper Uninstaller ...")
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
instance_manager.current_instance = instance_list[0]
|
|
||||||
instance_manager.stop_instance()
|
|
||||||
instance_manager.disable_instance()
|
|
||||||
instance_manager.delete_instance(del_remnants=del_remnants)
|
|
||||||
instance_manager.reload_daemon()
|
|
||||||
except (OSError, subprocess.CalledProcessError):
|
|
||||||
Logger.print_error("Removing instance failed!")
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def remove_multi_instance(
|
|
||||||
instance_manager: InstanceManager, instance_list: List[Klipper]
|
|
||||||
) -> None:
|
|
||||||
print_instance_overview(instance_list, show_index=True, show_select_all=True)
|
|
||||||
|
|
||||||
options = [str(i) for i in range(len(instance_list))]
|
|
||||||
options.extend(["a", "A", "b", "B"])
|
|
||||||
|
|
||||||
selection = get_selection_input("Select Klipper instance to remove", options)
|
|
||||||
|
|
||||||
if selection == "b".lower():
|
|
||||||
return
|
|
||||||
elif selection == "a".lower():
|
|
||||||
question = f"Delete {KLIPPER_DIR} and {KLIPPER_ENV_DIR}?"
|
|
||||||
del_remnants = get_confirm(question, allow_go_back=True)
|
|
||||||
if del_remnants is None:
|
|
||||||
Logger.print_status("Exiting Klipper Uninstaller ...")
|
|
||||||
return
|
|
||||||
|
|
||||||
Logger.print_status("Removing all Klipper instances ...")
|
|
||||||
for instance in instance_list:
|
|
||||||
instance_manager.current_instance = instance
|
|
||||||
instance_manager.stop_instance()
|
|
||||||
instance_manager.disable_instance()
|
|
||||||
instance_manager.delete_instance(del_remnants=del_remnants)
|
|
||||||
else:
|
|
||||||
instance = instance_list[int(selection)]
|
|
||||||
log = f"Removing Klipper instance: {instance.get_service_file_name()}"
|
|
||||||
Logger.print_status(log)
|
|
||||||
instance_manager.current_instance = instance
|
|
||||||
instance_manager.stop_instance()
|
|
||||||
instance_manager.disable_instance()
|
|
||||||
instance_manager.delete_instance(del_remnants=False)
|
|
||||||
|
|
||||||
instance_manager.reload_daemon()
|
|
||||||
|
|
||||||
|
|
||||||
def update_klipper() -> None:
|
def update_klipper() -> None:
|
||||||
print_update_warn_dialog()
|
print_update_warn_dialog()
|
||||||
if not get_confirm("Update Klipper now?"):
|
if not get_confirm("Update Klipper now?"):
|
||||||
|
|||||||
0
kiauh/modules/klipper/menus/__init__.py
Normal file
0
kiauh/modules/klipper/menus/__init__.py
Normal file
109
kiauh/modules/klipper/menus/klipper_remove_menu.py
Normal file
109
kiauh/modules/klipper/menus/klipper_remove_menu.py
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# ======================================================================= #
|
||||||
|
# Copyright (C) 2020 - 2023 Dominik Willner <th33xitus@gmail.com> #
|
||||||
|
# #
|
||||||
|
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||||
|
# https://github.com/dw-0/kiauh #
|
||||||
|
# #
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
|
# ======================================================================= #
|
||||||
|
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
from kiauh.core.menus import BACK_HELP_FOOTER
|
||||||
|
from kiauh.core.menus.base_menu import BaseMenu
|
||||||
|
from kiauh.modules.klipper import klipper_remove
|
||||||
|
from kiauh.modules.moonraker import moonraker_remove
|
||||||
|
from kiauh.utils.constants import RESET_FORMAT, COLOR_RED, COLOR_CYAN
|
||||||
|
|
||||||
|
|
||||||
|
class KlipperRemoveMenu(BaseMenu):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(
|
||||||
|
header=False,
|
||||||
|
options={
|
||||||
|
0: self.toggle_all,
|
||||||
|
1: self.toggle_remove_klipper_service,
|
||||||
|
2: self.toggle_remove_klipper_dir,
|
||||||
|
3: self.toggle_remove_klipper_env,
|
||||||
|
4: self.toggle_delete_klipper_logs,
|
||||||
|
5: self.run_removal_process,
|
||||||
|
},
|
||||||
|
footer_type=BACK_HELP_FOOTER,
|
||||||
|
)
|
||||||
|
self.remove_klipper_service = False
|
||||||
|
self.remove_klipper_dir = False
|
||||||
|
self.remove_klipper_env = False
|
||||||
|
self.delete_klipper_logs = False
|
||||||
|
|
||||||
|
def print_menu(self) -> None:
|
||||||
|
header = " [ Remove Klipper ] "
|
||||||
|
color = COLOR_RED
|
||||||
|
count = 62 - len(color) - len(RESET_FORMAT)
|
||||||
|
checked = f"[{COLOR_CYAN}x{RESET_FORMAT}]"
|
||||||
|
unchecked = "[ ]"
|
||||||
|
o1 = checked if self.remove_klipper_service else unchecked
|
||||||
|
o2 = checked if self.remove_klipper_dir else unchecked
|
||||||
|
o3 = checked if self.remove_klipper_env else unchecked
|
||||||
|
o4 = checked if self.delete_klipper_logs else unchecked
|
||||||
|
menu = textwrap.dedent(
|
||||||
|
f"""
|
||||||
|
/=======================================================\\
|
||||||
|
| {color}{header:~^{count}}{RESET_FORMAT} |
|
||||||
|
|-------------------------------------------------------|
|
||||||
|
| Enter a number and hit enter to select / deselect |
|
||||||
|
| the specific option for removal. |
|
||||||
|
|-------------------------------------------------------|
|
||||||
|
| 0) Select everything |
|
||||||
|
|-------------------------------------------------------|
|
||||||
|
| 1) {o1} Remove Service |
|
||||||
|
| 2) {o2} Remove Local Repository |
|
||||||
|
| 3) {o3} Remove Python Environment |
|
||||||
|
| 4) {o4} Delete all Log-Files |
|
||||||
|
|-------------------------------------------------------|
|
||||||
|
| 5) Continue |
|
||||||
|
"""
|
||||||
|
)[1:]
|
||||||
|
print(menu, end="")
|
||||||
|
|
||||||
|
def toggle_all(self) -> None:
|
||||||
|
self.remove_klipper_service = True
|
||||||
|
self.remove_klipper_dir = True
|
||||||
|
self.remove_klipper_env = True
|
||||||
|
self.delete_klipper_logs = True
|
||||||
|
|
||||||
|
def toggle_remove_klipper_service(self) -> None:
|
||||||
|
self.remove_klipper_service = not self.remove_klipper_service
|
||||||
|
|
||||||
|
def toggle_remove_klipper_dir(self) -> None:
|
||||||
|
self.remove_klipper_dir = not self.remove_klipper_dir
|
||||||
|
|
||||||
|
def toggle_remove_klipper_env(self) -> None:
|
||||||
|
self.remove_klipper_env = not self.remove_klipper_env
|
||||||
|
|
||||||
|
def toggle_delete_klipper_logs(self) -> None:
|
||||||
|
self.delete_klipper_logs = not self.delete_klipper_logs
|
||||||
|
|
||||||
|
def run_removal_process(self) -> None:
|
||||||
|
if (
|
||||||
|
not self.remove_klipper_service
|
||||||
|
and not self.remove_klipper_dir
|
||||||
|
and not self.remove_klipper_env
|
||||||
|
and not self.delete_klipper_logs
|
||||||
|
):
|
||||||
|
error = f"{COLOR_RED}Nothing selected! Select options to remove first.{RESET_FORMAT}"
|
||||||
|
print(error)
|
||||||
|
return
|
||||||
|
|
||||||
|
klipper_remove.run_klipper_removal(
|
||||||
|
self.remove_klipper_service,
|
||||||
|
self.remove_klipper_dir,
|
||||||
|
self.remove_klipper_env,
|
||||||
|
self.delete_klipper_logs,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.remove_klipper_service = False
|
||||||
|
self.remove_klipper_dir = False
|
||||||
|
self.remove_klipper_env = False
|
||||||
|
self.delete_klipper_logs = False
|
||||||
Reference in New Issue
Block a user