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 | |
26 | 25 |
27 # local imports | 26 # local imports |
28 import errors | 27 import errors |
29 import logger | 28 import logger |
30 | 29 |
31 _abort_on_error = False | 30 _abort_on_error = False |
32 | 31 |
33 def SetAbortOnError(abort=True): | 32 def SetAbortOnError(abort=True): |
34 """Sets behavior of RunCommand to throw AbortError if command process returns | 33 """Sets behavior of RunCommand to throw AbortError if command process returns |
35 a negative error code""" | 34 a negative error code""" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 86 |
88 if return_output: | 87 if return_output: |
89 output_dest = tempfile.TemporaryFile(bufsize=0) | 88 output_dest = tempfile.TemporaryFile(bufsize=0) |
90 else: | 89 else: |
91 # None means direct to stdout | 90 # None means direct to stdout |
92 output_dest = None | 91 output_dest = None |
93 if stdin_input: | 92 if stdin_input: |
94 stdin_dest = subprocess.PIPE | 93 stdin_dest = subprocess.PIPE |
95 else: | 94 else: |
96 stdin_dest = None | 95 stdin_dest = None |
97 stderr_dest = subprocess.STDOUT | |
98 if os.environ.get('ADB_TRACE'): | |
99 stderr_dest = sys.stdout | |
100 pipe = subprocess.Popen( | 96 pipe = subprocess.Popen( |
101 cmd, | 97 cmd, |
102 executable='/bin/bash', | 98 executable='/bin/bash', |
103 stdin=stdin_dest, | 99 stdin=stdin_dest, |
104 stdout=output_dest, | 100 stdout=output_dest, |
105 stderr=stderr_dest, | 101 stderr=subprocess.STDOUT, |
106 shell=True, close_fds=True, | 102 shell=True, close_fds=True, |
107 preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL)) | 103 preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL)) |
108 | 104 |
109 def Run(): | 105 def Run(): |
110 global error_occurred | 106 global error_occurred |
111 try: | 107 try: |
112 pipe.communicate(input=stdin_input) | 108 pipe.communicate(input=stdin_input) |
113 output = None | 109 output = None |
114 if return_output: | 110 if return_output: |
115 output_dest.seek(0) | 111 output_dest.seek(0) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 def HasValgrind(): | 183 def HasValgrind(): |
188 """Check that /usr/bin/valgrind exists. | 184 """Check that /usr/bin/valgrind exists. |
189 | 185 |
190 We look for the fullpath to avoid picking up 'alternative' valgrind | 186 We look for the fullpath to avoid picking up 'alternative' valgrind |
191 on the system. | 187 on the system. |
192 | 188 |
193 Returns: | 189 Returns: |
194 True if a system valgrind was found. | 190 True if a system valgrind was found. |
195 """ | 191 """ |
196 return os.path.exists("/usr/bin/valgrind") | 192 return os.path.exists("/usr/bin/valgrind") |
OLD | NEW |