diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2017-06-16 16:19:27 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-23 11:44:12 +0100 |
commit | a0536e61dcea2e7207a8933c6fad71c2c1cdf21a (patch) | |
tree | 5347917f6d52d9cd31bdc74c4c84aa465612088c /scripts/lib/wic/misc.py | |
parent | 44023e6c41a57d93d7b3a7c6d297e1ca77cd69ff (diff) | |
download | poky-a0536e61dcea2e7207a8933c6fad71c2c1cdf21a.tar.gz |
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>
Diffstat (limited to 'scripts/lib/wic/misc.py')
-rw-r--r-- | scripts/lib/wic/misc.py | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/scripts/lib/wic/misc.py b/scripts/lib/wic/misc.py index 8a38f2f479..3ebae0a6e0 100644 --- a/scripts/lib/wic/misc.py +++ b/scripts/lib/wic/misc.py | |||
@@ -29,12 +29,12 @@ | |||
29 | import logging | 29 | import logging |
30 | import os | 30 | import os |
31 | import re | 31 | import re |
32 | import subprocess | ||
32 | 33 | ||
33 | from collections import defaultdict | 34 | from collections import defaultdict |
34 | from distutils import spawn | 35 | from distutils import spawn |
35 | 36 | ||
36 | from wic import WicError | 37 | from wic import WicError |
37 | from wic.utils import runner | ||
38 | 38 | ||
39 | logger = logging.getLogger('wic') | 39 | logger = logging.getLogger('wic') |
40 | 40 | ||
@@ -59,6 +59,39 @@ NATIVE_RECIPES = {"bmaptool": "bmap-tools", | |||
59 | "syslinux": "syslinux" | 59 | "syslinux": "syslinux" |
60 | } | 60 | } |
61 | 61 | ||
62 | def runtool(cmdln_or_args): | ||
63 | """ wrapper for most of the subprocess calls | ||
64 | input: | ||
65 | cmdln_or_args: can be both args and cmdln str (shell=True) | ||
66 | return: | ||
67 | rc, output | ||
68 | """ | ||
69 | if isinstance(cmdln_or_args, list): | ||
70 | cmd = cmdln_or_args[0] | ||
71 | shell = False | ||
72 | else: | ||
73 | import shlex | ||
74 | cmd = shlex.split(cmdln_or_args)[0] | ||
75 | shell = True | ||
76 | |||
77 | sout = subprocess.PIPE | ||
78 | serr = subprocess.STDOUT | ||
79 | |||
80 | try: | ||
81 | process = subprocess.Popen(cmdln_or_args, stdout=sout, | ||
82 | stderr=serr, shell=shell) | ||
83 | sout, serr = process.communicate() | ||
84 | # combine stdout and stderr, filter None out and decode | ||
85 | out = ''.join([out.decode('utf-8') for out in [sout, serr] if out]) | ||
86 | except OSError as err: | ||
87 | if err.errno == 2: | ||
88 | # [Errno 2] No such file or directory | ||
89 | raise WicError('Cannot run command: %s, lost dependency?' % cmd) | ||
90 | else: | ||
91 | raise # relay | ||
92 | |||
93 | return process.returncode, out | ||
94 | |||
62 | def _exec_cmd(cmd_and_args, as_shell=False): | 95 | def _exec_cmd(cmd_and_args, as_shell=False): |
63 | """ | 96 | """ |
64 | Execute command, catching stderr, stdout | 97 | Execute command, catching stderr, stdout |
@@ -70,9 +103,9 @@ def _exec_cmd(cmd_and_args, as_shell=False): | |||
70 | logger.debug(args) | 103 | logger.debug(args) |
71 | 104 | ||
72 | if as_shell: | 105 | if as_shell: |
73 | ret, out = runner.runtool(cmd_and_args) | 106 | ret, out = runtool(cmd_and_args) |
74 | else: | 107 | else: |
75 | ret, out = runner.runtool(args) | 108 | ret, out = runtool(args) |
76 | out = out.strip() | 109 | out = out.strip() |
77 | if ret != 0: | 110 | if ret != 0: |
78 | raise WicError("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \ | 111 | raise WicError("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \ |