summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-03-26 20:39:22 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-04-01 08:14:57 +0100
commitad1bce56c43cf4758b4974f95736cfef3840c246 (patch)
tree3b0b201eed1f7a1a41acc0d5938252e4f6b1a42f /scripts
parentd39a1588556d0063ac9c2dd7ed310826db41e677 (diff)
downloadpoky-ad1bce56c43cf4758b4974f95736cfef3840c246.tar.gz
wic: remove unused code from runner module
Removed unused APIs 'outs' and 'quiet'. Removed 'catch' parameter from runner.runtool API as wic uses only one value of it. Removed the code that handles unused values of 'catch' parameter. [YOCTO #10618] (From OE-Core rev: 1e45a4f72b16c7ab64f46907d2d2ee9cd749dc23) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/wic/utils/misc.py14
-rw-r--r--scripts/lib/wic/utils/runner.py50
2 files changed, 13 insertions, 51 deletions
diff --git a/scripts/lib/wic/utils/misc.py b/scripts/lib/wic/utils/misc.py
index c941112c63..307779aad5 100644
--- a/scripts/lib/wic/utils/misc.py
+++ b/scripts/lib/wic/utils/misc.py
@@ -59,7 +59,7 @@ NATIVE_RECIPES = {"bmaptool": "bmap-tools",
59 "syslinux": "syslinux" 59 "syslinux": "syslinux"
60 } 60 }
61 61
62def _exec_cmd(cmd_and_args, as_shell=False, catch=3): 62def _exec_cmd(cmd_and_args, as_shell=False):
63 """ 63 """
64 Execute command, catching stderr, stdout 64 Execute command, catching stderr, stdout
65 65
@@ -70,9 +70,9 @@ def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
70 logger.debug(args) 70 logger.debug(args)
71 71
72 if as_shell: 72 if as_shell:
73 ret, out = runner.runtool(cmd_and_args, catch) 73 ret, out = runner.runtool(cmd_and_args)
74 else: 74 else:
75 ret, out = runner.runtool(args, catch) 75 ret, out = runner.runtool(args)
76 out = out.strip() 76 out = out.strip()
77 if ret != 0: 77 if ret != 0:
78 raise WicError("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \ 78 raise WicError("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
@@ -84,14 +84,14 @@ def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
84 return ret, out 84 return ret, out
85 85
86 86
87def exec_cmd(cmd_and_args, as_shell=False, catch=3): 87def exec_cmd(cmd_and_args, as_shell=False):
88 """ 88 """
89 Execute command, return output 89 Execute command, return output
90 """ 90 """
91 return _exec_cmd(cmd_and_args, as_shell, catch)[1] 91 return _exec_cmd(cmd_and_args, as_shell)[1]
92 92
93 93
94def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""): 94def exec_native_cmd(cmd_and_args, native_sysroot, pseudo=""):
95 """ 95 """
96 Execute native command, catching stderr, stdout 96 Execute native command, catching stderr, stdout
97 97
@@ -118,7 +118,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
118 118
119 # If the command isn't in the native sysroot say we failed. 119 # If the command isn't in the native sysroot say we failed.
120 if spawn.find_executable(args[0], native_paths): 120 if spawn.find_executable(args[0], native_paths):
121 ret, out = _exec_cmd(native_cmd_and_args, True, catch) 121 ret, out = _exec_cmd(native_cmd_and_args, True)
122 else: 122 else:
123 ret = 127 123 ret = 127
124 out = "can't find native executable %s in %s" % (args[0], native_paths) 124 out = "can't find native executable %s in %s" % (args[0], native_paths)
diff --git a/scripts/lib/wic/utils/runner.py b/scripts/lib/wic/utils/runner.py
index 348557aee8..4aa00fbe20 100644
--- a/scripts/lib/wic/utils/runner.py
+++ b/scripts/lib/wic/utils/runner.py
@@ -14,32 +14,17 @@
14# You should have received a copy of the GNU General Public License along 14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc., 59 15# with this program; if not, write to the Free Software Foundation, Inc., 59
16# Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18import logging
19import os
20import subprocess 17import subprocess
21 18
22from wic import WicError 19from wic import WicError
23 20
24logger = logging.getLogger('wic') 21def runtool(cmdln_or_args):
25
26def runtool(cmdln_or_args, catch=1):
27 """ wrapper for most of the subprocess calls 22 """ wrapper for most of the subprocess calls
28 input: 23 input:
29 cmdln_or_args: can be both args and cmdln str (shell=True) 24 cmdln_or_args: can be both args and cmdln str (shell=True)
30 catch: 0, quitely run
31 1, only STDOUT
32 2, only STDERR
33 3, both STDOUT and STDERR
34 return: 25 return:
35 (rc, output) 26 rc, output
36 if catch==0: the output will always None
37 """ 27 """
38
39 if catch not in (0, 1, 2, 3):
40 # invalid catch selection, will cause exception, that's good
41 return None
42
43 if isinstance(cmdln_or_args, list): 28 if isinstance(cmdln_or_args, list):
44 cmd = cmdln_or_args[0] 29 cmd = cmdln_or_args[0]
45 shell = False 30 shell = False
@@ -48,26 +33,13 @@ def runtool(cmdln_or_args, catch=1):
48 cmd = shlex.split(cmdln_or_args)[0] 33 cmd = shlex.split(cmdln_or_args)[0]
49 shell = True 34 shell = True
50 35
51 if catch != 3: 36 sout = subprocess.PIPE
52 dev_null = os.open("/dev/null", os.O_WRONLY) 37 serr = subprocess.STDOUT
53
54 if catch == 0:
55 sout = dev_null
56 serr = dev_null
57 elif catch == 1:
58 sout = subprocess.PIPE
59 serr = dev_null
60 elif catch == 2:
61 sout = dev_null
62 serr = subprocess.PIPE
63 elif catch == 3:
64 sout = subprocess.PIPE
65 serr = subprocess.STDOUT
66 38
67 try: 39 try:
68 process = subprocess.Popen(cmdln_or_args, stdout=sout, 40 process = subprocess.Popen(cmdln_or_args, stdout=sout,
69 stderr=serr, shell=shell) 41 stderr=serr, shell=shell)
70 (sout, serr) = process.communicate() 42 sout, serr = process.communicate()
71 # combine stdout and stderr, filter None out and decode 43 # combine stdout and stderr, filter None out and decode
72 out = ''.join([out.decode('utf-8') for out in [sout, serr] if out]) 44 out = ''.join([out.decode('utf-8') for out in [sout, serr] if out])
73 except OSError as err: 45 except OSError as err:
@@ -76,15 +48,5 @@ def runtool(cmdln_or_args, catch=1):
76 raise WicError('Cannot run command: %s, lost dependency?' % cmd) 48 raise WicError('Cannot run command: %s, lost dependency?' % cmd)
77 else: 49 else:
78 raise # relay 50 raise # relay
79 finally:
80 if catch != 3:
81 os.close(dev_null)
82
83 return (process.returncode, out)
84
85def outs(cmdln_or_args, catch=1):
86 # get the outputs of tools
87 return runtool(cmdln_or_args, catch)[1].strip()
88 51
89def quiet(cmdln_or_args): 52 return process.returncode, out
90 return runtool(cmdln_or_args, catch=0)[0]