| 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 about the review you done, or forgot to do. | 6 """Get rietveld stats about the review you done, or forgot to do. |
| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 created_before=created_before, | 69 created_before=created_before, |
| 70 keys_only=True))) | 70 keys_only=True))) |
| 71 | 71 |
| 72 | 72 |
| 73 def get_previous_quarter(today): | 73 def get_previous_quarter(today): |
| 74 """There are four quarters, 01-03, 04-06, 07-09, 10-12. | 74 """There are four quarters, 01-03, 04-06, 07-09, 10-12. |
| 75 | 75 |
| 76 If today is in the last month of a quarter, assume it's the current quarter | 76 If today is in the last month of a quarter, assume it's the current quarter |
| 77 that is requested. | 77 that is requested. |
| 78 """ | 78 """ |
| 79 year = today.year | 79 end_year = today.year |
| 80 month = today.month - (today.month % 3) + 1 | 80 end_month = today.month - (today.month % 3) + 1 |
| 81 if month <= 0: | 81 if end_month <= 0: |
| 82 month += 12 | 82 end_year -= 1 |
| 83 year -= 1 | 83 end_month += 12 |
| 84 if month > 12: | 84 if end_month > 12: |
| 85 month -= 12 | 85 end_year += 1 |
| 86 year += 1 | 86 end_month -= 12 |
| 87 previous_month = month - 3 | 87 end = '%d-%02d-01' % (end_year, end_month) |
| 88 previous_year = year | 88 begin_year = end_year |
| 89 if previous_month <= 0: | 89 begin_month = end_month - 3 |
| 90 previous_month += 12 | 90 if begin_month <= 0: |
| 91 previous_year -= 1 | 91 begin_year -= 1 |
| 92 return ( | 92 begin_month += 12 |
| 93 '%d-%02d-01' % (previous_year, previous_month), | 93 begin = '%d-%02d-01' % (begin_year, begin_month) |
| 94 '%d-%02d-01' % (year, month)) | 94 return begin, end |
| 95 | 95 |
| 96 | 96 |
| 97 def main(): | 97 def main(): |
| 98 # Silence upload.py. | 98 # Silence upload.py. |
| 99 rietveld.upload.verbosity = 0 | 99 rietveld.upload.verbosity = 0 |
| 100 today = datetime.date.today() | 100 today = datetime.date.today() |
| 101 created_after, created_before = get_previous_quarter(today) | 101 begin, end = get_previous_quarter(today) |
| 102 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 102 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
| 103 parser.add_option( | 103 parser.add_option( |
| 104 '--count', action='store_true', | 104 '--count', action='store_true', |
| 105 help='Just count instead of printing individual issues') | 105 help='Just count instead of printing individual issues') |
| 106 parser.add_option( | 106 parser.add_option( |
| 107 '-r', '--reviewer', metavar='<email>', | 107 '-r', '--reviewer', metavar='<email>', |
| 108 default=os.environ.get('EMAIL_ADDRESS'), | 108 default=os.environ.get('EMAIL_ADDRESS'), |
| 109 help='Filter on issue reviewer, default=%default') | 109 help='Filter on issue reviewer, default=%default') |
| 110 parser.add_option( | 110 parser.add_option( |
| 111 '-c', '--created_after', metavar='<date>', | 111 '-b', '--begin', metavar='<date>', |
| 112 help='Filter issues created after the date') | 112 help='Filter issues created after the date') |
| 113 parser.add_option( | 113 parser.add_option( |
| 114 '-C', '--created_before', metavar='<date>', | 114 '-e', '--end', metavar='<date>', |
| 115 help='Filter issues create before the date') | 115 help='Filter issues created before the date') |
| 116 parser.add_option( | 116 parser.add_option( |
| 117 '-Q', '--last_quarter', action='store_true', | 117 '-Q', '--last_quarter', action='store_true', |
| 118 help='Use last quarter\'s dates, e.g. %s to %s' % ( | 118 help='Use last quarter\'s dates, e.g. %s to %s' % ( |
| 119 created_after, created_before)) | 119 begin, end)) |
| 120 parser.add_option( | 120 parser.add_option( |
| 121 '-i', '--instance_url', metavar='<host>', | 121 '-i', '--instance_url', metavar='<host>', |
| 122 default='http://codereview.chromium.org', | 122 default='http://codereview.chromium.org', |
| 123 help='Host to use, default is %default') | 123 help='Host to use, default is %default') |
| 124 # Remove description formatting | 124 # Remove description formatting |
| 125 parser.format_description = lambda x: parser.description | 125 parser.format_description = lambda x: parser.description |
| 126 options, args = parser.parse_args() | 126 options, args = parser.parse_args() |
| 127 if args: | 127 if args: |
| 128 parser.error('Args unsupported') | 128 parser.error('Args unsupported') |
| 129 | 129 if not options.reviewer: |
| 130 parser.error('$EMAIL_ADDRESS is not set, please use -r') |
| 130 print >> sys.stderr, 'Searching for reviews by %s' % options.reviewer | 131 print >> sys.stderr, 'Searching for reviews by %s' % options.reviewer |
| 131 if options.last_quarter: | 132 if options.last_quarter: |
| 132 options.created_after = created_after | 133 options.begin = begin |
| 133 options.created_before = created_before | 134 options.end = end |
| 134 print >> sys.stderr, 'Using range %s to %s' % ( | 135 print >> sys.stderr, 'Using range %s to %s' % ( |
| 135 options.created_after, options.created_before) | 136 options.begin, options.end) |
| 136 if options.count: | 137 if options.count: |
| 137 print_count( | 138 print_count( |
| 138 options.reviewer, | 139 options.reviewer, |
| 139 options.created_after, | 140 options.begin, |
| 140 options.created_before, | 141 options.end, |
| 141 options.instance_url) | 142 options.instance_url) |
| 142 else: | 143 else: |
| 143 print_reviews( | 144 print_reviews( |
| 144 options.reviewer, | 145 options.reviewer, |
| 145 options.created_after, | 146 options.begin, |
| 146 options.created_before, | 147 options.end, |
| 147 options.instance_url) | 148 options.instance_url) |
| 148 return 0 | 149 return 0 |
| 149 | 150 |
| 150 | 151 |
| 151 if __name__ == '__main__': | 152 if __name__ == '__main__': |
| 152 sys.exit(main()) | 153 sys.exit(main()) |
| OLD | NEW |