Update klipper_backup_extension.py
This commit is contained in:
@@ -46,6 +46,7 @@ class KlipperbackupExtension(BaseExtension):
|
|||||||
def is_service_installed(service_name):
|
def is_service_installed(service_name):
|
||||||
command = ["systemctl", "status", service_name]
|
command = ["systemctl", "status", service_name]
|
||||||
result = subprocess.run(command, capture_output=True, text=True)
|
result = subprocess.run(command, capture_output=True, text=True)
|
||||||
|
# Doesn't matter whether the service is active or not, what matters is whether it is installed. So let's search for "Loaded:" in stdout
|
||||||
if "Loaded:" in result.stdout:
|
if "Loaded:" in result.stdout:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@@ -58,9 +59,9 @@ class KlipperbackupExtension(BaseExtension):
|
|||||||
subprocess.run(["sudo", "systemctl", "daemon-reload"], check=True)
|
subprocess.run(["sudo", "systemctl", "daemon-reload"], check=True)
|
||||||
service_path = f'/etc/systemd/system/{service_name}'
|
service_path = f'/etc/systemd/system/{service_name}'
|
||||||
os.system(f'sudo rm {service_path}')
|
os.system(f'sudo rm {service_path}')
|
||||||
Logger.print_ok(f"The service {service_name} has been successfully uninstalled.")
|
return True
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
Logger.print_error(f"Error uninstalling the service {service_name}.")
|
return False
|
||||||
|
|
||||||
def check_crontab_entry(entry):
|
def check_crontab_entry(entry):
|
||||||
try:
|
try:
|
||||||
@@ -103,7 +104,10 @@ class KlipperbackupExtension(BaseExtension):
|
|||||||
Logger.print_status(f"Check whether the service {service_name} is installed ...")
|
Logger.print_status(f"Check whether the service {service_name} is installed ...")
|
||||||
if is_service_installed(service_name):
|
if is_service_installed(service_name):
|
||||||
Logger.print_info(f"Service {service_name} detected.")
|
Logger.print_info(f"Service {service_name} detected.")
|
||||||
uninstall_service(service_name)
|
if uninstall_service(service_name):
|
||||||
|
Logger.print_ok(f"The service {service_name} has been successfully uninstalled.")
|
||||||
|
else:
|
||||||
|
Logger.print_error(f"Error uninstalling the service {service_name}.")
|
||||||
else:
|
else:
|
||||||
Logger.print_info(f"The service {service_name} is not installed. Skipping ...")
|
Logger.print_info(f"The service {service_name} is not installed. Skipping ...")
|
||||||
except:
|
except:
|
||||||
@@ -142,4 +146,4 @@ class KlipperbackupExtension(BaseExtension):
|
|||||||
shutil.rmtree(KLIPPERBACKUP_CONFIG_DIR)
|
shutil.rmtree(KLIPPERBACKUP_CONFIG_DIR)
|
||||||
Logger.print_ok("Extension Klipper-Backup successfully removed!")
|
Logger.print_ok("Extension Klipper-Backup successfully removed!")
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
Logger.print_error(f"Unable to remove extension: {e}")
|
Logger.print_error(f"Unable to remove extension: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user