mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 08:43:36 +05:00
refactor: allow to also check for timer unit files
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -23,7 +23,7 @@ from extensions.klipper_backup import (
|
||||
)
|
||||
from utils.fs_utils import check_file_exist
|
||||
from utils.input_utils import get_confirm
|
||||
from utils.sys_utils import service_instance_exists
|
||||
from utils.sys_utils import unit_file_exists
|
||||
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
@@ -114,7 +114,7 @@ class KlipperbackupExtension(BaseExtension):
|
||||
Logger.print_status(
|
||||
f"Check whether the {service_name} service is installed ..."
|
||||
)
|
||||
if service_instance_exists(service_name):
|
||||
if unit_file_exists(service_name, "service"):
|
||||
Logger.print_info(f"Service {service_name} detected.")
|
||||
if uninstall_service(service_name):
|
||||
Logger.print_ok(
|
||||
|
||||
@@ -401,15 +401,18 @@ def cmd_sysctl_manage(action: SysCtlManageAction) -> None:
|
||||
raise
|
||||
|
||||
|
||||
def service_instance_exists(name: str, exclude: List[str] | None = None) -> bool:
|
||||
def unit_file_exists(
|
||||
name: str, suffix: Literal["service", "timer"], exclude: List[str] | None = None
|
||||
) -> bool:
|
||||
"""
|
||||
Checks if a systemd service instance exists.
|
||||
:param name: the service name
|
||||
:param exclude: List of strings of service names to exclude
|
||||
:return: True if the service exists, False otherwise
|
||||
Checks if a systemd unit file of the provided suffix exists.
|
||||
:param name: the name of the unit file
|
||||
:param suffix: suffix of the unit file, either "service" or "timer"
|
||||
:param exclude: List of strings of names to exclude
|
||||
:return: True if the unit file exists, False otherwise
|
||||
"""
|
||||
exclude = exclude or []
|
||||
pattern = re.compile(f"^{name}(-[0-9a-zA-Z]+)?.service$")
|
||||
pattern = re.compile(f"^{name}(-[0-9a-zA-Z]+)?.{suffix}$")
|
||||
service_list = [
|
||||
Path(SYSTEMD, service)
|
||||
for service in SYSTEMD.iterdir()
|
||||
|
||||
Reference in New Issue
Block a user