OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # | 2 # |
3 # | 3 # |
4 # Copyright 2007, The Android Open Source Project | 4 # Copyright 2007, The Android Open Source Project |
5 # | 5 # |
6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
9 # | 9 # |
10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
(...skipping 16 matching lines...) Expand all Loading... |
27 import logger | 27 import logger |
28 | 28 |
29 _abort_on_error = False | 29 _abort_on_error = False |
30 | 30 |
31 def SetAbortOnError(abort=True): | 31 def SetAbortOnError(abort=True): |
32 """Sets behavior of RunCommand to throw AbortError if command process returns | 32 """Sets behavior of RunCommand to throw AbortError if command process returns |
33 a negative error code""" | 33 a negative error code""" |
34 global _abort_on_error | 34 global _abort_on_error |
35 _abort_on_error = abort | 35 _abort_on_error = abort |
36 | 36 |
37 def RunCommand(cmd, timeout_time=None, retry_count=3, return_output=True, | 37 def RunCommand(cmd, timeout_time=None, retry_count=0, return_output=True, |
38 stdin_input=None): | 38 stdin_input=None): |
39 """Spawn and retry a subprocess to run the given shell command. | 39 """Spawn and retry a subprocess to run the given shell command. |
40 | 40 |
41 Args: | 41 Args: |
42 cmd: shell command to run | 42 cmd: shell command to run |
43 timeout_time: time in seconds to wait for command to run before aborting. | 43 timeout_time: time in seconds to wait for command to run before aborting. |
44 retry_count: number of times to retry command | 44 retry_count: number of times to retry command |
45 return_output: if True return output of command as string. Otherwise, | 45 return_output: if True return output of command as string. Otherwise, |
46 direct output of command to stdout. | 46 direct output of command to stdout. |
47 stdin_input: data to feed to stdin | 47 stdin_input: data to feed to stdin |
48 Returns: | 48 Returns: |
49 output of command | 49 output of command |
50 """ | 50 """ |
| 51 retry_count = 0 |
51 result = None | 52 result = None |
52 while True: | 53 while True: |
53 try: | 54 try: |
54 result = RunOnce(cmd, timeout_time=timeout_time, | 55 result = RunOnce(cmd, timeout_time=timeout_time, |
55 return_output=return_output, stdin_input=stdin_input) | 56 return_output=return_output, stdin_input=stdin_input) |
56 except errors.WaitForResponseTimedOutError: | 57 except errors.WaitForResponseTimedOutError: |
57 if retry_count == 0: | 58 if retry_count == 0: |
58 raise | 59 raise |
59 retry_count -= 1 | 60 retry_count -= 1 |
60 logger.Log("No response for %s, retrying" % cmd) | 61 logger.Log("No response for %s, retrying" % cmd) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 def HasValgrind(): | 188 def HasValgrind(): |
188 """Check that /usr/bin/valgrind exists. | 189 """Check that /usr/bin/valgrind exists. |
189 | 190 |
190 We look for the fullpath to avoid picking up 'alternative' valgrind | 191 We look for the fullpath to avoid picking up 'alternative' valgrind |
191 on the system. | 192 on the system. |
192 | 193 |
193 Returns: | 194 Returns: |
194 True if a system valgrind was found. | 195 True if a system valgrind was found. |
195 """ | 196 """ |
196 return os.path.exists("/usr/bin/valgrind") | 197 return os.path.exists("/usr/bin/valgrind") |
OLD | NEW |