From d5eb5ee0f27ee48f79d9e9a87efe70be8ed2f689 Mon Sep 17 00:00:00 2001 From: Jaroslava Fiedlerova Date: Thu, 28 Dec 2023 12:00:14 +0100 Subject: [PATCH] Support for context manager in cls_cmd SSH class --- ci-scripts/cls_cmd.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ci-scripts/cls_cmd.py b/ci-scripts/cls_cmd.py index 30f00cdb02..e2a735fa35 100644 --- a/ci-scripts/cls_cmd.py +++ b/ci-scripts/cls_cmd.py @@ -86,6 +86,12 @@ class Cmd(metaclass=abc.ABCMeta): return class LocalCmd(Cmd): + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, exc_traceback): + self.close() + def __init__(self, d = None): self.cwd = d if self.cwd is not None: @@ -128,6 +134,12 @@ class LocalCmd(Cmd): self.copyin(src, tgt, recursive) class RemoteCmd(Cmd): + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, exc_traceback): + self.close() + def __init__(self, hostname, d=None): cIdx = 0 logging.getLogger('paramiko').setLevel(logging.ERROR) # prevent spamming through Paramiko