Pylint for common/runner.py and cleanups
authorLingchaox Xin <lingchaox.xin@intel.com>
Thu, 20 Jun 2013 02:55:25 +0000 (10:55 +0800)
committerLingchaox Xin <lingchaox.xin@intel.com>
Fri, 21 Jun 2013 07:44:47 +0000 (15:44 +0800)
Change-Id: I384d50dc13c07f129e1e8f30bbd4691c671e7f1e

common/runner.py

index a49b894..649c0e1 100644 (file)
 # with this program; if not, write to the Free Software Foundation, Inc., 59
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+"""A runtool which wraps subprocess related"""
+
 import os
+import shlex
 import subprocess
 
 def runtool(cmdln_or_args, catch=1):
@@ -37,28 +40,21 @@ def runtool(cmdln_or_args, catch=1):
         return None
 
     if isinstance(cmdln_or_args, list):
-        cmd = cmdln_or_args[0]
-        shell = False
+        cmd, shell = cmdln_or_args[0], False
     else:
-        import shlex
-        cmd = shlex.split(cmdln_or_args)[0]
-        shell = True
+        cmd, shell = shlex.split(cmdln_or_args)[0], True
 
     if catch != 3:
         dev_null = os.open("/dev/null", os.O_WRONLY)
 
     if catch == 0:
-        sout = dev_null
-        serr = dev_null
+        sout, serr = dev_null, dev_null
     elif catch == 1:
-        sout = subprocess.PIPE
-        serr = dev_null
+        sout, serr = subprocess.PIPE, dev_null
     elif catch == 2:
-        sout = dev_null
-        serr = subprocess.PIPE
+        sout, serr = dev_null, subprocess.PIPE
     elif catch == 3:
-        sout = subprocess.PIPE
-        serr = subprocess.STDOUT
+        sout, serr = subprocess.PIPE, subprocess.STDOUT
 
     try:
         process = subprocess.Popen(cmdln_or_args, stdout=sout,
@@ -76,11 +72,10 @@ def runtool(cmdln_or_args, catch=1):
         if catch != 3:
             os.close(dev_null)
 
-    #print 'execute cmd: %s\nreturncode: %s\n%s' %(cmdln_or_args, process.returncode, out) 
     return (process.returncode, out)
 
 def show(cmdln_or_args):
-    # show all the message
+    """Show all the message"""
 
     rcode, out = runtool(cmdln_or_args, catch=3)
 
@@ -90,8 +85,7 @@ def show(cmdln_or_args):
         cmd = cmdln_or_args
 
     msg =  'running command: "%s"' % cmd
-    if out: out = out.strip()
-    if out:
+    if out and out.strip():
         msg += ', with output::'
         msg += '\n  +----------------'
         for line in out.splitlines():
@@ -102,19 +96,19 @@ def show(cmdln_or_args):
     return rcode, out
 
 def outs(cmdln_or_args, catch=1):
-    # get the outputs of tools
+    """Get the outputs of tools"""
     return runtool(cmdln_or_args, catch)[1].strip()
 
 def quiet(cmdln_or_args):
+    """Execute a cmd quiet, no debug information printed"""
     return runtool(cmdln_or_args, catch=0)[0]
 
 def embed(cmdln_or_args):
-    # embed shell script into python frame code
+    """Eembed shell script into python frame code"""
 
     if isinstance(cmdln_or_args, list):
         args = cmdln_or_args
     else:
-        import shlex
         args = shlex.split(cmdln_or_args)
 
     try: