| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 |
| 11 import re | 11 import re |
| 12 import stat | 12 import stat |
| 13 import subprocess | 13 import subprocess |
| 14 import sys | 14 import sys |
| 15 import threading | 15 import threading |
| 16 import time | 16 import time |
| 17 | 17 |
| 18 import subprocess2 |
| 19 |
| 18 | 20 |
| 19 def hack_subprocess(): | 21 def hack_subprocess(): |
| 20 """subprocess functions may throw exceptions when used in multiple threads. | 22 """subprocess functions may throw exceptions when used in multiple threads. |
| 21 | 23 |
| 22 See http://bugs.python.org/issue1731717 for more information. | 24 See http://bugs.python.org/issue1731717 for more information. |
| 23 """ | 25 """ |
| 24 subprocess._cleanup = lambda: None | 26 subprocess._cleanup = lambda: None |
| 25 | 27 |
| 26 | 28 |
| 27 class Error(Exception): | 29 class Error(Exception): |
| 28 """gclient exception class.""" | 30 """gclient exception class.""" |
| 29 pass | 31 pass |
| 30 | 32 |
| 31 | 33 |
| 32 class CheckCallError(OSError, Error): | 34 class CheckCallError(subprocess2.CalledProcessError, Error): |
| 33 """CheckCall() returned non-0.""" | 35 """CheckCall() returned non-0.""" |
| 34 def __init__(self, command, cwd, returncode, stdout, stderr=None): | 36 def __init__(self, cmd, cwd, returncode, stdout, stderr=None): |
| 35 OSError.__init__(self, command, cwd, returncode) | 37 subprocess2.CalledProcessError.__init__( |
| 36 Error.__init__(self, command) | 38 self, returncode, cmd, cwd, stdout, stderr) |
| 37 self.command = command | 39 Error.__init__(self, cmd) |
| 38 self.cwd = cwd | |
| 39 self.returncode = returncode | |
| 40 self.stdout = stdout | |
| 41 self.stderr = stderr | |
| 42 | 40 |
| 43 def __str__(self): | 41 def __str__(self): |
| 44 out = ' '.join(self.command) | 42 return subprocess2.CalledProcessError.__str__(self) |
| 45 if self.cwd: | |
| 46 out += ' in ' + self.cwd | |
| 47 if self.returncode is not None: | |
| 48 out += ' returned %d' % self.returncode | |
| 49 if self.stdout is not None: | |
| 50 out += '\nstdout: %s\n' % self.stdout | |
| 51 if self.stderr is not None: | |
| 52 out += '\nstderr: %s\n' % self.stderr | |
| 53 return out | |
| 54 | 43 |
| 55 | 44 |
| 56 def Popen(args, **kwargs): | 45 def Popen(args, **kwargs): |
| 57 """Calls subprocess.Popen() with hacks to work around certain behaviors. | 46 """Calls subprocess.Popen() with hacks to work around certain behaviors. |
| 58 | 47 |
| 59 Ensure English outpout for svn and make it work reliably on Windows. | 48 Ensure English outpout for svn and make it work reliably on Windows. |
| 60 """ | 49 """ |
| 61 logging.debug(u'%s, cwd=%s' % (u' '.join(args), kwargs.get('cwd', ''))) | 50 logging.debug(u'%s, cwd=%s' % (u' '.join(args), kwargs.get('cwd', ''))) |
| 62 if not 'env' in kwargs: | 51 if not 'env' in kwargs: |
| 63 # It's easier to parse the stdout if it is always in English. | 52 # It's easier to parse the stdout if it is always in English. |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 logging.info('Caught exception in thread %s' % self.item.name) | 680 logging.info('Caught exception in thread %s' % self.item.name) |
| 692 logging.info(str(sys.exc_info())) | 681 logging.info(str(sys.exc_info())) |
| 693 work_queue.exceptions.put(sys.exc_info()) | 682 work_queue.exceptions.put(sys.exc_info()) |
| 694 logging.info('Task %s done' % self.item.name) | 683 logging.info('Task %s done' % self.item.name) |
| 695 | 684 |
| 696 work_queue.ready_cond.acquire() | 685 work_queue.ready_cond.acquire() |
| 697 try: | 686 try: |
| 698 work_queue.ready_cond.notifyAll() | 687 work_queue.ready_cond.notifyAll() |
| 699 finally: | 688 finally: |
| 700 work_queue.ready_cond.release() | 689 work_queue.ready_cond.release() |
| OLD | NEW |