Chromium Code Reviews| 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 tempfile | |
| 15 import threading | 16 import threading |
| 16 import time | 17 import time |
| 17 import xml.dom.minidom | 18 import xml.dom.minidom |
| 18 import xml.parsers.expat | 19 import xml.parsers.expat |
| 19 | 20 |
| 20 | 21 |
| 21 def hack_subprocess(): | 22 def hack_subprocess(): |
| 22 """subprocess functions may throw exceptions when used in multiple threads. | 23 """subprocess functions may throw exceptions when used in multiple threads. |
| 23 | 24 |
| 24 See http://bugs.python.org/issue1731717 for more information. | 25 See http://bugs.python.org/issue1731717 for more information. |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 logging.info('Caught exception in thread %s' % self.item.name) | 704 logging.info('Caught exception in thread %s' % self.item.name) |
| 704 logging.info(str(sys.exc_info())) | 705 logging.info(str(sys.exc_info())) |
| 705 work_queue.exceptions.put(sys.exc_info()) | 706 work_queue.exceptions.put(sys.exc_info()) |
| 706 logging.info('Task %s done' % self.item.name) | 707 logging.info('Task %s done' % self.item.name) |
| 707 | 708 |
| 708 work_queue.ready_cond.acquire() | 709 work_queue.ready_cond.acquire() |
| 709 try: | 710 try: |
| 710 work_queue.ready_cond.notifyAll() | 711 work_queue.ready_cond.notifyAll() |
| 711 finally: | 712 finally: |
| 712 work_queue.ready_cond.release() | 713 work_queue.ready_cond.release() |
| 714 | |
| 715 | |
| 716 def GetEditor(): | |
| 717 editor = os.environ.get("SVN_EDITOR") | |
| 718 if not editor: | |
| 719 editor = os.environ.get("EDITOR") | |
| 720 | |
| 721 if not editor: | |
| 722 if sys.platform.startswith("win"): | |
| 723 editor = "notepad" | |
| 724 else: | |
| 725 editor = "vi" | |
| 726 | |
| 727 return editor | |
| 728 | |
| 729 | |
| 730 def UserEdit(text): | |
| 731 """Open an editor, edit the text, and return the result.""" | |
| 732 (file_handle, filename) = tempfile.mkstemp() | |
| 733 fileobj = os.fdopen(file_handle, 'w') | |
| 734 fileobj.write(text) | |
| 735 fileobj.close() | |
| 736 | |
| 737 # Open up the default editor in the system to get the CL description. | |
| 738 try: | |
| 739 cmd = '%s %s' % (GetEditor(), filename) | |
| 740 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys': | |
| 741 # Msysgit requires the usage of 'env' to be present. | |
| 742 cmd = 'env ' + cmd | |
| 743 # shell=True to allow the shell to handle all forms of quotes in $EDITOR. | |
| 744 subprocess.check_call(cmd, shell=True) | |
| 745 text = FileRead(filename, 'r') | |
|
M-A Ruel
2011/03/22 17:24:16
you can return right here, no need for 'text' vari
| |
| 746 finally: | |
| 747 os.remove(filename) | |
| 748 | |
| 749 return text | |
| OLD | NEW |