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 pipes | 10 import pipes |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 | 790 |
791 | 791 |
792 def GetEditor(git, git_editor=None): | 792 def GetEditor(git, git_editor=None): |
793 """Returns the most plausible editor to use. | 793 """Returns the most plausible editor to use. |
794 | 794 |
795 In order of preference: | 795 In order of preference: |
796 - GIT_EDITOR/SVN_EDITOR environment variable | 796 - GIT_EDITOR/SVN_EDITOR environment variable |
797 - core.editor git configuration variable (if supplied by git-cl) | 797 - core.editor git configuration variable (if supplied by git-cl) |
798 - VISUAL environment variable | 798 - VISUAL environment variable |
799 - EDITOR environment variable | 799 - EDITOR environment variable |
800 - vim (non-Windows) or notepad (Windows) | 800 - vi (non-Windows) or notepad (Windows) |
801 | 801 |
802 In the case of git-cl, this matches git's behaviour, except that it does not | 802 In the case of git-cl, this matches git's behaviour, except that it does not |
803 include dumb terminal detection. | 803 include dumb terminal detection. |
804 | 804 |
805 In the case of gcl, this matches svn's behaviour, except that it does not | 805 In the case of gcl, this matches svn's behaviour, except that it does not |
806 accept a command-line flag or check the editor-cmd configuration variable. | 806 accept a command-line flag or check the editor-cmd configuration variable. |
807 """ | 807 """ |
808 if git: | 808 if git: |
809 editor = os.environ.get('GIT_EDITOR') or git_editor | 809 editor = os.environ.get('GIT_EDITOR') or git_editor |
810 else: | 810 else: |
811 editor = os.environ.get('SVN_EDITOR') | 811 editor = os.environ.get('SVN_EDITOR') |
812 if not editor: | 812 if not editor: |
813 editor = os.environ.get('VISUAL') | 813 editor = os.environ.get('VISUAL') |
814 if not editor: | 814 if not editor: |
815 editor = os.environ.get('EDITOR') | 815 editor = os.environ.get('EDITOR') |
816 if not editor: | 816 if not editor: |
817 if sys.platform.startswith('win'): | 817 if sys.platform.startswith('win'): |
818 editor = 'notepad' | 818 editor = 'notepad' |
819 else: | 819 else: |
820 editor = 'vim' | 820 editor = 'vi' |
821 return editor | 821 return editor |
822 | 822 |
823 | 823 |
824 def RunEditor(content, git, git_editor=None): | 824 def RunEditor(content, git, git_editor=None): |
825 """Opens up the default editor in the system to get the CL description.""" | 825 """Opens up the default editor in the system to get the CL description.""" |
826 file_handle, filename = tempfile.mkstemp(text=True, prefix='cl_description') | 826 file_handle, filename = tempfile.mkstemp(text=True, prefix='cl_description') |
827 # Make sure CRLF is handled properly by requiring none. | 827 # Make sure CRLF is handled properly by requiring none. |
828 if '\r' in content: | 828 if '\r' in content: |
829 print >> sys.stderr, ( | 829 print >> sys.stderr, ( |
830 '!! Please remove \\r from your change description !!') | 830 '!! Please remove \\r from your change description !!') |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 | 894 |
895 Python on OSX 10.6 raises a NotImplementedError exception. | 895 Python on OSX 10.6 raises a NotImplementedError exception. |
896 """ | 896 """ |
897 try: | 897 try: |
898 import multiprocessing | 898 import multiprocessing |
899 return multiprocessing.cpu_count() | 899 return multiprocessing.cpu_count() |
900 except: # pylint: disable=W0702 | 900 except: # pylint: disable=W0702 |
901 # Mac OS 10.6 only | 901 # Mac OS 10.6 only |
902 # pylint: disable=E1101 | 902 # pylint: disable=E1101 |
903 return int(os.sysconf('SC_NPROCESSORS_ONLN')) | 903 return int(os.sysconf('SC_NPROCESSORS_ONLN')) |
OLD | NEW |