OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium 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 """Generic utils.""" | 5 """Generic utils.""" |
6 | 6 |
7 import errno | 7 import errno |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import Queue | 10 import Queue |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 os.makedirs(tree) | 186 os.makedirs(tree) |
187 except OSError, e: | 187 except OSError, e: |
188 # 17 POSIX, 183 Windows | 188 # 17 POSIX, 183 Windows |
189 if e.errno not in (17, 183): | 189 if e.errno not in (17, 183): |
190 raise | 190 raise |
191 if count > 40: | 191 if count > 40: |
192 # Give up. | 192 # Give up. |
193 raise | 193 raise |
194 | 194 |
195 | 195 |
| 196 def FindCommandExecutable(cmd): |
| 197 """Finds the specified |cmd| in $PATH and returns its path. Returns None |
| 198 if it's not found.""" |
| 199 for path in os.environ['PATH'].split(os.pathsep): |
| 200 full_path = os.path.join(path, cmd) |
| 201 if os.path.isfile(full_path) and os.access(full_path, os.X_OK): |
| 202 return full_path |
| 203 return None |
| 204 |
| 205 |
196 def CheckCallAndFilterAndHeader(args, always=False, **kwargs): | 206 def CheckCallAndFilterAndHeader(args, always=False, **kwargs): |
197 """Adds 'header' support to CheckCallAndFilter. | 207 """Adds 'header' support to CheckCallAndFilter. |
198 | 208 |
199 If |always| is True, a message indicating what is being done | 209 If |always| is True, a message indicating what is being done |
200 is printed to stdout all the time even if not output is generated. Otherwise | 210 is printed to stdout all the time even if not output is generated. Otherwise |
201 the message header is printed only if the call generated any ouput. | 211 the message header is printed only if the call generated any ouput. |
202 """ | 212 """ |
203 stdout = kwargs.get('stdout', None) or sys.stdout | 213 stdout = kwargs.get('stdout', None) or sys.stdout |
204 if always: | 214 if always: |
205 stdout.write('\n________ running \'%s\' in \'%s\'\n' | 215 stdout.write('\n________ running \'%s\' in \'%s\'\n' |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) | 776 keyvals = dict([x.strip() for x in l.split(':', 1)] for l in lines if l) |
767 except ValueError: | 777 except ValueError: |
768 raise Error( | 778 raise Error( |
769 'Failed to process settings, please fix. Content:\n\n%s' % content) | 779 'Failed to process settings, please fix. Content:\n\n%s' % content) |
770 def fix_url(key): | 780 def fix_url(key): |
771 if keyvals.get(key): | 781 if keyvals.get(key): |
772 keyvals[key] = UpgradeToHttps(keyvals[key]) | 782 keyvals[key] = UpgradeToHttps(keyvals[key]) |
773 fix_url('CODE_REVIEW_SERVER') | 783 fix_url('CODE_REVIEW_SERVER') |
774 fix_url('VIEW_VC') | 784 fix_url('VIEW_VC') |
775 return keyvals | 785 return keyvals |
OLD | NEW |