| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 | 166 |
| 167 def _launch_cmd(cmd): | 167 def _launch_cmd(cmd): |
| 168 """Launch the given command. Non-blocking. | 168 """Launch the given command. Non-blocking. |
| 169 | 169 |
| 170 Args: | 170 Args: |
| 171 cmd: list of strings; command to run. | 171 cmd: list of strings; command to run. |
| 172 Returns: | 172 Returns: |
| 173 subprocess.Popen instance. | 173 subprocess.Popen instance. |
| 174 """ | 174 """ |
| 175 print ' '.join(cmd) |
| 175 return subprocess.Popen(cmd, shell=False, stderr=subprocess.PIPE, | 176 return subprocess.Popen(cmd, shell=False, stderr=subprocess.PIPE, |
| 176 stdout=subprocess.PIPE) | 177 stdout=subprocess.PIPE) |
| 177 | 178 |
| 178 | 179 |
| 179 def _get_result(popen): | 180 def _get_result(popen): |
| 180 """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. |
| 181 | 182 |
| 182 Args: | 183 Args: |
| 183 popen: subprocess.Popen instance. | 184 popen: subprocess.Popen instance. |
| 184 Returns: | 185 Returns: |
| 185 A dictionary with stdout, stderr, and returncode as keys. | 186 A dictionary with stdout, stderr, and returncode as keys. |
| 186 """ | 187 """ |
| 188 print popen.stdout.read() |
| 189 print popen.stderr.read() |
| 187 stdout, stderr = popen.communicate() | 190 stdout, stderr = popen.communicate() |
| 188 return CommandResults.make(stdout=stdout, | 191 return CommandResults.make(stdout=stdout, |
| 189 stderr=stderr, | 192 stderr=stderr, |
| 190 returncode=popen.returncode) | 193 returncode=popen.returncode) |
| 191 | 194 |
| 192 | 195 |
| 193 def run(cmd): | 196 def run(cmd): |
| 194 """Run the command, block until it completes, and return a results dictionary. | 197 """Run the command, block until it completes, and return a results dictionary. |
| 195 | 198 |
| 196 Args: | 199 Args: |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 setattr(options, cmd, args) | 352 setattr(options, cmd, args) |
| 350 except IndexError: | 353 except IndexError: |
| 351 parser.print_usage() | 354 parser.print_usage() |
| 352 sys.exit(1) | 355 sys.exit(1) |
| 353 return options | 356 return options |
| 354 | 357 |
| 355 | 358 |
| 356 if '__main__' == __name__: | 359 if '__main__' == __name__: |
| 357 parsed_args = parse_args() | 360 parsed_args = parse_args() |
| 358 run(parsed_args.cmd).print_results(pretty=parsed_args.pretty) | 361 run(parsed_args.cmd).print_results(pretty=parsed_args.pretty) |
| OLD | NEW |