[gnome-continuous-yocto/gnomeostree-3.28-rocko: 6434/8267] wic/runner.py: move runtool API to misc.py



commit a0536e61dcea2e7207a8933c6fad71c2c1cdf21a
Author: Ed Bartosh <ed bartosh linux intel com>
Date:   Fri Jun 16 16:19:27 2017 +0300

    wic/runner.py: move runtool API to misc.py
    
    Moved remaining API to misc.py.
    Removed runner.py.
    
    Now misc.py is ready to be moved to the scripts/lib/wic and
    utils directory can be removed.
    
    (From OE-Core rev: 327e340a29d330f24117e24d0649fa156017208f)
    
    Signed-off-by: Ed Bartosh <ed bartosh linux intel com>
    Signed-off-by: Ross Burton <ross burton intel com>
    Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>

 scripts/lib/wic/misc.py         |   39 +++++++++++++++++++++++++++--
 scripts/lib/wic/utils/runner.py |   52 ---------------------------------------
 2 files changed, 36 insertions(+), 55 deletions(-)
---
diff --git a/scripts/lib/wic/misc.py b/scripts/lib/wic/misc.py
index 8a38f2f..3ebae0a 100644
--- a/scripts/lib/wic/misc.py
+++ b/scripts/lib/wic/misc.py
@@ -29,12 +29,12 @@
 import logging
 import os
 import re
+import subprocess
 
 from collections import defaultdict
 from distutils import spawn
 
 from wic import WicError
-from wic.utils import runner
 
 logger = logging.getLogger('wic')
 
@@ -59,6 +59,39 @@ NATIVE_RECIPES = {"bmaptool": "bmap-tools",
                   "syslinux": "syslinux"
                  }
 
+def runtool(cmdln_or_args):
+    """ wrapper for most of the subprocess calls
+    input:
+        cmdln_or_args: can be both args and cmdln str (shell=True)
+    return:
+        rc, output
+    """
+    if isinstance(cmdln_or_args, list):
+        cmd = cmdln_or_args[0]
+        shell = False
+    else:
+        import shlex
+        cmd = shlex.split(cmdln_or_args)[0]
+        shell = True
+
+    sout = subprocess.PIPE
+    serr = subprocess.STDOUT
+
+    try:
+        process = subprocess.Popen(cmdln_or_args, stdout=sout,
+                                   stderr=serr, shell=shell)
+        sout, serr = process.communicate()
+        # combine stdout and stderr, filter None out and decode
+        out = ''.join([out.decode('utf-8') for out in [sout, serr] if out])
+    except OSError as err:
+        if err.errno == 2:
+            # [Errno 2] No such file or directory
+            raise WicError('Cannot run command: %s, lost dependency?' % cmd)
+        else:
+            raise # relay
+
+    return process.returncode, out
+
 def _exec_cmd(cmd_and_args, as_shell=False):
     """
     Execute command, catching stderr, stdout
@@ -70,9 +103,9 @@ def _exec_cmd(cmd_and_args, as_shell=False):
     logger.debug(args)
 
     if as_shell:
-        ret, out = runner.runtool(cmd_and_args)
+        ret, out = runtool(cmd_and_args)
     else:
-        ret, out = runner.runtool(args)
+        ret, out = runtool(args)
     out = out.strip()
     if ret != 0:
         raise WicError("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]