Add copyright banner to scripts.
[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)
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)
44         print printPrefix + "Install complete\n",
45
46 def installToDevice (device, printPrefix=""):
47         print printPrefix + "Installing to %s (%s)...\n" % (device.serial, device.model),
48         install(['-s', device.serial], printPrefix)
49
50 def installToAllDevices (doParallel):
51         devices = common.getDevices(common.ADB_BIN)
52         padLen = max([len(device.model) for device in devices])+1
53         if doParallel:
54                 common.parallelApply(installToDevice, [(device, ("(%s):%s" % (device.model, ' ' * (padLen - len(device.model))))) for device in devices]);
55         else:
56                 common.serialApply(installToDevice, [(device, ) for device in devices]);
57
58 if __name__ == "__main__":
59         if len(sys.argv) > 1:
60                 if sys.argv[1] == '-a':
61                         doParallel = '-p' in sys.argv[1:]
62                         installToAllDevices(doParallel)
63                 else:
64                         install(sys.argv[1:])
65         else:
66                 devices = common.getDevices(common.ADB_BIN)
67                 if len(devices) == 0:
68                         common.die('No devices connected')
69                 elif len(devices) == 1:
70                         installToDevice(devices[0])
71                 else:
72                         print "More than one device connected:"
73                         for i in range(0, len(devices)):
74                                 print "%3d: %16s %s" % ((i+1), devices[i].serial, devices[i].model)
75
76                         deviceNdx = int(raw_input("Choose device (1-%d): " % len(devices)))
77                         installToDevice(devices[deviceNdx-1])