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 subprocess | 9 import subprocess |
10 import sys | 10 import sys |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 (error_message or error or output or '')) | 69 (error_message or error or output or '')) |
70 except Exception, e: | 70 except Exception, e: |
71 if not error_ok: | 71 if not error_ok: |
72 raise | 72 raise |
73 else: | 73 else: |
74 Warning(str(e)) | 74 Warning(str(e)) |
75 | 75 |
76 return output | 76 return output |
77 | 77 |
78 | 78 |
| 79 def RunCommandWithRetries(cmd, num_retries=5): |
| 80 """Runs a shell command with retries |
| 81 |
| 82 Runs a shell command. In case of failure, this function will retry the |
| 83 command up to num_retries times. |
| 84 |
| 85 Arguments: |
| 86 cmd: Array of commands/args to execute |
| 87 num_retries: The number of retries to perform before dying |
| 88 |
| 89 Returns: |
| 90 The stdout output of the command. |
| 91 |
| 92 Raises: |
| 93 Exception: Raises generic exception on error with optional error_message. |
| 94 """ |
| 95 output = '' |
| 96 |
| 97 for i in range(num_retries): |
| 98 try: |
| 99 output = RunCommand(cmd) |
| 100 break |
| 101 except Exception, e: |
| 102 if (i < num_retries - 1): |
| 103 Warning('Retrying command: %r' % cmd) |
| 104 else: |
| 105 raise |
| 106 |
| 107 return output |
| 108 |
| 109 |
79 class Color(object): | 110 class Color(object): |
80 """Conditionally wraps text in ANSI color escape sequences.""" | 111 """Conditionally wraps text in ANSI color escape sequences.""" |
81 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) | 112 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) |
82 BOLD = -1 | 113 BOLD = -1 |
83 COLOR_START = '\033[1;%dm' | 114 COLOR_START = '\033[1;%dm' |
84 BOLD_START = '\033[1m' | 115 BOLD_START = '\033[1m' |
85 RESET = '\033[0m' | 116 RESET = '\033[0m' |
86 | 117 |
87 def __init__(self, enabled=True): | 118 def __init__(self, enabled=True): |
88 self._enabled = enabled | 119 self._enabled = enabled |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 193 |
163 # Strip the repository root from the path and strip first /. | 194 # Strip the repository root from the path and strip first /. |
164 relative_path = path_abs_path.replace(root_abs_path, '')[1:] | 195 relative_path = path_abs_path.replace(root_abs_path, '')[1:] |
165 | 196 |
166 if relative_path == path_abs_path: | 197 if relative_path == path_abs_path: |
167 raise Exception('Error: path is outside your src tree, cannot reinterpret.') | 198 raise Exception('Error: path is outside your src tree, cannot reinterpret.') |
168 | 199 |
169 new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path) | 200 new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path) |
170 return new_path | 201 return new_path |
171 | 202 |
OLD | NEW |