Make install.py print device name for each message in -a -p mode.
authorJarkko Pöyry <jpoyry@google.com>
Thu, 12 Mar 2015 22:20:47 +0000 (15:20 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Tue, 17 Mar 2015 03:06:38 +0000 (20:06 -0700)
- Add device prefix for each adb subprocess message. This makes
  it possible to know which device failed the install.

Change-Id: I4a116e17df1073913abfb6dd9fee1c9ef1e62ed9

android/scripts/common.py
android/scripts/install.py

index cc66dce..241cecf 100644 (file)
@@ -110,10 +110,20 @@ def execArgs (args):
        if retcode != 0:
                raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
 
-def execArgsInDirectory (args, cwd):
-       # Make sure previous stdout prints have been written out.
-       sys.stdout.flush()
-       process = subprocess.Popen(args, cwd=cwd)
+def execArgsInDirectory (args, cwd, linePrefix=""):
+
+       def readApplyPrefixAndPrint (source, prefix, sink):
+               while True:
+                       line = source.readline()
+                       if len(line) == 0: # EOF
+                               break;
+                       sink.write(prefix + line)
+
+       process = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+       stdoutJob = threading.Thread(target=readApplyPrefixAndPrint, args=(process.stdout, linePrefix, sys.stdout))
+       stderrJob = threading.Thread(target=readApplyPrefixAndPrint, args=(process.stdout, linePrefix, sys.stderr))
+       stdoutJob.start()
+       stderrJob.start()
        retcode = process.wait()
        if retcode != 0:
                raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
index 89e60f5..1bf63fd 100644 (file)
@@ -32,7 +32,7 @@ def install (extraArgs = [], printPrefix=""):
        common.execArgsInDirectory([common.ADB_BIN] + extraArgs + [
                        'uninstall',
                        'com.drawelements.deqp'
-               ], common.ANDROID_DIR)
+               ], common.ANDROID_DIR, printPrefix)
        print printPrefix + "Remove complete\n",
 
        print printPrefix + "Installing dEQP Package...\n",
@@ -40,11 +40,15 @@ def install (extraArgs = [], printPrefix=""):
                        'install',
                        '-r',
                        'package/bin/dEQP-debug.apk'
-               ], common.ANDROID_DIR)
+               ], common.ANDROID_DIR, printPrefix)
        print printPrefix + "Install complete\n",
 
 def installToDevice (device, printPrefix=""):
-       print printPrefix + "Installing to %s (%s)...\n" % (device.serial, device.model),
+       if len(printPrefix) == 0:
+               print "Installing to %s (%s)...\n" % (device.serial, device.model),
+       else:
+               print printPrefix + "Installing to %s\n" % device.serial,
+
        install(['-s', device.serial], printPrefix)
 
 def installToAllDevices (doParallel):