Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Wrapper that does auto-retry and stats logging for command invocation. | 7 """Wrapper that does auto-retry and stats logging for command invocation. |
| 8 | 8 |
| 9 Various command line tools in use: gsutil, curl have spurious failure. | 9 Various command line tools in use: gsutil, curl have spurious failure. |
| 10 This wrapper will track stats to an AppEngine based service to | 10 This wrapper will track stats to an AppEngine based service to |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 help='number of times to retry on failure') | 88 help='number of times to retry on failure') |
| 89 parser.add_option('-u', '--logurl', dest='logurl', | 89 parser.add_option('-u', '--logurl', dest='logurl', |
| 90 default='https://command-wrapper.appspot.com/log', | 90 default='https://command-wrapper.appspot.com/log', |
| 91 help='URL to log invocations/failures to') | 91 help='URL to log invocations/failures to') |
| 92 (options, args) = parser.parse_args(args=argv[1:]) | 92 (options, args) = parser.parse_args(args=argv[1:]) |
| 93 | 93 |
| 94 # Limit tcp connnection timeouts to 10 seconds. | 94 # Limit tcp connnection timeouts to 10 seconds. |
| 95 socket.setdefaulttimeout(10) | 95 socket.setdefaulttimeout(10) |
| 96 | 96 |
| 97 command_id = uuid.uuid1() | 97 command_id = uuid.uuid1() |
| 98 cmd = ' '.join(args) | 98 |
| 99 # Ensure that args with spaces in them remain quoted. | |
| 100 args_quoted = [] | |
|
bradn
2011/11/19 01:09:13
Why not just requote it all?
| |
| 101 for arg in args: | |
| 102 if ' ' in arg: | |
| 103 arg = '"' + arg + '"' | |
| 104 args_quoted.append(arg) | |
| 105 cmd = ' '.join(args_quoted) | |
| 99 | 106 |
| 100 # Log that we're even starting. | 107 # Log that we're even starting. |
| 101 RunWithTimeout(LOG_TIMEOUT, LogCommand, | 108 RunWithTimeout(LOG_TIMEOUT, LogCommand, |
| 102 options, command_id, -1, cmd, -1, '', '', 0) | 109 options, command_id, -1, cmd, -1, '', '', 0) |
| 103 | 110 |
| 104 # Try up to a certain number of times. | 111 # Try up to a certain number of times. |
| 105 for r in range(options.retries): | 112 for r in range(options.retries): |
| 106 tm = time.time() | 113 tm = time.time() |
| 107 p = subprocess.Popen(cmd, shell=True, | 114 p = subprocess.Popen(cmd, shell=True, |
| 108 stdout=subprocess.PIPE, | 115 stdout=subprocess.PIPE, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 121 print 'Command %s failed with retcode %d, try %d.' % ( | 128 print 'Command %s failed with retcode %d, try %d.' % ( |
| 122 ' '.join(args), p.returncode, r + 1) | 129 ' '.join(args), p.returncode, r + 1) |
| 123 print 'Command %s failed %d retries, giving up.' % ( | 130 print 'Command %s failed %d retries, giving up.' % ( |
| 124 ' '.join(args), options.retries) | 131 ' '.join(args), options.retries) |
| 125 | 132 |
| 126 return p.returncode | 133 return p.returncode |
| 127 | 134 |
| 128 | 135 |
| 129 if __name__ == '__main__': | 136 if __name__ == '__main__': |
| 130 sys.exit(main(sys.argv)) | 137 sys.exit(main(sys.argv)) |
| OLD | NEW |