| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 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 """A simple client for the crrev.com API. | 6 """A simple client for the crrev.com API. |
| 7 | 7 |
| 8 API Explorer page: https://goo.gl/5ThLDm | 8 API Explorer page: https://goo.gl/5ThLDm |
| 9 | 9 |
| 10 Example usage: | 10 Example usage: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 if attempt >= attempts: | 54 if attempt >= attempts: |
| 55 raise | 55 raise |
| 56 logging.exception('Failed to request from crrev: %s', e) | 56 logging.exception('Failed to request from crrev: %s', e) |
| 57 | 57 |
| 58 logging.info('Sleeping %d seconds before retry (%d/%d).', | 58 logging.info('Sleeping %d seconds before retry (%d/%d).', |
| 59 retry_delay_seconds, attempt, attempts) | 59 retry_delay_seconds, attempt, attempts) |
| 60 time.sleep(retry_delay_seconds) | 60 time.sleep(retry_delay_seconds) |
| 61 retry_delay_seconds *= 2 | 61 retry_delay_seconds *= 2 |
| 62 | 62 |
| 63 | 63 |
| 64 def main(): | 64 def main(args): |
| 65 parser = argparse.ArgumentParser() | 65 parser = argparse.ArgumentParser() |
| 66 parser.add_argument('path', help='Path + query to add onto the base URL.') | 66 parser.add_argument('path', help='Path + query to add onto the base URL.') |
| 67 parser.add_argument('--params-file', help='Request parameter JSON file.') | 67 parser.add_argument('--params-file', help='Request parameter JSON file.') |
| 68 parser.add_argument('--attempts', default=1, help='Number of times to retry.') | 68 parser.add_argument('--attempts', default=1, help='Number of times to retry.') |
| 69 args = parser.parse_args() | 69 args = parser.parse_args(args) |
| 70 params = {} | 70 params = {} |
| 71 if args.params_file: | 71 if args.params_file: |
| 72 params = json.lad(args.params_file) | 72 params = json.load(open(args.params_file)) |
| 73 print json.dumps(crrev_get(args.path, params, args.attempts), indent=2) | 73 return json.dumps(crrev_get(args.path, params, args.attempts), indent=2) |
| 74 | 74 |
| 75 | 75 |
| 76 if __name__ == '__main__': | 76 if __name__ == '__main__': |
| 77 main() | 77 print main(sys.argv[1:]) |
| OLD | NEW |