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

Side by Side Diff: git_cl.py

Issue 15025003: Add colors to git cl comments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix import Created 7 years, 7 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 | « no previous file | tests/git_cl_test.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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 import json 10 import json
11 import logging 11 import logging
12 import optparse 12 import optparse
13 import os 13 import os
14 import re 14 import re
15 import stat 15 import stat
16 import sys 16 import sys
17 import textwrap 17 import textwrap
18 import urlparse 18 import urlparse
19 import urllib2 19 import urllib2
20 20
21 try: 21 try:
22 import readline # pylint: disable=F0401,W0611 22 import readline # pylint: disable=F0401,W0611
23 except ImportError: 23 except ImportError:
24 pass 24 pass
25 25
26 26
27 from third_party import colorama
27 from third_party import upload 28 from third_party import upload
28 import breakpad # pylint: disable=W0611 29 import breakpad # pylint: disable=W0611
29 import fix_encoding 30 import fix_encoding
30 import gclient_utils 31 import gclient_utils
31 import presubmit_support 32 import presubmit_support
32 import rietveld 33 import rietveld
33 import scm 34 import scm
34 import subprocess2 35 import subprocess2
35 import watchlists 36 import watchlists
36 37
37 38
38 DEFAULT_SERVER = 'https://codereview.appspot.com' 39 DEFAULT_SERVER = 'https://codereview.appspot.com'
39 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' 40 POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s'
40 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' 41 DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup'
41 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' 42 GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit'
42 CHANGE_ID = 'Change-Id:' 43 CHANGE_ID = 'Change-Id:'
43 44
45 # Shortcut since it quickly becomes redundant.
46 Fore = colorama.Fore
44 47
45 # Initialized in main() 48 # Initialized in main()
46 settings = None 49 settings = None
47 50
48 51
49 def DieWithError(message): 52 def DieWithError(message):
50 print >> sys.stderr, message 53 print >> sys.stderr, message
51 sys.exit(1) 54 sys.exit(1)
52 55
53 56
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 def CMDcomments(parser, args): 1097 def CMDcomments(parser, args):
1095 """show review comments of the current changelist""" 1098 """show review comments of the current changelist"""
1096 (_, args) = parser.parse_args(args) 1099 (_, args) = parser.parse_args(args)
1097 if args: 1100 if args:
1098 parser.error('Unsupported argument: %s' % args) 1101 parser.error('Unsupported argument: %s' % args)
1099 1102
1100 cl = Changelist() 1103 cl = Changelist()
1101 if cl.GetIssue(): 1104 if cl.GetIssue():
1102 data = cl.RpcServer().get_issue_properties(cl.GetIssue(), True) 1105 data = cl.RpcServer().get_issue_properties(cl.GetIssue(), True)
1103 for message in sorted(data['messages'], key=lambda x: x['date']): 1106 for message in sorted(data['messages'], key=lambda x: x['date']):
1104 print '\n%s %s' % (message['date'].split('.', 1)[0], message['sender']) 1107 if message['disapproval']:
1108 color = Fore.RED
1109 elif message['approval']:
1110 color = Fore.GREEN
1111 elif message['sender'] == data['owner_email']:
1112 color = Fore.MAGENTA
1113 else:
1114 color = Fore.BLUE
1115 print '\n%s%s %s%s' % (
1116 color, message['date'].split('.', 1)[0], message['sender'],
1117 Fore.RESET)
1105 if message['text'].strip(): 1118 if message['text'].strip():
1106 print '\n'.join(' ' + l for l in message['text'].splitlines()) 1119 print '\n'.join(' ' + l for l in message['text'].splitlines())
1107 return 0 1120 return 0
1108 1121
1109 1122
1110 def CreateDescriptionFromLog(args): 1123 def CreateDescriptionFromLog(args):
1111 """Pulls out the commit log to use as a base for the CL description.""" 1124 """Pulls out the commit log to use as a base for the CL description."""
1112 log_args = [] 1125 log_args = []
1113 if len(args) == 1 and not args[0].endswith('.'): 1126 if len(args) == 1 and not args[0].endswith('.'):
1114 log_args = [args[0] + '..'] 1127 log_args = [args[0] + '..']
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 2000
1988 2001
1989 def main(argv): 2002 def main(argv):
1990 """Doesn't parse the arguments here, just find the right subcommand to 2003 """Doesn't parse the arguments here, just find the right subcommand to
1991 execute.""" 2004 execute."""
1992 if sys.hexversion < 0x02060000: 2005 if sys.hexversion < 0x02060000:
1993 print >> sys.stderr, ( 2006 print >> sys.stderr, (
1994 '\nYour python version %s is unsupported, please upgrade.\n' % 2007 '\nYour python version %s is unsupported, please upgrade.\n' %
1995 sys.version.split(' ', 1)[0]) 2008 sys.version.split(' ', 1)[0])
1996 return 2 2009 return 2
2010
1997 # Reload settings. 2011 # Reload settings.
1998 global settings 2012 global settings
1999 settings = Settings() 2013 settings = Settings()
2000 2014
2001 # Do it late so all commands are listed. 2015 # Do it late so all commands are listed.
2002 CMDhelp.usage_more = ('\n\nCommands are:\n' + '\n'.join([ 2016 CMDhelp.usage_more = ('\n\nCommands are:\n' + '\n'.join([
2003 ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip()) 2017 ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip())
2004 for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')])) 2018 for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')]))
2005 2019
2006 # Create the option parse and add --verbose support. 2020 # Create the option parse and add --verbose support.
(...skipping 26 matching lines...) Expand all
2033 DieWithError( 2047 DieWithError(
2034 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2048 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2035 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2049 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2036 2050
2037 # Not a known command. Default to help. 2051 # Not a known command. Default to help.
2038 GenUsage(parser, 'help') 2052 GenUsage(parser, 'help')
2039 return CMDhelp(parser, argv) 2053 return CMDhelp(parser, argv)
2040 2054
2041 2055
2042 if __name__ == '__main__': 2056 if __name__ == '__main__':
2057 # These affect sys.stdout so do it outside of main() to simplify mocks in
2058 # unit testing.
2043 fix_encoding.fix_encoding() 2059 fix_encoding.fix_encoding()
2060 colorama.init()
2044 sys.exit(main(sys.argv[1:])) 2061 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698