OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import datetime | 5 import datetime |
6 import functools | 6 import functools |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import shutil | 9 import shutil |
10 import tempfile | 10 import tempfile |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 with open(cache_path, 'w') as f: | 181 with open(cache_path, 'w') as f: |
182 f.write(d.DumpCacheData()) | 182 f.write(d.DumpCacheData()) |
183 logging.info('Wrote device cache: %s', cache_path) | 183 logging.info('Wrote device cache: %s', cache_path) |
184 | 184 |
185 self.parallel_devices.pMap(tear_down_device) | 185 self.parallel_devices.pMap(tear_down_device) |
186 | 186 |
187 for m in self._logcat_monitors: | 187 for m in self._logcat_monitors: |
188 try: | 188 try: |
189 m.Stop() | 189 m.Stop() |
190 m.Close() | 190 m.Close() |
191 _, temp_path = tempfile.mkstemp() | |
192 with open(m.output_file, 'r') as infile: | |
193 with open(temp_path, 'w') as outfile: | |
194 for line in infile: | |
195 outfile.write('Device(%s) %s' % (m.adb.GetDeviceSerial(), line)) | |
196 shutil.move(temp_path, m.output_file) | |
197 except base_error.BaseError: | 191 except base_error.BaseError: |
198 logging.exception('Failed to stop logcat monitor for %s', | 192 logging.exception('Failed to stop logcat monitor for %s', |
199 m.adb.GetDeviceSerial()) | 193 m.adb.GetDeviceSerial()) |
200 except IOError: | |
201 logging.exception('Failed to locate logcat for device %s', | |
202 m.adb.GetDeviceSerial()) | |
203 | 194 |
204 if self._logcat_output_file: | 195 if self._logcat_output_file: |
205 file_utils.MergeFiles( | 196 file_utils.MergeFiles( |
206 self._logcat_output_file, | 197 self._logcat_output_file, |
207 [m.output_file for m in self._logcat_monitors]) | 198 [m.output_file for m in self._logcat_monitors]) |
208 shutil.rmtree(self._logcat_output_dir) | 199 shutil.rmtree(self._logcat_output_dir) |
209 | 200 |
210 def BlacklistDevice(self, device, reason='local_device_failure'): | 201 def BlacklistDevice(self, device, reason='local_device_failure'): |
211 device_serial = device.adb.GetDeviceSerial() | 202 device_serial = device.adb.GetDeviceSerial() |
212 if self._blacklist: | 203 if self._blacklist: |
213 self._blacklist.Extend([device_serial], reason=reason) | 204 self._blacklist.Extend([device_serial], reason=reason) |
214 with self._devices_lock: | 205 with self._devices_lock: |
215 self._devices = [d for d in self._devices if str(d) != device_serial] | 206 self._devices = [d for d in self._devices if str(d) != device_serial] |
216 | 207 |
OLD | NEW |