| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Common python commands used by various build scripts.""" | 5 """Common python commands used by various build scripts.""" |
| 6 | 6 |
| 7 import inspect | 7 import inspect |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import subprocess | 10 import subprocess |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 break | 103 break |
| 104 | 104 |
| 105 if file_handle: file_handle.close() | 105 if file_handle: file_handle.close() |
| 106 | 106 |
| 107 # If they asked for an exit_code, give it to them on success or failure | 107 # If they asked for an exit_code, give it to them on success or failure |
| 108 if exit_code: | 108 if exit_code: |
| 109 return proc.returncode | 109 return proc.returncode |
| 110 | 110 |
| 111 # If the command (and all retries) failed, handle error result | 111 # If the command (and all retries) failed, handle error result |
| 112 if proc.returncode != 0 and not error_ok: | 112 if proc.returncode != 0 and not error_ok: |
| 113 if output: |
| 114 print >> sys.stderr, output |
| 115 sys.stderr.flush() |
| 116 |
| 113 error_info = ('Command "%r" failed.\n' % (cmd) + | 117 error_info = ('Command "%r" failed.\n' % (cmd) + |
| 114 (error_message or error or output or '')) | 118 (error_message or error or '')) |
| 115 if log_to_file: error_info += '\nOutput logged to %s' % log_to_file | 119 if log_to_file: error_info += '\nOutput logged to %s' % log_to_file |
| 116 raise RunCommandException(error_info) | 120 raise RunCommandException(error_info) |
| 117 | 121 |
| 118 # return final result | 122 # return final result |
| 119 return output | 123 return output |
| 120 | 124 |
| 121 | 125 |
| 122 def RunCommandCaptureOutput(cmd, print_cmd=True, cwd=None, input=None, | 126 def RunCommandCaptureOutput(cmd, print_cmd=True, cwd=None, input=None, |
| 123 enter_chroot=False, | 127 enter_chroot=False, |
| 124 combine_stdout_stderr=True, | 128 combine_stdout_stderr=True, |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 return os.path.join(GetCrosUtilsPath(source_dir_path), 'bin') | 359 return os.path.join(GetCrosUtilsPath(source_dir_path), 'bin') |
| 356 | 360 |
| 357 | 361 |
| 358 def IsInsideChroot(): | 362 def IsInsideChroot(): |
| 359 """Returns True if we are inside chroot.""" | 363 """Returns True if we are inside chroot.""" |
| 360 return os.path.exists('/etc/debian_chroot') | 364 return os.path.exists('/etc/debian_chroot') |
| 361 | 365 |
| 362 | 366 |
| 363 # TODO(sosa): Remove once all callers use method. | 367 # TODO(sosa): Remove once all callers use method. |
| 364 CROSUTILS_DIRECTORY = GetCrosUtilsPath(True) | 368 CROSUTILS_DIRECTORY = GetCrosUtilsPath(True) |
| OLD | NEW |