| 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 |
| 11 # | 11 # |
| 12 # Unless required by applicable law or agreed to in writing, software | 12 # Unless required by applicable law or agreed to in writing, software |
| 13 # distributed under the License is distributed on an "AS IS" BASIS, | 13 # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 # See the License for the specific language governing permissions and | 15 # See the License for the specific language governing permissions and |
| 16 # limitations under the License. | 16 # limitations under the License. |
| 17 | 17 |
| 18 # System imports | 18 # System imports |
| 19 import os | 19 import os |
| 20 import signal | 20 import signal |
| 21 import subprocess | 21 import subprocess |
| 22 import tempfile | 22 import tempfile |
| 23 import threading | 23 import threading |
| 24 import time | 24 import time |
| 25 import sys |
| 25 | 26 |
| 26 # local imports | 27 # local imports |
| 27 import errors | 28 import errors |
| 28 import logger | 29 import logger |
| 29 | 30 |
| 30 _abort_on_error = False | 31 _abort_on_error = False |
| 31 | 32 |
| 32 def SetAbortOnError(abort=True): | 33 def SetAbortOnError(abort=True): |
| 33 """Sets behavior of RunCommand to throw AbortError if command process returns | 34 """Sets behavior of RunCommand to throw AbortError if command process returns |
| 34 a negative error code""" | 35 a negative error code""" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 87 |
| 87 if return_output: | 88 if return_output: |
| 88 output_dest = tempfile.TemporaryFile(bufsize=0) | 89 output_dest = tempfile.TemporaryFile(bufsize=0) |
| 89 else: | 90 else: |
| 90 # None means direct to stdout | 91 # None means direct to stdout |
| 91 output_dest = None | 92 output_dest = None |
| 92 if stdin_input: | 93 if stdin_input: |
| 93 stdin_dest = subprocess.PIPE | 94 stdin_dest = subprocess.PIPE |
| 94 else: | 95 else: |
| 95 stdin_dest = None | 96 stdin_dest = None |
| 97 stderr_dest = subprocess.STDOUT |
| 98 if os.environ.get('ADB_TRACE'): |
| 99 stderr_dest = sys.stdout |
| 96 pipe = subprocess.Popen( | 100 pipe = subprocess.Popen( |
| 97 cmd, | 101 cmd, |
| 98 executable='/bin/bash', | 102 executable='/bin/bash', |
| 99 stdin=stdin_dest, | 103 stdin=stdin_dest, |
| 100 stdout=output_dest, | 104 stdout=output_dest, |
| 101 stderr=subprocess.STDOUT, | 105 stderr=stderr_dest, |
| 102 shell=True, close_fds=True, | 106 shell=True, close_fds=True, |
| 103 preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL)) | 107 preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL)) |
| 104 | 108 |
| 105 def Run(): | 109 def Run(): |
| 106 global error_occurred | 110 global error_occurred |
| 107 try: | 111 try: |
| 108 pipe.communicate(input=stdin_input) | 112 pipe.communicate(input=stdin_input) |
| 109 output = None | 113 output = None |
| 110 if return_output: | 114 if return_output: |
| 111 output_dest.seek(0) | 115 output_dest.seek(0) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 def HasValgrind(): | 187 def HasValgrind(): |
| 184 """Check that /usr/bin/valgrind exists. | 188 """Check that /usr/bin/valgrind exists. |
| 185 | 189 |
| 186 We look for the fullpath to avoid picking up 'alternative' valgrind | 190 We look for the fullpath to avoid picking up 'alternative' valgrind |
| 187 on the system. | 191 on the system. |
| 188 | 192 |
| 189 Returns: | 193 Returns: |
| 190 True if a system valgrind was found. | 194 True if a system valgrind was found. |
| 191 """ | 195 """ |
| 192 return os.path.exists("/usr/bin/valgrind") | 196 return os.path.exists("/usr/bin/valgrind") |
| OLD | NEW |