summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/utils/runner.py
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/lib/wic/utils/runner.py
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/lib/wic/utils/runner.py')
-rw-r--r--scripts/lib/wic/utils/runner.py50
1 files changed, 6 insertions, 44 deletions
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]