Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: command_wrapper.py

Issue 8597020: Ensure that all args with spaces in them remain quoted when used with command_wrapper.py. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/command_wrapper/bin/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698