| 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 signal | 10 import signal |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 # TODO(sosa): is it possible not to use the catch-all Exception here? | 110 # TODO(sosa): is it possible not to use the catch-all Exception here? |
| 111 except Exception, e: | 111 except Exception, e: |
| 112 if not error_ok: | 112 if not error_ok: |
| 113 raise | 113 raise |
| 114 else: | 114 else: |
| 115 Warning(str(e)) | 115 Warning(str(e)) |
| 116 | 116 |
| 117 return cmd_result | 117 return cmd_result |
| 118 | 118 |
| 119 | 119 |
| 120 #TODO(sjg): Remove this in favor of operation.Die | |
| 121 def Die(message): | 120 def Die(message): |
| 122 """Emits a red error message and halts execution. | 121 """Emits a red error message and halts execution. |
| 123 | 122 |
| 124 Args: | 123 Args: |
| 125 message: The message to be emitted before exiting. | 124 message: The message to be emitted before exiting. |
| 126 """ | 125 """ |
| 127 print >> sys.stderr, ( | 126 print >> sys.stderr, ( |
| 128 Color(_STDOUT_IS_TTY).Color(Color.RED, '\nERROR: ' + message)) | 127 Color(_STDOUT_IS_TTY).Color(Color.RED, '\nERROR: ' + message)) |
| 129 sys.exit(1) | 128 sys.exit(1) |
| 130 | 129 |
| 131 | 130 |
| 132 #TODO(sjg): Remove this in favor of operation.Warning | |
| 133 # pylint: disable-msg=W0622 | 131 # pylint: disable-msg=W0622 |
| 134 def Warning(message): | 132 def Warning(message): |
| 135 """Emits a yellow warning message and continues execution. | 133 """Emits a yellow warning message and continues execution. |
| 136 | 134 |
| 137 Args: | 135 Args: |
| 138 message: The message to be emitted. | 136 message: The message to be emitted. |
| 139 """ | 137 """ |
| 140 print >> sys.stderr, ( | 138 print >> sys.stderr, ( |
| 141 Color(_STDOUT_IS_TTY).Color(Color.YELLOW, '\nWARNING: ' + message)) | 139 Color(_STDOUT_IS_TTY).Color(Color.YELLOW, '\nWARNING: ' + message)) |
| 142 | 140 |
| 143 | 141 |
| 144 # This command is deprecated in favor of operation.Info() | 142 def Info(message): |
| 145 # It is left here for the moment so people are aware what happened. | 143 """Emits a blue informational message and continues execution. |
| 146 # The reason is that this is not aware of the terminal output restrictions such | 144 |
| 147 # as verbose, quiet and subprocess output. You should not be calling this. | 145 Args: |
| 148 # def Info(message): | 146 message: The message to be emitted. |
| 149 # """Emits a blue informational message and continues execution. | 147 """ |
| 150 # | 148 print >> sys.stderr, ( |
| 151 # Args: | 149 Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message)) |
| 152 # message: The message to be emitted. | |
| 153 # """ | |
| 154 # print >> sys.stderr, ( | |
| 155 # Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message)) | |
| 156 | 150 |
| 157 | 151 |
| 158 def ListFiles(base_dir): | 152 def ListFiles(base_dir): |
| 159 """Recurively list files in a directory. | 153 """Recurively list files in a directory. |
| 160 | 154 |
| 161 Args: | 155 Args: |
| 162 base_dir: directory to start recursively listing in. | 156 base_dir: directory to start recursively listing in. |
| 163 | 157 |
| 164 Returns: | 158 Returns: |
| 165 A list of files relative to the base_dir path or | 159 A list of files relative to the base_dir path or |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 except RunCommandException as e: | 348 except RunCommandException as e: |
| 355 if not error_ok and retry_count == num_retries: | 349 if not error_ok and retry_count == num_retries: |
| 356 raise e | 350 raise e |
| 357 else: | 351 else: |
| 358 Warning(str(e)) | 352 Warning(str(e)) |
| 359 if print_cmd: | 353 if print_cmd: |
| 360 Info('PROGRAM(%s) -> RunCommand: retrying %r in dir %s' % | 354 Info('PROGRAM(%s) -> RunCommand: retrying %r in dir %s' % |
| 361 (GetCallerName(), cmd, cwd)) | 355 (GetCallerName(), cmd, cwd)) |
| 362 | 356 |
| 363 return output | 357 return output |
| OLD | NEW |