refactor(Klipper): add some exception handling
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -74,25 +74,30 @@ def install_klipper() -> None:
|
||||
|
||||
create_example_cfg = get_confirm("Create example printer.cfg?")
|
||||
|
||||
if not kl_im.instances:
|
||||
setup_klipper_prerequesites()
|
||||
try:
|
||||
if not kl_im.instances:
|
||||
setup_klipper_prerequesites()
|
||||
|
||||
count = 0
|
||||
for name in name_dict:
|
||||
if name_dict[name] in [n.suffix for n in kl_im.instances]:
|
||||
continue
|
||||
count = 0
|
||||
for name in name_dict:
|
||||
if name_dict[name] in [n.suffix for n in kl_im.instances]:
|
||||
continue
|
||||
|
||||
if check_is_single_to_multi_conversion(kl_im.instances):
|
||||
handle_to_multi_instance_conversion(name_dict[name])
|
||||
continue
|
||||
if check_is_single_to_multi_conversion(kl_im.instances):
|
||||
handle_to_multi_instance_conversion(name_dict[name])
|
||||
continue
|
||||
|
||||
count += 1
|
||||
create_klipper_instance(name_dict[name], create_example_cfg)
|
||||
count += 1
|
||||
create_klipper_instance(name_dict[name], create_example_cfg)
|
||||
|
||||
if count == install_count:
|
||||
break
|
||||
if count == install_count:
|
||||
break
|
||||
|
||||
kl_im.reload_daemon()
|
||||
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
|
||||
install_klipper_packages(KLIPPER_DIR)
|
||||
create_python_venv(KLIPPER_ENV_DIR)
|
||||
install_python_requirements(KLIPPER_ENV_DIR, KLIPPER_REQUIREMENTS_TXT)
|
||||
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