Chromium Code Reviews| 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 """A wrapper for subprocess to make calling shell commands easier.""" | 5 """A wrapper for subprocess to make calling shell commands easier.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import pipes | 9 import pipes |
| 10 import select | 10 import select |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 buffer_output += data | 302 buffer_output += data |
| 303 has_incomplete_line = buffer_output[-1] not in '\r\n' | 303 has_incomplete_line = buffer_output[-1] not in '\r\n' |
| 304 lines = buffer_output.splitlines() | 304 lines = buffer_output.splitlines() |
| 305 buffer_output = lines.pop() if has_incomplete_line else '' | 305 buffer_output = lines.pop() if has_incomplete_line else '' |
| 306 for line in lines: | 306 for line in lines: |
| 307 yield line | 307 yield line |
| 308 if buffer_output: | 308 if buffer_output: |
| 309 yield buffer_output | 309 yield buffer_output |
| 310 if check_status and process.returncode: | 310 if check_status and process.returncode: |
| 311 raise subprocess.CalledProcessError(process.returncode, cmd) | 311 raise subprocess.CalledProcessError(process.returncode, cmd) |
| 312 | |
| 313 | |
| 314 def IterCmdOutput(args, timeout=None, cwd=None, shell=False, | |
|
mikecase (-- gone --)
2015/12/16 23:52:05
Need the logcat output as soon as I can get it to
| |
| 315 check_status=True): | |
| 316 """Executes a subprocess and continuously yields its output. | |
| 317 | |
| 318 Args: | |
| 319 args: List of arguments to the program, the program to execute is the first | |
| 320 element. | |
| 321 cwd: If not None, the subprocess's current directory will be changed to | |
| 322 |cwd| before it's executed. | |
| 323 shell: Whether to execute args as a shell command. Must be True if args | |
| 324 is a string and False if args is a sequence. | |
| 325 check_status: A boolean indicating whether to check the exit status of the | |
| 326 process after all output has been read. | |
| 327 | |
| 328 Yields: | |
| 329 The output of the subprocess. | |
| 330 | |
| 331 Raises: | |
| 332 CalledProcessError if check_status is True and the process exited with a | |
| 333 non-zero exit status. | |
| 334 """ | |
| 335 cmd = _ValidateAndLogCommand(args, cwd, shell) | |
| 336 process = Popen(args, cwd=cwd, shell=shell, stdout=subprocess.PIPE, | |
| 337 stderr=subprocess.STDOUT) | |
| 338 for data in _IterProcessStdout(process, timeout=timeout): | |
| 339 yield data | |
| 340 if check_status and process.returncode: | |
| 341 raise subprocess.CalledProcessError(process.returncode, cmd) | |
| OLD | NEW |