refactor(Klipper): add some exception handling
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -74,6 +74,7 @@ def install_klipper() -> None:
|
||||
|
||||
create_example_cfg = get_confirm("Create example printer.cfg?")
|
||||
|
||||
try:
|
||||
if not kl_im.instances:
|
||||
setup_klipper_prerequesites()
|
||||
|
||||
@@ -94,6 +95,10 @@ def install_klipper() -> None:
|
||||
|
||||
kl_im.reload_daemon()
|
||||
|
||||
except Exception:
|
||||
Logger.print_error("Klipper installation failed!")
|
||||
return
|
||||
|
||||
# step 4: check/handle conflicting packages/services
|
||||
handle_disruptive_system_packages()
|
||||
|
||||
@@ -114,9 +119,13 @@ def setup_klipper_prerequesites() -> None:
|
||||
repo_manager.clone_repo()
|
||||
|
||||
# install klipper dependencies and create python virtualenv
|
||||
try:
|
||||
install_klipper_packages(KLIPPER_DIR)
|
||||
create_python_venv(KLIPPER_ENV_DIR)
|
||||
install_python_requirements(KLIPPER_ENV_DIR, KLIPPER_REQUIREMENTS_TXT)
|
||||
except Exception:
|
||||
Logger.print_error("Error during installation of Klipper requirements!")
|
||||
raise
|
||||
|
||||
|
||||
def install_klipper_packages(klipper_dir: Path) -> None:
|
||||
|
||||
@@ -73,8 +73,10 @@ def create_python_venv(target: Path) -> None:
|
||||
Logger.print_ok("Setup of virtualenv successfull!")
|
||||
except OSError as e:
|
||||
Logger.print_error(f"Error setting up virtualenv:\n{e}")
|
||||
raise
|
||||
except subprocess.CalledProcessError as e:
|
||||
Logger.print_error(f"Error setting up virtualenv:\n{e.output.decode()}")
|
||||
raise
|
||||
else:
|
||||
if get_confirm("Virtualenv already exists. Re-create?", default_choice=False):
|
||||
try:
|
||||
@@ -83,6 +85,7 @@ def create_python_venv(target: Path) -> None:
|
||||
except OSError as e:
|
||||
log = f"Error removing existing virtualenv: {e.strerror}"
|
||||
Logger.print_error(log, False)
|
||||
raise
|
||||
else:
|
||||
Logger.print_info("Skipping re-creation of virtualenv ...")
|
||||
|
||||
@@ -128,6 +131,7 @@ def install_python_requirements(target: Path, requirements: Path) -> None:
|
||||
except subprocess.CalledProcessError as e:
|
||||
log = f"Error installing Python requirements:\n{e.output.decode()}"
|
||||
Logger.print_error(log)
|
||||
raise
|
||||
|
||||
|
||||
def update_system_package_lists(silent: bool, rls_info_change=False) -> None:
|
||||
|
||||
Reference in New Issue
Block a user