Service.has_executable

This commit is contained in:
Jörn-Michael Miehe 2021-12-02 02:48:41 +01:00
parent 0fc55154f2
commit d9f66f069c

View file

@ -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: