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 codecs | 7 import codecs |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import pipes | 10 import pipes |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 def CheckCallAndFilterAndHeader(args, always=False, header=None, **kwargs): | 191 def CheckCallAndFilterAndHeader(args, always=False, header=None, **kwargs): |
192 """Adds 'header' support to CheckCallAndFilter. | 192 """Adds 'header' support to CheckCallAndFilter. |
193 | 193 |
194 If |always| is True, a message indicating what is being done | 194 If |always| is True, a message indicating what is being done |
195 is printed to stdout all the time even if not output is generated. Otherwise | 195 is printed to stdout all the time even if not output is generated. Otherwise |
196 the message header is printed only if the call generated any ouput. | 196 the message header is printed only if the call generated any ouput. |
197 """ | 197 """ |
198 stdout = kwargs.setdefault('stdout', sys.stdout) | 198 stdout = kwargs.setdefault('stdout', sys.stdout) |
199 if header is None: | 199 if header is None: |
200 header = "\n________ running '%s' in '%s'\n" % ( | 200 header = "\n________ running '%s' in '%s'\n" % ( |
201 CommandToStr(args), kwargs.get('cwd', '.')) | 201 ' '.join(args), kwargs.get('cwd', '.')) |
202 | 202 |
203 if always: | 203 if always: |
204 stdout.write(header) | 204 stdout.write(header) |
205 else: | 205 else: |
206 filter_fn = kwargs.get('filter_fn') | 206 filter_fn = kwargs.get('filter_fn') |
207 def filter_msg(line): | 207 def filter_msg(line): |
208 if line is None: | 208 if line is None: |
209 stdout.write(header) | 209 stdout.write(header) |
210 elif filter_fn: | 210 elif filter_fn: |
211 filter_fn(line) | 211 filter_fn(line) |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 | 877 |
878 Python on OSX 10.6 raises a NotImplementedError exception. | 878 Python on OSX 10.6 raises a NotImplementedError exception. |
879 """ | 879 """ |
880 try: | 880 try: |
881 import multiprocessing | 881 import multiprocessing |
882 return multiprocessing.cpu_count() | 882 return multiprocessing.cpu_count() |
883 except: # pylint: disable=W0702 | 883 except: # pylint: disable=W0702 |
884 # Mac OS 10.6 only | 884 # Mac OS 10.6 only |
885 # pylint: disable=E1101 | 885 # pylint: disable=E1101 |
886 return int(os.sysconf('SC_NPROCESSORS_ONLN')) | 886 return int(os.sysconf('SC_NPROCESSORS_ONLN')) |
OLD | NEW |