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

Side by Side Diff: build/android/pylib/device/adb_wrapper.py

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « build/android/pylib/device/OWNERS ('k') | build/android/pylib/device/device_utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """This module wraps Android's adb tool. 5 """This module wraps Android's adb tool.
6 6
7 This is a thin wrapper around the adb interface. Any additional complexity 7 This is a thin wrapper around the adb interface. Any additional complexity
8 should be delegated to a higher level (ex. DeviceUtils). 8 should be delegated to a higher level (ex. DeviceUtils).
9 """ 9 """
10 10
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 except ValueError: 246 except ValueError:
247 logging.warning('exit status of shell command %r missing.', command) 247 logging.warning('exit status of shell command %r missing.', command)
248 raise device_errors.AdbShellCommandFailedError( 248 raise device_errors.AdbShellCommandFailedError(
249 command, output, status=None, device_serial=self._device_serial) 249 command, output, status=None, device_serial=self._device_serial)
250 output = output[:output_end] 250 output = output[:output_end]
251 if status != expect_status: 251 if status != expect_status:
252 raise device_errors.AdbShellCommandFailedError( 252 raise device_errors.AdbShellCommandFailedError(
253 command, output, status=status, device_serial=self._device_serial) 253 command, output, status=status, device_serial=self._device_serial)
254 return output 254 return output
255 255
256 def IterShell(self, command, timeout):
257 """Runs a shell command and returns an iterator over its output lines.
258
259 Args:
260 command: A string with the shell command to run.
261 timeout: Timeout in seconds.
262
263 Yields:
264 The output of the command line by line.
265 """
266 args = ['shell', command]
267 return cmd_helper.IterCmdOutputLines(
268 self._BuildAdbCmd(args, self._device_serial), timeout=timeout)
269
256 def Ls(self, path, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): 270 def Ls(self, path, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
257 """List the contents of a directory on the device. 271 """List the contents of a directory on the device.
258 272
259 Args: 273 Args:
260 path: Path on the device filesystem. 274 path: Path on the device filesystem.
261 timeout: (optional) Timeout per try in seconds. 275 timeout: (optional) Timeout per try in seconds.
262 retries: (optional) Number of retries to attempt. 276 retries: (optional) Number of retries to attempt.
263 277
264 Returns: 278 Returns:
265 A list of pairs (filename, stat) for each file found in the directory, 279 A list of pairs (filename, stat) for each file found in the directory,
(...skipping 13 matching lines...) Expand all
279 lines = self._RunDeviceAdbCmd( 293 lines = self._RunDeviceAdbCmd(
280 cmd, timeout=timeout, retries=retries).splitlines() 294 cmd, timeout=timeout, retries=retries).splitlines()
281 if lines: 295 if lines:
282 return [ParseLine(line) for line in lines] 296 return [ParseLine(line) for line in lines]
283 else: 297 else:
284 raise device_errors.AdbCommandFailedError( 298 raise device_errors.AdbCommandFailedError(
285 cmd, 'path does not specify an accessible directory in the device', 299 cmd, 'path does not specify an accessible directory in the device',
286 device_serial=self._device_serial) 300 device_serial=self._device_serial)
287 301
288 def Logcat(self, clear=False, dump=False, filter_spec=None, 302 def Logcat(self, clear=False, dump=False, filter_spec=None,
289 logcat_format=None, timeout=None): 303 logcat_format=None, timeout=None, retries=_DEFAULT_RETRIES):
290 """Get an iterator over the logcat output. 304 """Get an iterable over the logcat output.
291 305
292 Args: 306 Args:
293 filter_spec: (optional) Spec to filter the logcat. 307 clear: If true, clear the logcat.
294 timeout: (optional) Timeout per try in seconds. 308 dump: If true, dump the current logcat contents.
309 filter_spec: If set, spec to filter the logcat.
310 logcat_format: If set, the format in which the logcat should be output.
311 Options include "brief", "process", "tag", "thread", "raw", "time",
312 "threadtime", and "long"
313 timeout: (optional) If set, timeout per try in seconds. If clear or dump
314 is set, defaults to _DEFAULT_TIMEOUT.
315 retries: (optional) If clear or dump is set, the number of retries to
316 attempt. Otherwise, does nothing.
295 317
296 Yields: 318 Yields:
297 logcat output line by line. 319 logcat output line by line.
298 """ 320 """
299 cmd = ['logcat'] 321 cmd = ['logcat']
322 use_iter = True
300 if clear: 323 if clear:
301 cmd.append('-c') 324 cmd.append('-c')
325 use_iter = False
302 if dump: 326 if dump:
303 cmd.append('-d') 327 cmd.append('-d')
328 use_iter = False
304 if logcat_format: 329 if logcat_format:
305 cmd.extend(['-v', logcat_format]) 330 cmd.extend(['-v', logcat_format])
306 if filter_spec is not None: 331 if filter_spec is not None:
307 cmd.append(filter_spec) 332 cmd.append(filter_spec)
308 return self._IterRunDeviceAdbCmd(cmd, timeout) 333
334 if use_iter:
335 return self._IterRunDeviceAdbCmd(cmd, timeout)
336 else:
337 timeout = timeout if timeout is not None else _DEFAULT_TIMEOUT
338 return self._RunDeviceAdbCmd(cmd, timeout, retries)
309 339
310 def Forward(self, local, remote, timeout=_DEFAULT_TIMEOUT, 340 def Forward(self, local, remote, timeout=_DEFAULT_TIMEOUT,
311 retries=_DEFAULT_RETRIES): 341 retries=_DEFAULT_RETRIES):
312 """Forward socket connections from the local socket to the remote socket. 342 """Forward socket connections from the local socket to the remote socket.
313 343
314 Sockets are specified by one of: 344 Sockets are specified by one of:
315 tcp:<port> 345 tcp:<port>
316 localabstract:<unix domain socket name> 346 localabstract:<unix domain socket name>
317 localreserved:<unix domain socket name> 347 localreserved:<unix domain socket name>
318 localfilesystem:<unix domain socket name> 348 localfilesystem:<unix domain socket name>
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 """Restarts the adbd daemon with root permissions, if possible. 516 """Restarts the adbd daemon with root permissions, if possible.
487 517
488 Args: 518 Args:
489 timeout: (optional) Timeout per try in seconds. 519 timeout: (optional) Timeout per try in seconds.
490 retries: (optional) Number of retries to attempt. 520 retries: (optional) Number of retries to attempt.
491 """ 521 """
492 output = self._RunDeviceAdbCmd(['root'], timeout, retries) 522 output = self._RunDeviceAdbCmd(['root'], timeout, retries)
493 if 'cannot' in output: 523 if 'cannot' in output:
494 raise device_errors.AdbCommandFailedError( 524 raise device_errors.AdbCommandFailedError(
495 ['root'], output, device_serial=self._device_serial) 525 ['root'], output, device_serial=self._device_serial)
OLDNEW
« no previous file with comments | « build/android/pylib/device/OWNERS ('k') | build/android/pylib/device/device_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698