Make install.py print device name for each message in -a -p mode.
[platform/upstream/VK-GL-CTS.git] / android / scripts / install.py
1 # -*- coding: utf-8 -*-
2
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
23 import sys
24 import os
25 import time
26 import string
27
28 import common
29
30 def install (extraArgs = [], printPrefix=""):
31         print printPrefix + "Removing old dEQP Package...\n",
32         common.execArgsInDirectory([common.ADB_BIN] + extraArgs + [
33                         'uninstall',
34                         'com.drawelements.deqp'
35                 ], common.ANDROID_DIR, printPrefix)
36         print printPrefix + "Remove complete\n",
37
38         print printPrefix + "Installing dEQP Package...\n",
39         common.execArgsInDirectory([common.ADB_BIN] + extraArgs + [
40                         'install',
41                         '-r',
42                         'package/bin/dEQP-debug.apk'
43                 ], common.ANDROID_DIR, printPrefix)
44         print printPrefix + "Install complete\n",
45
46 def installToDevice (device, printPrefix=""):
47         if len(printPrefix) == 0:
48                 print "Installing to %s (%s)...\n" % (device.serial, device.model),
49         else:
50                 print printPrefix + "Installing to %s\n" % device.serial,
51
52         install(['-s', device.serial], printPrefix)
53
54 def installToAllDevices (doParallel):
55         devices = common.getDevices(common.ADB_BIN)
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]);
61
62 if __name__ == "__main__":
63         if len(sys.argv) > 1:
64                 if sys.argv[1] == '-a':
65                         doParallel = '-p' in sys.argv[1:]
66                         installToAllDevices(doParallel)
67                 else:
68                         install(sys.argv[1:])
69         else:
70                 devices = common.getDevices(common.ADB_BIN)
71                 if len(devices) == 0:
72                         common.die('No devices connected')
73                 elif len(devices) == 1:
74                         installToDevice(devices[0])
75                 else:
76                         print "More than one device connected:"
77                         for i in range(0, len(devices)):
78                                 print "%3d: %16s %s" % ((i+1), devices[i].serial, devices[i].model)
79
80                         deviceNdx = int(raw_input("Choose device (1-%d): " % len(devices)))
81                         installToDevice(devices[deviceNdx-1])