[Kimchi-devel] [PATCH 1/2] Add option 'silent' in run_command

Jose Ricardo Ziviani joserz at linux.vnet.ibm.com
Thu Jul 23 13:56:10 UTC 2015


 - With this new option the caller can choose if run_command errors will
   be logged as error or debug. There are cases where a command error is
   expected and don't need to alert users.

Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
 src/kimchi/utils.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
index ff3a5da..baf2d62 100644
--- a/src/kimchi/utils.py
+++ b/src/kimchi/utils.py
@@ -165,11 +165,13 @@ def check_url_path(path):
     return True
 
 
-def run_command(cmd, timeout=None):
+def run_command(cmd, timeout=None, silent=False):
     """
     cmd is a sequence of command arguments.
     timeout is a float number in seconds.
     timeout default value is None, means command run without timeout.
+    silent is bool, it will log errors using debug handler not error.
+    silent default value is False.
     """
     # subprocess.kill() can leave descendants running
     # and halting the execution. Using psutil to
@@ -206,8 +208,14 @@ def run_command(cmd, timeout=None):
             kimchi_log.debug("out:\n%s", out)
 
         if proc.returncode != 0:
-            kimchi_log.error("rc: %s error: %s returned from cmd: %s",
-                             proc.returncode, error, ' '.join(cmd))
+            msg = "rc: %s error: %s returned from cmd: %s" %\
+                  (proc.returncode, error, ' '.join(cmd))
+
+            if silent:
+                kimchi_log.debug(msg)
+
+            else:
+                kimchi_log.error(msg)
         elif error:
             kimchi_log.debug("error: %s returned from cmd: %s",
                              error, ' '.join(cmd))
-- 
1.9.1




More information about the Kimchi-devel mailing list