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

Unified Diff: common/battor/battor/battor_wrapper.py

Issue 1946773002: [BattOr] Add support to battor_wrapper to autodetect if battor is attached. (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | common/battor/battor/battor_wrapper_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/battor/battor/battor_wrapper.py
diff --git a/common/battor/battor/battor_wrapper.py b/common/battor/battor/battor_wrapper.py
index 2676ff9fb29e8aaaced61fc070c143b10933d0a3..d1aa1ed4d91f8df0e4cf3628695bc958942c1703 100644
--- a/common/battor/battor/battor_wrapper.py
+++ b/common/battor/battor/battor_wrapper.py
@@ -17,6 +17,44 @@ from devil.utils import find_usb_devices
import serial
from serial.tools import list_ports
+
+def IsBattOrConnected(test_platform, android_device=None,
+ android_device_map=None, android_device_file=None):
+ """Returns True if BattOr is detected."""
+ if test_platform == 'android':
+ if not android_device:
+ raise battor_error.BattorError('Must past android device serial when '
+ 'determining support on android platform')
+
+ if not android_device_map:
+ if android_device_file:
+ android_device_map = battor_device_mapping.ReadSerialMapFile(
+ android_device_file)
+ else:
+ android_device_map = battor_device_mapping.GenerateSerialMap()
+
+ # If neither if statement above is triggered, it means that an
+ # android_device_map was passed in and will be used.
+ return str(android_device) in android_device_map
+
+ elif test_platform == 'win':
+ for (_, desc, _) in serial.tools.list_ports.comports():
+ if 'USB Serial Port' in desc:
+ return True
+ return False
+
+ elif test_platform == 'mac':
+ # TODO(rnephew): When we have a BattOr that can attach to mac, find a way
+ # to detect BattOrs on mac.
+ return False
+
+ elif test_platform == 'linux':
+ device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap(fast=True)
+ return bool(battor_device_mapping.GetBattorList(device_tree))
+
+ return False
+
+
class BattorWrapper(object):
"""A class for communicating with a BattOr in python."""
_START_TRACING_CMD = 'StartTracing'
« no previous file with comments | « no previous file | common/battor/battor/battor_wrapper_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698