| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 | 6 |
| 7 """Run a command and report its results in machine-readable format.""" | 7 """Run a command and report its results in machine-readable format.""" |
| 8 | 8 |
| 9 | 9 |
| 10 import collections | 10 import collections |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 | 179 |
| 180 def _get_result(popen): | 180 def _get_result(popen): |
| 181 """Get the results from a running process. Blocks until the process completes. | 181 """Get the results from a running process. Blocks until the process completes. |
| 182 | 182 |
| 183 Args: | 183 Args: |
| 184 popen: subprocess.Popen instance. | 184 popen: subprocess.Popen instance. |
| 185 Returns: | 185 Returns: |
| 186 A dictionary with stdout, stderr, and returncode as keys. | 186 A dictionary with stdout, stderr, and returncode as keys. |
| 187 """ | 187 """ |
| 188 print popen.stdout.read() | 188 for fd in (popen.stdout, popen.stderr): |
| 189 print popen.stderr.read() | 189 for line in iter(fd.readline, ''): |
| 190 print line |
| 190 stdout, stderr = popen.communicate() | 191 stdout, stderr = popen.communicate() |
| 191 return CommandResults.make(stdout=stdout, | 192 return CommandResults.make(stdout=stdout, |
| 192 stderr=stderr, | 193 stderr=stderr, |
| 193 returncode=popen.returncode) | 194 returncode=popen.returncode) |
| 194 | 195 |
| 195 | 196 |
| 196 def run(cmd): | 197 def run(cmd): |
| 197 """Run the command, block until it completes, and return a results dictionary. | 198 """Run the command, block until it completes, and return a results dictionary. |
| 198 | 199 |
| 199 Args: | 200 Args: |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 setattr(options, cmd, args) | 353 setattr(options, cmd, args) |
| 353 except IndexError: | 354 except IndexError: |
| 354 parser.print_usage() | 355 parser.print_usage() |
| 355 sys.exit(1) | 356 sys.exit(1) |
| 356 return options | 357 return options |
| 357 | 358 |
| 358 | 359 |
| 359 if '__main__' == __name__: | 360 if '__main__' == __name__: |
| 360 parsed_args = parse_args() | 361 parsed_args = parse_args() |
| 361 run(parsed_args.cmd).print_results(pretty=parsed_args.pretty) | 362 run(parsed_args.cmd).print_results(pretty=parsed_args.pretty) |
| OLD | NEW |