| 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 """ |
| 11 import datetime | 11 import datetime |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import sys | 14 import sys |
| 15 | 15 |
| 16 import rietveld | 16 import rietveld |
| 17 | 17 |
| 18 | 18 |
| 19 def print_reviews(owner, reviewer, created_after, created_before): | 19 def print_reviews(owner, reviewer, created_after, created_before, instance_url): |
| 20 """Prints issues with the filter. | 20 """Prints issues with the filter. |
| 21 | 21 |
| 22 Set with_messages=True to search() call bellow if you want each message too. | 22 Set with_messages=True to search() call bellow if you want each message too. |
| 23 If you only want issue numbers, use keys_only=True in the search() call. | 23 If you only want issue numbers, use keys_only=True in the search() call. |
| 24 You can then use remote.get_issue_properties(issue, True) to get the data per | 24 You can then use remote.get_issue_properties(issue, True) to get the data per |
| 25 issue. | 25 issue. |
| 26 """ | 26 """ |
| 27 instance_url = 'codereview.chromium.org' | |
| 28 remote = rietveld.Rietveld(instance_url, None, None) | 27 remote = rietveld.Rietveld(instance_url, None, None) |
| 29 | 28 |
| 30 # See def search() in rietveld.py to see all the filters you can use. | 29 # See def search() in rietveld.py to see all the filters you can use. |
| 31 for issue in remote.search( | 30 for issue in remote.search( |
| 32 owner=owner, | 31 owner=owner, |
| 33 reviewer=reviewer, | 32 reviewer=reviewer, |
| 34 created_after=created_after, | 33 created_after=created_after, |
| 35 created_before=created_before, | 34 created_before=created_before, |
| 36 keys_only=False, | 35 keys_only=False, |
| 37 with_messages=False, | 36 with_messages=False, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 63 '%d-%02d-01' % (year, month)) | 62 '%d-%02d-01' % (year, month)) |
| 64 | 63 |
| 65 | 64 |
| 66 def main(): | 65 def main(): |
| 67 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 66 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
| 68 parser.add_option('-o', '--owner') | 67 parser.add_option('-o', '--owner') |
| 69 parser.add_option('-r', '--reviewer') | 68 parser.add_option('-r', '--reviewer') |
| 70 parser.add_option('-c', '--created_after') | 69 parser.add_option('-c', '--created_after') |
| 71 parser.add_option('-C', '--created_before') | 70 parser.add_option('-C', '--created_before') |
| 72 parser.add_option('-Q', '--last_quarter', action='store_true') | 71 parser.add_option('-Q', '--last_quarter', action='store_true') |
| 72 parser.add_option('-i', '--instance_url', default='codereview.chromium.org') |
| 73 # Remove description formatting | 73 # Remove description formatting |
| 74 parser.format_description = lambda x: parser.description | 74 parser.format_description = lambda x: parser.description |
| 75 options, args = parser.parse_args() | 75 options, args = parser.parse_args() |
| 76 if args: | 76 if args: |
| 77 parser.error('Args unsupported') | 77 parser.error('Args unsupported') |
| 78 if not options.owner and not options.reviewer: | 78 if not options.owner and not options.reviewer: |
| 79 options.owner = os.environ['EMAIL_ADDRESS'] | 79 options.owner = os.environ['EMAIL_ADDRESS'] |
| 80 if '@' not in options.owner: | 80 if '@' not in options.owner: |
| 81 parser.error('Please specify at least -o or -r') | 81 parser.error('Please specify at least -o or -r') |
| 82 print 'Defaulting to owner=%s' % options.owner | 82 print 'Defaulting to owner=%s' % options.owner |
| 83 if options.last_quarter: | 83 if options.last_quarter: |
| 84 today = datetime.date.today() | 84 today = datetime.date.today() |
| 85 options.created_after, options.created_before = get_previous_quarter(today) | 85 options.created_after, options.created_before = get_previous_quarter(today) |
| 86 print 'Using range %s to %s' % ( | 86 print 'Using range %s to %s' % ( |
| 87 options.created_after, options.created_before) | 87 options.created_after, options.created_before) |
| 88 print_reviews( | 88 print_reviews( |
| 89 options.owner, options.reviewer, | 89 options.owner, options.reviewer, |
| 90 options.created_after, options.created_before) | 90 options.created_after, options.created_before, |
| 91 options.instance_url) |
| 91 return 0 | 92 return 0 |
| 92 | 93 |
| 93 | 94 |
| 94 if __name__ == '__main__': | 95 if __name__ == '__main__': |
| 95 sys.exit(main()) | 96 sys.exit(main()) |
| OLD | NEW |