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

Side by Side Diff: devil/devil/android/tools/device_status.py

Issue 2920513003: Revert of devil: Add physical port num to device_status.py (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A script to keep track of devices across builds and report state.""" 6 """A script to keep track of devices across builds and report state."""
7 7
8 import argparse 8 import argparse
9 import json 9 import json
10 import logging 10 import logging
11 import os 11 import os
12 import re 12 import re
13 import sys 13 import sys
14 14
15 if __name__ == '__main__': 15 if __name__ == '__main__':
16 sys.path.append( 16 sys.path.append(
17 os.path.abspath(os.path.join(os.path.dirname(__file__), 17 os.path.abspath(os.path.join(os.path.dirname(__file__),
18 '..', '..', '..'))) 18 '..', '..', '..')))
19 from devil import devil_env 19 from devil import devil_env
20 from devil.android import battery_utils 20 from devil.android import battery_utils
21 from devil.android import device_blacklist 21 from devil.android import device_blacklist
22 from devil.android import device_errors 22 from devil.android import device_errors
23 from devil.android import device_list 23 from devil.android import device_list
24 from devil.android import device_utils 24 from devil.android import device_utils
25 from devil.android.sdk import adb_wrapper 25 from devil.android.sdk import adb_wrapper
26 from devil.constants import exit_codes 26 from devil.constants import exit_codes
27 from devil.utils import find_usb_devices
28 from devil.utils import lsusb 27 from devil.utils import lsusb
29 from devil.utils import run_tests_helper 28 from devil.utils import run_tests_helper
30 from devil.utils import usb_hubs
31 29
32 logger = logging.getLogger(__name__) 30 logger = logging.getLogger(__name__)
33 31
34 _RE_DEVICE_ID = re.compile(r'Device ID = (\d+)') 32 _RE_DEVICE_ID = re.compile(r'Device ID = (\d+)')
35 33
36 34
37 def IsBlacklisted(serial, blacklist): 35 def IsBlacklisted(serial, blacklist):
38 return blacklist and serial in blacklist.Read() 36 return blacklist and serial in blacklist.Read()
39 37
40 38
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 }, 100 },
103 ... 101 ...
104 } 102 }
105 """ 103 """
106 adb_devices = { 104 adb_devices = {
107 a[0].GetDeviceSerial(): a 105 a[0].GetDeviceSerial(): a
108 for a in adb_wrapper.AdbWrapper.Devices(desired_state=None, long_list=True) 106 for a in adb_wrapper.AdbWrapper.Devices(desired_state=None, long_list=True)
109 } 107 }
110 usb_devices = set(lsusb.get_android_devices()) 108 usb_devices = set(lsusb.get_android_devices())
111 109
112 port_mapping = {}
113 for hub in find_usb_devices.GetAllPhysicalPortToSerialMaps(
114 usb_hubs.ALL_HUBS, fast=True):
115 # Reverse the mapping.
116 port_mapping.update({device: port for port, device in hub.iteritems()})
117
118 def blacklisting_device_status(device): 110 def blacklisting_device_status(device):
119 serial = device.adb.GetDeviceSerial() 111 serial = device.adb.GetDeviceSerial()
120 adb_status = ( 112 adb_status = (
121 adb_devices[serial][1] if serial in adb_devices 113 adb_devices[serial][1] if serial in adb_devices
122 else 'missing') 114 else 'missing')
123 usb_status = bool(serial in usb_devices) 115 usb_status = bool(serial in usb_devices)
124 116
125 device_status = { 117 device_status = {
126 'serial': serial, 118 'serial': serial,
127 'adb_status': adb_status, 119 'adb_status': adb_status,
128 'usb_status': usb_status, 120 'usb_status': usb_status,
129 'physical_port': port_mapping.get(serial, 'unknown'),
130 } 121 }
131 122
132 if not IsBlacklisted(serial, blacklist): 123 if not IsBlacklisted(serial, blacklist):
133 if adb_status == 'device': 124 if adb_status == 'device':
134 try: 125 try:
135 build_product = device.build_product 126 build_product = device.build_product
136 build_id = device.build_id 127 build_id = device.build_id
137 build_fingerprint = device.build_fingerprint 128 build_fingerprint = device.build_fingerprint
138 build_description = device.build_description 129 build_description = device.build_description
139 wifi_ip = device.GetProp('dhcp.wlan0.ipaddress') 130 wifi_ip = device.GetProp('dhcp.wlan0.ipaddress')
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 and not IsBlacklisted(status['serial'], blacklist))] 307 and not IsBlacklisted(status['serial'], blacklist))]
317 308
318 # If all devices failed, or if there are no devices, it's an infra error. 309 # If all devices failed, or if there are no devices, it's an infra error.
319 if not live_devices: 310 if not live_devices:
320 logger.error('No available devices.') 311 logger.error('No available devices.')
321 return 0 if live_devices else exit_codes.INFRA 312 return 0 if live_devices else exit_codes.INFRA
322 313
323 314
324 if __name__ == '__main__': 315 if __name__ == '__main__':
325 sys.exit(main()) 316 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698