OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 rietveld stats. | 6 """Get rietveld stats. |
7 | 7 |
8 Example: | 8 Example: |
9 - my_reviews.py -o me@chromium.org -Q for stats for last quarter. | 9 - my_reviews.py -o me@chromium.org -Q for stats for last quarter. |
10 """ | 10 """ |
(...skipping 27 matching lines...) Expand all Loading... | |
38 # By default, hide commit-bot and the domain. | 38 # By default, hide commit-bot and the domain. |
39 reviewers = set(r.split('@', 1)[0] for r in issue['reviewers']) | 39 reviewers = set(r.split('@', 1)[0] for r in issue['reviewers']) |
40 reviewers -= set(('commit-bot',)) | 40 reviewers -= set(('commit-bot',)) |
41 # Strip time. | 41 # Strip time. |
42 timestamp = issue['created'][:10] | 42 timestamp = issue['created'][:10] |
43 | 43 |
44 # More information is available, print issue.keys() to see them. | 44 # More information is available, print issue.keys() to see them. |
45 print '%d: %s %s' % (issue['issue'], timestamp, ', '.join(reviewers)) | 45 print '%d: %s %s' % (issue['issue'], timestamp, ', '.join(reviewers)) |
46 | 46 |
47 | 47 |
48 def print_count(owner, reviewer, created_after, created_before, instance_url): | |
49 remote = rietveld.Rietveld(instance_url, None, None) | |
50 print len(list(remote.search( | |
51 owner=owner, | |
52 reviewer=reviewer, | |
53 created_after=created_after, | |
54 created_before=created_before, | |
55 keys_only=False))) | |
56 | |
57 | |
48 def get_previous_quarter(today): | 58 def get_previous_quarter(today): |
49 """There are four quarters, 01-03, 04-06, 07-09, 10-12. | 59 """There are four quarters, 01-03, 04-06, 07-09, 10-12. |
50 | 60 |
51 If today is in the last month of a quarter, assume it's the current quarter | 61 If today is in the last month of a quarter, assume it's the current quarter |
52 that is requested. | 62 that is requested. |
53 """ | 63 """ |
54 year = today.year | 64 year = today.year |
55 month = today.month - (today.month % 3) | 65 month = today.month - (today.month % 3) |
56 if not month: | 66 if not month: |
57 month = 12 | 67 month = 12 |
58 year -= 1 | 68 year -= 1 |
59 previous_month = month - 2 | 69 previous_month = month - 2 |
60 return ( | 70 return ( |
61 '%d-%02d-01' % (year, previous_month), | 71 '%d-%02d-01' % (year, previous_month), |
62 '%d-%02d-01' % (year, month)) | 72 '%d-%02d-01' % (year, month)) |
63 | 73 |
64 | 74 |
65 def main(): | 75 def main(): |
76 # Silence upload.py. | |
77 rietveld.upload.verbosity = 0 | |
66 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 78 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
79 parser.add_option( | |
80 '--count', action='store_true', | |
81 help='Just count instead of printing individual issues') | |
67 parser.add_option('-o', '--owner') | 82 parser.add_option('-o', '--owner') |
68 parser.add_option('-r', '--reviewer') | 83 parser.add_option('-r', '--reviewer') |
69 parser.add_option('-c', '--created_after') | 84 parser.add_option('-c', '--created_after') |
70 parser.add_option('-C', '--created_before') | 85 parser.add_option('-C', '--created_before') |
71 parser.add_option('-Q', '--last_quarter', action='store_true') | 86 parser.add_option( |
87 '-Q', '--last_quarter', action='store_true', | |
88 help='Use last quarter dates as filter') | |
Dirk Pranke
2011/09/22 01:13:15
Nit: "last quarter's"
| |
72 parser.add_option('-i', '--instance_url', default='codereview.chromium.org') | 89 parser.add_option('-i', '--instance_url', default='codereview.chromium.org') |
73 # Remove description formatting | 90 # Remove description formatting |
74 parser.format_description = lambda x: parser.description | 91 parser.format_description = lambda x: parser.description |
75 options, args = parser.parse_args() | 92 options, args = parser.parse_args() |
76 if args: | 93 if args: |
77 parser.error('Args unsupported') | 94 parser.error('Args unsupported') |
78 if not options.owner and not options.reviewer: | 95 if not options.owner and not options.reviewer: |
79 options.owner = os.environ['EMAIL_ADDRESS'] | 96 options.owner = os.environ['EMAIL_ADDRESS'] |
80 if '@' not in options.owner: | 97 if '@' not in options.owner: |
81 parser.error('Please specify at least -o or -r') | 98 parser.error('Please specify at least -o or -r') |
82 print 'Defaulting to owner=%s' % options.owner | 99 print >> sys.stderr, 'Defaulting to owner=%s' % options.owner |
83 if options.last_quarter: | 100 if options.last_quarter: |
84 today = datetime.date.today() | 101 today = datetime.date.today() |
85 options.created_after, options.created_before = get_previous_quarter(today) | 102 options.created_after, options.created_before = get_previous_quarter(today) |
86 print 'Using range %s to %s' % ( | 103 print >> sys.stderr, 'Using range %s to %s' % ( |
87 options.created_after, options.created_before) | 104 options.created_after, options.created_before) |
88 print_reviews( | 105 if options.count: |
89 options.owner, options.reviewer, | 106 print_count( |
90 options.created_after, options.created_before, | 107 options.owner, options.reviewer, |
91 options.instance_url) | 108 options.created_after, options.created_before, |
109 options.instance_url) | |
110 else: | |
111 print_reviews( | |
112 options.owner, options.reviewer, | |
113 options.created_after, options.created_before, | |
114 options.instance_url) | |
92 return 0 | 115 return 0 |
93 | 116 |
94 | 117 |
95 if __name__ == '__main__': | 118 if __name__ == '__main__': |
96 sys.exit(main()) | 119 sys.exit(main()) |
OLD | NEW |