From d9f66f069c20afd8edc90011935f215bb4ec0aad Mon Sep 17 00:00:00 2001 From: ldericher <40151420+ldericher@users.noreply.github.com> Date: Thu, 2 Dec 2021 02:48:41 +0100 Subject: [PATCH] Service.has_executable --- kiwi_scp/instance.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kiwi_scp/instance.py b/kiwi_scp/instance.py index 3d47c87..8cf1f80 100644 --- a/kiwi_scp/instance.py +++ b/kiwi_scp/instance.py @@ -33,6 +33,19 @@ class Service: if cd_match: yield Path(cd_match.group(1)) + def has_executable(self, exe_name: str) -> bool: + try: + # test if desired executable exists + COMPOSE_EXE.run( + ["exec", "-T", self.name, "/bin/sh", "-c", f"command -v {exe_name}"], + check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + **self.parent.process_kwargs, + ) + return True + + except subprocess.CalledProcessError: + return False + @attr.s class Services: