Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: gclient_utils.py

Issue 8360007: Move code starting the editor into a common function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Rebase against HEAD Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gcl.py ('k') | git_cl.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import re 11 import re
12 import stat 12 import stat
13 import sys 13 import sys
14 import tempfile
14 import threading 15 import threading
15 import time 16 import time
16 17
17 import subprocess2 18 import subprocess2
18 19
19 20
20 class Error(Exception): 21 class Error(Exception):
21 """gclient exception class.""" 22 """gclient exception class."""
22 pass 23 pass
23 24
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 logging.info('Caught exception in thread %s' % self.item.name) 681 logging.info('Caught exception in thread %s' % self.item.name)
681 logging.info(str(sys.exc_info())) 682 logging.info(str(sys.exc_info()))
682 work_queue.exceptions.put(sys.exc_info()) 683 work_queue.exceptions.put(sys.exc_info())
683 logging.info('_Worker.run(%s) done' % self.item.name) 684 logging.info('_Worker.run(%s) done' % self.item.name)
684 685
685 work_queue.ready_cond.acquire() 686 work_queue.ready_cond.acquire()
686 try: 687 try:
687 work_queue.ready_cond.notifyAll() 688 work_queue.ready_cond.notifyAll()
688 finally: 689 finally:
689 work_queue.ready_cond.release() 690 work_queue.ready_cond.release()
691
692
693 def GetEditor(git):
694 """Returns the most plausible editor to use."""
695 if git:
696 editor = os.environ.get('GIT_EDITOR')
697 else:
698 editor = os.environ.get('SVN_EDITOR')
699 if not editor:
700 editor = os.environ.get('EDITOR')
701 if not editor:
702 if sys.platform.startswith('win'):
703 editor = 'notepad'
704 else:
705 editor = 'vim'
706 return editor
707
708
709 def RunEditor(content, git):
710 """Opens up the default editor in the system to get the CL description."""
711 file_handle, filename = tempfile.mkstemp(text=True)
712 # Make sure CRLF is handled properly by requiring none.
713 if '\r' in content:
714 print >> sys.stderr, ('!! Please remove \\r from your content !!')
715 fileobj = os.fdopen(file_handle, 'w')
716 # Still remove \r if present.
717 fileobj.write(re.sub('\r?\n', '\n', content))
718 fileobj.close()
719
720 try:
721 cmd = '%s %s' % (GetEditor(git), filename)
722 if sys.platform == 'win32' and os.environ.get('TERM') == 'msys':
723 # Msysgit requires the usage of 'env' to be present.
724 cmd = 'env ' + cmd
725 try:
726 # shell=True to allow the shell to handle all forms of quotes in
727 # $EDITOR.
728 subprocess2.check_call(cmd, shell=True)
729 except subprocess2.CalledProcessError:
730 return None
731 return FileRead(filename)
732 finally:
733 os.remove(filename)
OLDNEW
« no previous file with comments | « gcl.py ('k') | git_cl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698