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

Side by Side Diff: my_activity.py

Issue 46413002: Switch my_activity.py to use gerrit_util for gerrit REST connections (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 7 years, 1 month 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 | « gerrit_util.py ('k') | no next file » | 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 """Get stats about your activity. 6 """Get stats about your activity.
7 7
8 Example: 8 Example:
9 - my_activity.py for stats for the current week (last week on mondays). 9 - my_activity.py for stats for the current week (last week on mondays).
10 - my_activity.py -Q for stats for last quarter. 10 - my_activity.py -Q for stats for last quarter.
(...skipping 17 matching lines...) Expand all
28 from functools import partial 28 from functools import partial
29 import json 29 import json
30 import optparse 30 import optparse
31 import os 31 import os
32 import re 32 import re
33 import subprocess 33 import subprocess
34 import sys 34 import sys
35 import urllib 35 import urllib
36 import urllib2 36 import urllib2
37 37
38 import gerrit_util
38 import rietveld 39 import rietveld
39 from third_party import upload 40 from third_party import upload
40 41
41 # Imported later, once options are set. 42 # Imported later, once options are set.
42 webkitpy = None 43 webkitpy = None
43 44
44 try: 45 try:
45 from dateutil.relativedelta import relativedelta # pylint: disable=F0401 46 from dateutil.relativedelta import relativedelta # pylint: disable=F0401
46 except ImportError: 47 except ImportError:
47 print 'python-dateutil package required' 48 print 'python-dateutil package required'
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 'requires_auth': False, 113 'requires_auth': False,
113 'email_domain': 'chromium.org', 114 'email_domain': 'chromium.org',
114 }, 115 },
115 ] 116 ]
116 117
117 gerrit_instances = [ 118 gerrit_instances = [
118 { 119 {
119 'url': 'chromium-review.googlesource.com', 120 'url': 'chromium-review.googlesource.com',
120 'shorturl': 'crosreview.com', 121 'shorturl': 'crosreview.com',
121 }, 122 },
122 # TODO(deymo): chrome-internal-review requires login credentials. Enable once 123 {
123 # login support is added to this client. See crbug.com/281695. 124 'url': 'chrome-internal-review.googlesource.com',
124 #{ 125 'shorturl': 'crosreview.com/i',
125 # 'url': 'chrome-internal-review.googlesource.com', 126 },
126 # 'shorturl': 'crosreview.com/i',
127 #},
128 { 127 {
129 'host': 'gerrit.chromium.org', 128 'host': 'gerrit.chromium.org',
130 'port': 29418, 129 'port': 29418,
131 }, 130 },
132 { 131 {
133 'host': 'gerrit-int.chromium.org', 132 'host': 'gerrit-int.chromium.org',
134 'port': 29419, 133 'port': 29419,
135 }, 134 },
136 ] 135 ]
137 136
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 '--format', 'JSON', 396 '--format', 'JSON',
398 '--comments', 397 '--comments',
399 '--'] + filters 398 '--'] + filters
400 (stdout, _) = subprocess.Popen(gquery_cmd, stdout=subprocess.PIPE, 399 (stdout, _) = subprocess.Popen(gquery_cmd, stdout=subprocess.PIPE,
401 stderr=subprocess.PIPE).communicate() 400 stderr=subprocess.PIPE).communicate()
402 # Drop the last line of the output with the stats. 401 # Drop the last line of the output with the stats.
403 issues = stdout.splitlines()[:-1] 402 issues = stdout.splitlines()[:-1]
404 return map(json.loads, issues) 403 return map(json.loads, issues)
405 404
406 @staticmethod 405 @staticmethod
407 def gerrit_changes_over_rest(instance, filters): 406 def gerrit_changes_over_rest(instance, filters):
deymo 2013/10/30 21:36:33 I think the same functionality implemented in this
408 # See https://gerrit-review.googlesource.com/Documentation/rest-api.html 407 # See https://gerrit-review.googlesource.com/Documentation/rest-api.html
409 # Gerrit doesn't allow filtering by created time, only modified time. 408 # Gerrit doesn't allow filtering by created time, only modified time.
410 args = urllib.urlencode([ 409 args = urllib.urlencode([
411 ('q', ' '.join(filters)), 410 ('q', ' '.join(filters)),
412 ('o', 'MESSAGES'), 411 ('o', 'MESSAGES'),
413 ('o', 'LABELS')]) 412 ('o', 'LABELS')])
414 rest_url = 'https://%s/changes/?%s' % (instance['url'], args) 413 conn = gerrit_util.CreateHttpConn(instance['url'], 'changes/?%s' % args)
415 414
416 req = urllib2.Request(rest_url, headers={'Accept': 'text/plain'})
417 try: 415 try:
418 response = urllib2.urlopen(req) 416 response = gerrit_util.ReadHttpResponse(conn, ignore_404=False)
419 stdout = response.read() 417 stdout = response.read()
420 except urllib2.HTTPError, e: 418 except gerrit_util.GerritError, e:
421 print 'ERROR: Looking up %r: %s' % (rest_url, e) 419 print 'ERROR: Looking up %r: %s' % (instance['url'], e)
422 return [] 420 return []
423 421
424 # Check that the returned JSON starts with the right marker. 422 # Check that the returned JSON starts with the right marker.
425 if stdout[:5] != ")]}'\n": 423 if stdout[:5] != ")]}'\n":
426 print 'ERROR: Marker not found on REST API response: %r' % stdout[:5] 424 print 'ERROR: Marker not found on REST API response: %r' % stdout[:5]
427 return [] 425 return []
428 return json.loads(stdout[5:]) 426 return json.loads(stdout[5:])
429 427
430 def gerrit_search(self, instance, owner=None, reviewer=None): 428 def gerrit_search(self, instance, owner=None, reviewer=None):
431 max_age = datetime.today() - self.modified_after 429 max_age = datetime.today() - self.modified_after
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 print '\n\n\n' 1103 print '\n\n\n'
1106 1104
1107 my_activity.print_changes() 1105 my_activity.print_changes()
1108 my_activity.print_reviews() 1106 my_activity.print_reviews()
1109 my_activity.print_issues() 1107 my_activity.print_issues()
1110 return 0 1108 return 0
1111 1109
1112 1110
1113 if __name__ == '__main__': 1111 if __name__ == '__main__':
1114 sys.exit(main()) 1112 sys.exit(main())
OLDNEW
« no previous file with comments | « gerrit_util.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698