| OLD | NEW |
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 args, bufsize=0, stdout=subprocess2.PIPE, stderr=subprocess2.STDOUT, | 336 args, bufsize=0, stdout=subprocess2.PIPE, stderr=subprocess2.STDOUT, |
| 337 **kwargs) | 337 **kwargs) |
| 338 | 338 |
| 339 # Do a flush of stdout before we begin reading from the subprocess2's stdout | 339 # Do a flush of stdout before we begin reading from the subprocess2's stdout |
| 340 stdout.flush() | 340 stdout.flush() |
| 341 | 341 |
| 342 # Also, we need to forward stdout to prevent weird re-ordering of output. | 342 # Also, we need to forward stdout to prevent weird re-ordering of output. |
| 343 # This has to be done on a per byte basis to make sure it is not buffered: | 343 # This has to be done on a per byte basis to make sure it is not buffered: |
| 344 # normally buffering is done for each line, but if svn requests input, no | 344 # normally buffering is done for each line, but if svn requests input, no |
| 345 # end-of-line character is output after the prompt and it would not show up. | 345 # end-of-line character is output after the prompt and it would not show up. |
| 346 in_byte = kid.stdout.read(1) | 346 try: |
| 347 if in_byte: | 347 in_byte = kid.stdout.read(1) |
| 348 if call_filter_on_first_line: | 348 if in_byte: |
| 349 filter_fn(None) | 349 if call_filter_on_first_line: |
| 350 in_line = '' | 350 filter_fn(None) |
| 351 while in_byte: | 351 in_line = '' |
| 352 if in_byte != '\r': | 352 while in_byte: |
| 353 if print_stdout: | 353 if in_byte != '\r': |
| 354 stdout.write(in_byte) | 354 if print_stdout: |
| 355 if in_byte != '\n': | 355 stdout.write(in_byte) |
| 356 in_line += in_byte | 356 if in_byte != '\n': |
| 357 else: | 357 in_line += in_byte |
| 358 filter_fn(in_line) | 358 else: |
| 359 in_line = '' | 359 filter_fn(in_line) |
| 360 in_byte = kid.stdout.read(1) | 360 in_line = '' |
| 361 # Flush the rest of buffered output. This is only an issue with | 361 in_byte = kid.stdout.read(1) |
| 362 # stdout/stderr not ending with a \n. | 362 # Flush the rest of buffered output. This is only an issue with |
| 363 if len(in_line): | 363 # stdout/stderr not ending with a \n. |
| 364 filter_fn(in_line) | 364 if len(in_line): |
| 365 rv = kid.wait() | 365 filter_fn(in_line) |
| 366 rv = kid.wait() |
| 367 except KeyboardInterrupt: |
| 368 print >> sys.stderr, 'Failed while running "%s"' % ' '.join(args) |
| 369 raise |
| 370 |
| 366 if rv: | 371 if rv: |
| 367 raise subprocess2.CalledProcessError( | 372 raise subprocess2.CalledProcessError( |
| 368 rv, args, kwargs.get('cwd', None), None, None) | 373 rv, args, kwargs.get('cwd', None), None, None) |
| 369 return 0 | 374 return 0 |
| 370 | 375 |
| 371 | 376 |
| 372 def FindGclientRoot(from_dir, filename='.gclient'): | 377 def FindGclientRoot(from_dir, filename='.gclient'): |
| 373 """Tries to find the gclient root.""" | 378 """Tries to find the gclient root.""" |
| 374 real_from_dir = os.path.realpath(from_dir) | 379 real_from_dir = os.path.realpath(from_dir) |
| 375 path = real_from_dir | 380 path = real_from_dir |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 logging.info('Caught exception in thread %s' % self.item.name) | 635 logging.info('Caught exception in thread %s' % self.item.name) |
| 631 logging.info(str(sys.exc_info())) | 636 logging.info(str(sys.exc_info())) |
| 632 work_queue.exceptions.put(sys.exc_info()) | 637 work_queue.exceptions.put(sys.exc_info()) |
| 633 logging.info('Task %s done' % self.item.name) | 638 logging.info('Task %s done' % self.item.name) |
| 634 | 639 |
| 635 work_queue.ready_cond.acquire() | 640 work_queue.ready_cond.acquire() |
| 636 try: | 641 try: |
| 637 work_queue.ready_cond.notifyAll() | 642 work_queue.ready_cond.notifyAll() |
| 638 finally: | 643 finally: |
| 639 work_queue.ready_cond.release() | 644 work_queue.ready_cond.release() |
| OLD | NEW |