1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 The Android Open Source Project
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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.
21 #-------------------------------------------------------------------------
31 def install (buildRoot, extraArgs = [], printPrefix=""):
32 print printPrefix + "Removing old dEQP Package...\n",
33 common.execArgsInDirectory([common.ADB_BIN] + extraArgs + [
35 'com.drawelements.deqp'
36 ], buildRoot, printPrefix)
37 print printPrefix + "Remove complete\n",
39 print printPrefix + "Installing dEQP Package from %s...\n" %(buildRoot),
40 common.execArgsInDirectory([common.ADB_BIN] + extraArgs + [
43 'package/bin/dEQP-debug.apk'
44 ], buildRoot, printPrefix)
45 print printPrefix + "Install complete\n",
47 def installToDevice (device, buildRoot, printPrefix=""):
48 if len(printPrefix) == 0:
49 print "Installing to %s (%s)...\n" % (device.serial, device.model),
51 print printPrefix + "Installing to %s\n" % device.serial,
53 install(buildRoot, ['-s', device.serial], printPrefix)
55 def installToDevices (devices, doParallel, buildRoot):
56 padLen = max([len(device.model) for device in devices])+1
58 common.parallelApply(installToDevice, [(device, buildRoot, ("(%s):%s" % (device.model, ' ' * (padLen - len(device.model))))) for device in devices]);
60 common.serialApply(installToDevice, [(device, buildRoot) for device in devices]);
62 def installToAllDevices (doParallel, buildRoot):
63 devices = common.getDevices(common.ADB_BIN)
64 installToDevices(devices, doParallel, buildRoot)
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 parser.add_argument('-b', '--build-root', dest='buildRoot', default=common.ANDROID_DIR, help="Root directory from which to pick up APK. Generally, build root specified in build.py")
73 args = parser.parse_args()
74 absBuildRoot = os.path.abspath(args.buildRoot)
77 installToAllDevices(args.doParallel, absBuildRoot)
79 if args.serial == None:
80 devices = common.getDevices(common.ADB_BIN)
82 common.die('No devices connected')
83 elif len(devices) == 1:
84 installToDevice(devices[0], absBuildRoot)
86 print "More than one device connected:"
87 for i in range(0, len(devices)):
88 print "%3d: %16s %s" % ((i+1), devices[i].serial, devices[i].model)
90 deviceNdx = int(raw_input("Choose device (1-%d): " % len(devices)))
91 installToDevice(devices[deviceNdx-1], absBuildRoot)
93 devices = common.getDevices(common.ADB_BIN)
95 devices = [dev for dev in devices if dev.serial in args.serial]
96 devSerials = [dev.serial for dev in devices]
97 notFounds = [serial for serial in args.serial if not serial in devSerials]
99 for notFound in notFounds:
100 print("Couldn't find device matching serial '%s'" % notFound)
102 installToDevices(devices, args.doParallel, absBuildRoot)