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 Queue | 10 import Queue |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 # would be treated regardless of what they reference. | 151 # would be treated regardless of what they reference. |
152 fullpath = os.path.join(path, fn) | 152 fullpath = os.path.join(path, fn) |
153 if os.path.islink(fullpath) or not os.path.isdir(fullpath): | 153 if os.path.islink(fullpath) or not os.path.isdir(fullpath): |
154 remove(os.remove, fullpath) | 154 remove(os.remove, fullpath) |
155 else: | 155 else: |
156 # Recurse. | 156 # Recurse. |
157 rmtree(fullpath) | 157 rmtree(fullpath) |
158 | 158 |
159 remove(os.rmdir, path) | 159 remove(os.rmdir, path) |
160 | 160 |
161 # TODO(maruel): Rename the references. | |
162 RemoveDirectory = rmtree | |
163 | |
164 | 161 |
165 def safe_makedirs(tree): | 162 def safe_makedirs(tree): |
166 """Creates the directory in a safe manner. | 163 """Creates the directory in a safe manner. |
167 | 164 |
168 Because multiple threads can create these directories concurently, trap the | 165 Because multiple threads can create these directories concurently, trap the |
169 exception and pass on. | 166 exception and pass on. |
170 """ | 167 """ |
171 count = 0 | 168 count = 0 |
172 while not os.path.exists(tree): | 169 while not os.path.exists(tree): |
173 count += 1 | 170 count += 1 |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 764 |
768 Python on OSX 10.6 raises a NotImplementedError exception. | 765 Python on OSX 10.6 raises a NotImplementedError exception. |
769 """ | 766 """ |
770 try: | 767 try: |
771 import multiprocessing | 768 import multiprocessing |
772 return multiprocessing.cpu_count() | 769 return multiprocessing.cpu_count() |
773 except: # pylint: disable=W0702 | 770 except: # pylint: disable=W0702 |
774 # Mac OS 10.6 only | 771 # Mac OS 10.6 only |
775 # pylint: disable=E1101 | 772 # pylint: disable=E1101 |
776 return int(os.sysconf('SC_NPROCESSORS_ONLN')) | 773 return int(os.sysconf('SC_NPROCESSORS_ONLN')) |
OLD | NEW |