Commit 2e23ce3e authored by maruel@chromium.org's avatar maruel@chromium.org

Add colors to git cl comments.

Helps scanning faster. colorma is already slightly used by gclient but wasn't
by git-cl yet.

Update a unit test to be stricter, it was caught in the cross fire as colorma
hooks sys.stdout and stderr.

R=iannucci@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/15025003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@198689 0039d316-1c4b-4281-b951-d872f2087c98
parent 833a3853
...@@ -24,6 +24,7 @@ except ImportError: ...@@ -24,6 +24,7 @@ except ImportError:
pass pass
from third_party import colorama
from third_party import upload from third_party import upload
import breakpad # pylint: disable=W0611 import breakpad # pylint: disable=W0611
import fix_encoding import fix_encoding
...@@ -41,6 +42,8 @@ DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' ...@@ -41,6 +42,8 @@ DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup'
GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit' GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit'
CHANGE_ID = 'Change-Id:' CHANGE_ID = 'Change-Id:'
# Shortcut since it quickly becomes redundant.
Fore = colorama.Fore
# Initialized in main() # Initialized in main()
settings = None settings = None
...@@ -1101,7 +1104,17 @@ def CMDcomments(parser, args): ...@@ -1101,7 +1104,17 @@ def CMDcomments(parser, args):
if cl.GetIssue(): if cl.GetIssue():
data = cl.RpcServer().get_issue_properties(cl.GetIssue(), True) data = cl.RpcServer().get_issue_properties(cl.GetIssue(), True)
for message in sorted(data['messages'], key=lambda x: x['date']): for message in sorted(data['messages'], key=lambda x: x['date']):
print '\n%s %s' % (message['date'].split('.', 1)[0], message['sender']) if message['disapproval']:
color = Fore.RED
elif message['approval']:
color = Fore.GREEN
elif message['sender'] == data['owner_email']:
color = Fore.MAGENTA
else:
color = Fore.BLUE
print '\n%s%s %s%s' % (
color, message['date'].split('.', 1)[0], message['sender'],
Fore.RESET)
if message['text'].strip(): if message['text'].strip():
print '\n'.join(' ' + l for l in message['text'].splitlines()) print '\n'.join(' ' + l for l in message['text'].splitlines())
return 0 return 0
...@@ -1994,6 +2007,7 @@ def main(argv): ...@@ -1994,6 +2007,7 @@ def main(argv):
'\nYour python version %s is unsupported, please upgrade.\n' % '\nYour python version %s is unsupported, please upgrade.\n' %
sys.version.split(' ', 1)[0]) sys.version.split(' ', 1)[0])
return 2 return 2
# Reload settings. # Reload settings.
global settings global settings
settings = Settings() settings = Settings()
...@@ -2040,5 +2054,8 @@ def main(argv): ...@@ -2040,5 +2054,8 @@ def main(argv):
if __name__ == '__main__': if __name__ == '__main__':
# These affect sys.stdout so do it outside of main() to simplify mocks in
# unit testing.
fix_encoding.fix_encoding() fix_encoding.fix_encoding()
colorama.init()
sys.exit(main(sys.argv[1:])) sys.exit(main(sys.argv[1:]))
...@@ -455,23 +455,24 @@ class TestGitCl(TestCase): ...@@ -455,23 +455,24 @@ class TestGitCl(TestCase):
def test_reviewer_send_mail_no_rev(self): def test_reviewer_send_mail_no_rev(self):
# Fails without a reviewer. # Fails without a reviewer.
class FileMock(object): stdout = StringIO.StringIO()
buf = StringIO.StringIO() stderr = StringIO.StringIO()
def write(self, content):
self.buf.write(content)
mock = FileMock()
try: try:
self.calls = self._upload_no_rev_calls(None, None) self.calls = self._upload_no_rev_calls(None, None)
def RunEditor(desc, _, **kwargs): def RunEditor(desc, _, **kwargs):
return desc return desc
self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
self.mock(sys, 'stderr', mock) self.mock(sys, 'stdout', stdout)
self.mock(sys, 'stderr', stderr)
git_cl.main(['upload', '--send-mail']) git_cl.main(['upload', '--send-mail'])
self.fail() self.fail()
except SystemExit: except SystemExit:
self.assertEquals( self.assertEqual(
'Must specify reviewers to send email.\n', mock.buf.getvalue()) 'Using 50% similarity for rename/copy detection. Override with '
'--similarity.\n',
stdout.getvalue())
self.assertEqual(
'Must specify reviewers to send email.\n', stderr.getvalue())
def test_dcommit(self): def test_dcommit(self):
self.calls = ( self.calls = (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment