Chromium Code Reviews| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 keys_only=False))) | 55 keys_only=False))) |
| 56 | 56 |
| 57 | 57 |
| 58 def get_previous_quarter(today): | 58 def get_previous_quarter(today): |
| 59 """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. |
| 60 | 60 |
| 61 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 |
| 62 that is requested. | 62 that is requested. |
| 63 """ | 63 """ |
| 64 year = today.year | 64 year = today.year |
| 65 month = today.month - (today.month % 3) | 65 month = today.month - (today.month % 3) + 1 |
|
Peter Mayo
2011/09/22 18:56:07
I would call these begin&end rather than blank and
| |
| 66 if not month: | 66 if month <= 0: |
| 67 month = 12 | 67 month += 12 |
| 68 year -= 1 | 68 year -= 1 |
| 69 previous_month = month - 2 | 69 if month > 12: |
| 70 month -= 12 | |
| 71 year += 1 | |
| 72 previous_month = month - 3 | |
| 73 previous_year = year | |
| 74 if previous_month <= 0: | |
| 75 previous_month += 12 | |
| 76 previous_year -= 1 | |
| 70 return ( | 77 return ( |
| 71 '%d-%02d-01' % (year, previous_month), | 78 '%d-%02d-01' % (previous_year, previous_month), |
| 72 '%d-%02d-01' % (year, month)) | 79 '%d-%02d-01' % (year, month)) |
| 73 | 80 |
| 74 | 81 |
| 75 def main(): | 82 def main(): |
| 76 # Silence upload.py. | 83 # Silence upload.py. |
| 77 rietveld.upload.verbosity = 0 | 84 rietveld.upload.verbosity = 0 |
| 85 today = datetime.date.today() | |
| 86 created_after, created_before = get_previous_quarter(today) | |
| 78 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 87 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
| 79 parser.add_option( | 88 parser.add_option( |
| 80 '--count', action='store_true', | 89 '--count', action='store_true', |
| 81 help='Just count instead of printing individual issues') | 90 help='Just count instead of printing individual issues') |
| 82 parser.add_option('-o', '--owner') | 91 parser.add_option( |
| 83 parser.add_option('-r', '--reviewer') | 92 '-o', '--owner', metavar='<email>', help='Filter on issue owner') |
| 84 parser.add_option('-c', '--created_after') | 93 parser.add_option( |
| 85 parser.add_option('-C', '--created_before') | 94 '-r', '--reviewer', metavar='<email>', help='Filter on issue reviewer') |
| 95 parser.add_option( | |
| 96 '-c', '--created_after', metavar='<date>', | |
| 97 help='Filter issues created after the date') | |
| 98 parser.add_option( | |
| 99 '-C', '--created_before', metavar='<date>', | |
| 100 help='Filter issues create before the date') | |
| 86 parser.add_option( | 101 parser.add_option( |
| 87 '-Q', '--last_quarter', action='store_true', | 102 '-Q', '--last_quarter', action='store_true', |
| 88 help='Use last quarter\'s dates as filter') | 103 help='Use last quarter\'s dates, e.g. %s to %s' % ( |
| 89 parser.add_option('-i', '--instance_url', default='codereview.chromium.org') | 104 created_after, created_before)) |
| 105 parser.add_option( | |
| 106 '-i', '--instance_url', metavar='<host>', | |
| 107 default='http://codereview.chromium.org', | |
| 108 help='Host to use, default is %default') | |
| 90 # Remove description formatting | 109 # Remove description formatting |
| 91 parser.format_description = lambda x: parser.description | 110 parser.format_description = lambda x: parser.description |
| 92 options, args = parser.parse_args() | 111 options, args = parser.parse_args() |
| 93 if args: | 112 if args: |
| 94 parser.error('Args unsupported') | 113 parser.error('Args unsupported') |
| 95 if not options.owner and not options.reviewer: | 114 if not options.owner and not options.reviewer: |
| 96 options.owner = os.environ['EMAIL_ADDRESS'] | 115 options.owner = os.environ['EMAIL_ADDRESS'] |
| 97 if '@' not in options.owner: | 116 if '@' not in options.owner: |
| 98 parser.error('Please specify at least -o or -r') | 117 parser.error('Please specify at least -o or -r') |
| 99 print >> sys.stderr, 'Defaulting to owner=%s' % options.owner | 118 print >> sys.stderr, 'Defaulting to owner=%s' % options.owner |
| 100 if options.last_quarter: | 119 if options.last_quarter: |
| 101 today = datetime.date.today() | 120 options.created_after = created_after |
| 102 options.created_after, options.created_before = get_previous_quarter(today) | 121 options.created_before = created_before |
| 103 print >> sys.stderr, 'Using range %s to %s' % ( | 122 print >> sys.stderr, 'Using range %s to %s' % ( |
| 104 options.created_after, options.created_before) | 123 options.created_after, options.created_before) |
| 105 if options.count: | 124 if options.count: |
| 106 print_count( | 125 print_count( |
| 107 options.owner, options.reviewer, | 126 options.owner, options.reviewer, |
| 108 options.created_after, options.created_before, | 127 options.created_after, options.created_before, |
| 109 options.instance_url) | 128 options.instance_url) |
| 110 else: | 129 else: |
| 111 print_reviews( | 130 print_reviews( |
| 112 options.owner, options.reviewer, | 131 options.owner, options.reviewer, |
| 113 options.created_after, options.created_before, | 132 options.created_after, options.created_before, |
| 114 options.instance_url) | 133 options.instance_url) |
| 115 return 0 | 134 return 0 |
| 116 | 135 |
| 117 | 136 |
| 118 if __name__ == '__main__': | 137 if __name__ == '__main__': |
| 119 sys.exit(main()) | 138 sys.exit(main()) |
| OLD | NEW |