summaryrefslogtreecommitdiff
path: root/scripts/lib/wic/utils/runner.py
diff options
context:
space:
mode:
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 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-import logging
-import os
import subprocess
from wic import WicError
-logger = logging.getLogger('wic')
-
-def runtool(cmdln_or_args, catch=1):
+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)
- catch: 0, quitely run
- 1, only STDOUT
- 2, only STDERR
- 3, both STDOUT and STDERR
return:
- (rc, output)
- if catch==0: the output will always None
+ rc, output
"""
-
- if catch not in (0, 1, 2, 3):
- # invalid catch selection, will cause exception, that's good
- return None
-
if isinstance(cmdln_or_args, list):
cmd = cmdln_or_args[0]
shell = False
@@ -48,26 +33,13 @@ def runtool(cmdln_or_args, catch=1):
cmd = shlex.split(cmdln_or_args)[0]
shell = True
- if catch != 3:
- dev_null = os.open("/dev/null", os.O_WRONLY)
-
- if catch == 0:
- sout = dev_null
- serr = dev_null
- elif catch == 1:
- sout = subprocess.PIPE
- serr = dev_null
- elif catch == 2:
- sout = dev_null
- serr = subprocess.PIPE
- elif catch == 3:
- sout = subprocess.PIPE
- serr = subprocess.STDOUT
+ sout = subprocess.PIPE
+ serr = subprocess.STDOUT
try:
process = subprocess.Popen(cmdln_or_args, stdout=sout,
stderr=serr, shell=shell)
- (sout, serr) = process.communicate()
+ 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:
@@ -76,15 +48,5 @@ def runtool(cmdln_or_args, catch=1):
raise WicError('Cannot run command: %s, lost dependency?' % cmd)
else:
raise # relay
- finally:
- if catch != 3:
- os.close(dev_null)
-
- return (process.returncode, out)
-
-def outs(cmdln_or_args, catch=1):
- # get the outputs of tools
- return runtool(cmdln_or_args, catch)[1].strip()
-def quiet(cmdln_or_args):
- return runtool(cmdln_or_args, catch=0)[0]
+ return process.returncode, out