Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
Jarkko Pöyry | 3c77ed4 | 2015-01-06 12:54:34 -0800 | [diff] [blame] | 3 | #------------------------------------------------------------------------- |
| 4 | # drawElements Quality Program utilities |
| 5 | # -------------------------------------- |
| 6 | # |
| 7 | # Copyright 2015 The Android Open Source Project |
| 8 | # |
| 9 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | # you may not use this file except in compliance with the License. |
| 11 | # You may obtain a copy of the License at |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 15 | # Unless required by applicable law or agreed to in writing, software |
| 16 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | # See the License for the specific language governing permissions and |
| 19 | # limitations under the License. |
| 20 | # |
| 21 | #------------------------------------------------------------------------- |
| 22 | |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 23 | import sys |
| 24 | import os |
| 25 | import time |
| 26 | import string |
Mika Isojärvi | 0b894ac | 2015-03-31 17:10:19 -0700 | [diff] [blame] | 27 | import argparse |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 28 | |
| 29 | import common |
| 30 | |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 31 | def install (extraArgs = [], printPrefix=""): |
| 32 | print printPrefix + "Removing old dEQP Package...\n", |
| 33 | common.execArgsInDirectory([common.ADB_BIN] + extraArgs + [ |
| 34 | 'uninstall', |
| 35 | 'com.drawelements.deqp' |
Jarkko Pöyry | d1ae94f | 2015-03-12 15:20:47 -0700 | [diff] [blame] | 36 | ], common.ANDROID_DIR, printPrefix) |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 37 | print printPrefix + "Remove complete\n", |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 38 | |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 39 | print printPrefix + "Installing dEQP Package...\n", |
| 40 | common.execArgsInDirectory([common.ADB_BIN] + extraArgs + [ |
| 41 | 'install', |
| 42 | '-r', |
| 43 | 'package/bin/dEQP-debug.apk' |
Jarkko Pöyry | d1ae94f | 2015-03-12 15:20:47 -0700 | [diff] [blame] | 44 | ], common.ANDROID_DIR, printPrefix) |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 45 | print printPrefix + "Install complete\n", |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 46 | |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 47 | def installToDevice (device, printPrefix=""): |
Jarkko Pöyry | d1ae94f | 2015-03-12 15:20:47 -0700 | [diff] [blame] | 48 | if len(printPrefix) == 0: |
| 49 | print "Installing to %s (%s)...\n" % (device.serial, device.model), |
| 50 | else: |
| 51 | print printPrefix + "Installing to %s\n" % device.serial, |
| 52 | |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 53 | install(['-s', device.serial], printPrefix) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 54 | |
Mika Isojärvi | 0b894ac | 2015-03-31 17:10:19 -0700 | [diff] [blame] | 55 | def installToDevices (devices, doParallel): |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 56 | padLen = max([len(device.model) for device in devices])+1 |
| 57 | if doParallel: |
| 58 | common.parallelApply(installToDevice, [(device, ("(%s):%s" % (device.model, ' ' * (padLen - len(device.model))))) for device in devices]); |
| 59 | else: |
| 60 | common.serialApply(installToDevice, [(device, ) for device in devices]); |
Pyry Haulos | 89e0405 | 2014-10-20 11:09:56 -0700 | [diff] [blame] | 61 | |
Mika Isojärvi | 0b894ac | 2015-03-31 17:10:19 -0700 | [diff] [blame] | 62 | def installToAllDevices (doParallel): |
| 63 | devices = common.getDevices(common.ADB_BIN) |
| 64 | installToDevices(devices, doParallel) |
Pyry Haulos | 89e0405 | 2014-10-20 11:09:56 -0700 | [diff] [blame] | 65 | |
Mika Isojärvi | 0b894ac | 2015-03-31 17:10:19 -0700 | [diff] [blame] | 66 | if __name__ == "__main__": |
| 67 | parser = argparse.ArgumentParser() |
| 68 | parser.add_argument('-p', '--parallel', dest='doParallel', action="store_true", help="Install package in parallel.") |
| 69 | parser.add_argument('-s', '--serial', dest='serial', type=str, nargs='+', help="Install package to device with serial number.") |
| 70 | parser.add_argument('-a', '--all', dest='all', action="store_true", help="Install to all devices.") |
| 71 | |
| 72 | args = parser.parse_args() |
| 73 | |
| 74 | if args.all: |
| 75 | installToAllDevices(args.doParallel) |
| 76 | else: |
| 77 | if args.serial == None: |
| 78 | devices = common.getDevices(common.ADB_BIN) |
| 79 | if len(devices) == 0: |
| 80 | common.die('No devices connected') |
| 81 | elif len(devices) == 1: |
| 82 | installToDevice(devices[0]) |
| 83 | else: |
| 84 | print "More than one device connected:" |
| 85 | for i in range(0, len(devices)): |
| 86 | print "%3d: %16s %s" % ((i+1), devices[i].serial, devices[i].model) |
| 87 | |
| 88 | deviceNdx = int(raw_input("Choose device (1-%d): " % len(devices))) |
| 89 | installToDevice(devices[deviceNdx-1]) |
| 90 | else: |
| 91 | devices = common.getDevices(common.ADB_BIN) |
| 92 | |
| 93 | devices = [dev for dev in devices if dev.serial in args.serial] |
| 94 | devSerials = [dev.serial for dev in devices] |
| 95 | notFounds = [serial for serial in args.serial if not serial in devSerials] |
| 96 | |
| 97 | for notFound in notFounds: |
| 98 | print("Couldn't find device matching serial '%s'" % notFound) |
| 99 | |
| 100 | installToDevices(devices, args.doParallel) |