| 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 15 matching lines...) Expand all Loading... |
| 26 def __init__(self, msg, *args, **kwargs): | 26 def __init__(self, msg, *args, **kwargs): |
| 27 index = getattr(threading.currentThread(), 'index', 0) | 27 index = getattr(threading.currentThread(), 'index', 0) |
| 28 if index: | 28 if index: |
| 29 msg = '\n'.join('%d> %s' % (index, l) for l in msg.splitlines()) | 29 msg = '\n'.join('%d> %s' % (index, l) for l in msg.splitlines()) |
| 30 super(Error, self).__init__(msg, *args, **kwargs) | 30 super(Error, self).__init__(msg, *args, **kwargs) |
| 31 | 31 |
| 32 def SplitUrlRevision(url): | 32 def SplitUrlRevision(url): |
| 33 """Splits url and returns a two-tuple: url, rev""" | 33 """Splits url and returns a two-tuple: url, rev""" |
| 34 if url.startswith('ssh:'): | 34 if url.startswith('ssh:'): |
| 35 # Make sure ssh://user-name@example.com/~/test.git@stable works | 35 # Make sure ssh://user-name@example.com/~/test.git@stable works |
| 36 regex = r'(ssh://(?:[-\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' | 36 regex = r'(ssh://(?:[-.\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' |
| 37 components = re.search(regex, url).groups() | 37 components = re.search(regex, url).groups() |
| 38 else: | 38 else: |
| 39 components = url.split('@', 1) | 39 components = url.split('@', 1) |
| 40 if len(components) == 1: | 40 if len(components) == 1: |
| 41 components += [None] | 41 components += [None] |
| 42 return tuple(components) | 42 return tuple(components) |
| 43 | 43 |
| 44 | 44 |
| 45 def IsDateRevision(revision): | 45 def IsDateRevision(revision): |
| 46 """Returns true if the given revision is of the form "{ ... }".""" | 46 """Returns true if the given revision is of the form "{ ... }".""" |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 | 878 |
| 879 Python on OSX 10.6 raises a NotImplementedError exception. | 879 Python on OSX 10.6 raises a NotImplementedError exception. |
| 880 """ | 880 """ |
| 881 try: | 881 try: |
| 882 import multiprocessing | 882 import multiprocessing |
| 883 return multiprocessing.cpu_count() | 883 return multiprocessing.cpu_count() |
| 884 except: # pylint: disable=W0702 | 884 except: # pylint: disable=W0702 |
| 885 # Mac OS 10.6 only | 885 # Mac OS 10.6 only |
| 886 # pylint: disable=E1101 | 886 # pylint: disable=E1101 |
| 887 return int(os.sysconf('SC_NPROCESSORS_ONLN')) | 887 return int(os.sysconf('SC_NPROCESSORS_ONLN')) |
| OLD | NEW |