Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: build/android/provision_devices.py

Issue 12733012: Provision Android devices after the 'device_status_check' step. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address ilevy's comments Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Provisions Android devices with settings required for bots.
8
9 Usage:
10 ./provision_devices.py [-d <device serial number>]
11 """
12
13 import optparse
14 import os
15 import re
16 import subprocess
17 import sys
18 import time
19
20 from pylib import android_commands
21 from pylib import constants
22
23
24 def PushAndLaunchAdbReboot(device, adb_reboot):
25 """Pushes and launches the adb_reboot binary on the device.
26
27 Arguments:
28 device: The serial number of the device to which the
29 adb_reboot binary should be pushed.
30 adb_reboot: The path to the adb_reboot binary.
31 """
32 print 'Will push and launch adb_reboot on %s' % device
33 android_cmd = android_commands.AndroidCommands(device)
34 # Kill if adb_reboot is already running.
35 android_cmd.KillAllBlocking('adb_reboot', 2)
36 # Push adb_reboot
37 print ' Pushing adb_reboot ...'
38 android_cmd.PushIfNeeded(adb_reboot, '/data/local/')
39 # Launch adb_reboot
40 print ' Launching adb_reboot ...'
41 p = subprocess.Popen(['adb', '-s', device, 'shell'], stdin=subprocess.PIPE)
42 p.communicate('/data/local/adb_reboot; exit\n')
43
44
45 def LaunchHostHeartbeat():
46 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE)
47 stdout, _ = ps.communicate()
48 matches = re.findall('\\n.*host_heartbeat.*', stdout)
49 for match in matches:
50 print 'An instance of host heart beart already running... will kill'
51 pid = re.findall('(\d+)', match)[1]
52 subprocess.call(['kill', '%s' % str(pid)])
Isaac (away) 2013/03/29 00:18:33 '%s' % <string> is a no-op. Just use <string> or
Siva Chandra 2013/03/29 01:47:06 Done.
53 # Launch a new host_heartbeat
54 print 'Spawing host heartbeat...'
55 subprocess.Popen([os.path.join(constants.CHROME_DIR,
56 'build/android/host_heartbeat.py')])
57
58
59 def ProvisionDevices(options):
60 if options.device is not None:
61 devices = [options.device]
62 else:
63 devices = android_commands.GetAttachedDevices()
64 for device in devices:
65 android_cmd = android_commands.AndroidCommands(device)
66 android_cmd.EnableAdbRoot()
Isaac (away) 2013/03/29 00:18:33 This will convert phone to root until the phone is
Siva Chandra 2013/03/29 01:47:06 Removed enabling root.
67 android_cmd.RunShellCommand('date -u %f' % time.time())
68 PushAndLaunchAdbReboot(device, options.adb_reboot)
69 LaunchHostHeartbeat()
70
71
72 def main(argv):
73 parser = optparse.OptionParser()
74 parser.add_option('-d', '--device', dest='device',
Isaac (away) 2013/03/29 00:18:33 remove dest param, unneeded
Siva Chandra 2013/03/29 01:47:06 Done.
75 help='The serial number of the device to be provisioned')
76 parser.add_option('-a', '--adb-reboot', dest='adb_reboot',
Isaac (away) 2013/03/29 00:18:33 dest param unneded. Also I'd rather this script t
Siva Chandra 2013/03/29 01:47:06 Done.
77 help='Path to the adb_reboot binary')
78 options, args = parser.parse_args(argv[1:])
79
80 if args:
81 print >> sys.stderr, 'Unused args %s' % args
82 return 1
83
84 if not options.adb_reboot:
85 print >> sys.stderr, 'Path to adb_reboot not specified'
86 return 1
87
88 ProvisionDevices(options)
89
90
91 if __name__ == '__main__':
92 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698