OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
6 | 6 |
7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 return False | 1067 return False |
1068 | 1068 |
1069 def TakeScreenshot(self, host_file): | 1069 def TakeScreenshot(self, host_file): |
1070 """Saves a screenshot image to |host_file| on the host. | 1070 """Saves a screenshot image to |host_file| on the host. |
1071 | 1071 |
1072 Args: | 1072 Args: |
1073 host_file: Absolute path to the image file to store on the host. | 1073 host_file: Absolute path to the image file to store on the host. |
1074 """ | 1074 """ |
1075 host_dir = os.path.dirname(host_file) | 1075 host_dir = os.path.dirname(host_file) |
1076 if not os.path.exists(host_dir): | 1076 if not os.path.exists(host_dir): |
1077 os.mkdir(host_dir) | 1077 os.makedirs(host_dir) |
1078 device_file = '%s/screenshot.png' % self.GetExternalStorage() | 1078 device_file = '%s/screenshot.png' % self.GetExternalStorage() |
1079 self.RunShellCommand('/system/bin/screencap -p %s' % device_file) | 1079 self.RunShellCommand('/system/bin/screencap -p %s' % device_file) |
1080 assert self._adb.Pull(device_file, host_file) | 1080 assert self._adb.Pull(device_file, host_file) |
1081 assert os.path.exists(host_file) | 1081 assert os.path.exists(host_file) |
1082 | 1082 |
1083 | 1083 |
1084 class NewLineNormalizer(object): | 1084 class NewLineNormalizer(object): |
1085 """A file-like object to normalize EOLs to '\n'. | 1085 """A file-like object to normalize EOLs to '\n'. |
1086 | 1086 |
1087 Pexpect runs adb within a pseudo-tty device (see | 1087 Pexpect runs adb within a pseudo-tty device (see |
1088 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written | 1088 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written |
1089 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate | 1089 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate |
1090 lines, the log ends up having '\r\r\n' at the end of each line. This | 1090 lines, the log ends up having '\r\r\n' at the end of each line. This |
1091 filter replaces the above with a single '\n' in the data stream. | 1091 filter replaces the above with a single '\n' in the data stream. |
1092 """ | 1092 """ |
1093 def __init__(self, output): | 1093 def __init__(self, output): |
1094 self._output = output | 1094 self._output = output |
1095 | 1095 |
1096 def write(self, data): | 1096 def write(self, data): |
1097 data = data.replace('\r\r\n', '\n') | 1097 data = data.replace('\r\r\n', '\n') |
1098 self._output.write(data) | 1098 self._output.write(data) |
1099 | 1099 |
1100 def flush(self): | 1100 def flush(self): |
1101 self._output.flush() | 1101 self._output.flush() |
OLD | NEW |