| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 stderr=stderr, | 65 stderr=stderr, |
| 66 returncode=returncode) | 66 returncode=returncode) |
| 67 | 67 |
| 68 @property | 68 @property |
| 69 def __dict__(self): | 69 def __dict__(self): |
| 70 """Return a dictionary representation of this CommandResults instance. | 70 """Return a dictionary representation of this CommandResults instance. |
| 71 | 71 |
| 72 Since collections.NamedTuple.__dict__ returns an OrderedDict, we have to | 72 Since collections.NamedTuple.__dict__ returns an OrderedDict, we have to |
| 73 create this wrapper to get a normal dict. | 73 create this wrapper to get a normal dict. |
| 74 """ | 74 """ |
| 75 return dict(super(CommandResults, self).__dict__) | 75 return dict(self._asdict()) |
| 76 | 76 |
| 77 def print_results(self, pretty=False): | 77 def print_results(self, pretty=False): |
| 78 """Print the results of a command. | 78 """Print the results of a command. |
| 79 | 79 |
| 80 Args: | 80 Args: |
| 81 pretty: bool; whether or not to print in human-readable format. | 81 pretty: bool; whether or not to print in human-readable format. |
| 82 """ | 82 """ |
| 83 if pretty: | 83 if pretty: |
| 84 print pprint.pformat(self.__dict__) | 84 print pprint.pformat(self.__dict__) |
| 85 else: | 85 else: |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 setattr(options, cmd, args) | 354 setattr(options, cmd, args) |
| 355 except IndexError: | 355 except IndexError: |
| 356 parser.print_usage() | 356 parser.print_usage() |
| 357 sys.exit(1) | 357 sys.exit(1) |
| 358 return options | 358 return options |
| 359 | 359 |
| 360 | 360 |
| 361 if '__main__' == __name__: | 361 if '__main__' == __name__: |
| 362 parsed_args = parse_args() | 362 parsed_args = parse_args() |
| 363 run(parsed_args.cmd).print_results(pretty=parsed_args.pretty) | 363 run(parsed_args.cmd).print_results(pretty=parsed_args.pretty) |
| OLD | NEW |