[elbe-devel] [PATCH] elbepack: shellhelper: don't log CMD if output is not also logged

Thomas Weißschuh thomas.weissschuh at linutronix.de
Tue Jun 11 09:59:23 CEST 2024


If the command output is not going to be logged, also inhibit the log
about the command itself, as it would confuse the user.

Fixes: 1da35a273dcf ("elbepack: shellhelper: introduce run() function")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/shellhelper.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/elbepack/shellhelper.py b/elbepack/shellhelper.py
index 59982ed67360..108bce09f914 100644
--- a/elbepack/shellhelper.py
+++ b/elbepack/shellhelper.py
@@ -75,6 +75,9 @@ def run(cmd, /, *, check=True, log_cmd=None, **kwargs):
     ELBE
     ELBE
     CompletedProcess(args=['echo', 'ELBE'], returncode=0)
+
+    >>> run(['echo', 'ELBE'], capture_output=True)
+    CompletedProcess(args=['echo', 'ELBE'], returncode=0, stdout=b'ELBE\\n', stderr=b'')
     """
     stdout = kwargs.pop('stdout', None)
     stderr = kwargs.pop('stderr', None)
@@ -87,7 +90,8 @@ def run(cmd, /, *, check=True, log_cmd=None, **kwargs):
             if stderr is ELBE_LOGGING:
                 stderr = log_fd
 
-        logging.info(log_cmd or _log_cmd(cmd), extra={'context': '[CMD] '})
+            logging.info(log_cmd or _log_cmd(cmd), extra={'context': '[CMD] '})
+
         return subprocess.run(cmd, stdout=stdout, stderr=stderr, check=check, **kwargs)
 
 

---
base-commit: 29a68241db75756ba6e80e3c60bb5fd5f2be8bd9
change-id: 20240604-shellhelper-run-log-a9cf682b9ecb

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh at linutronix.de>



More information about the elbe-devel mailing list