OLD | NEW |
---|---|
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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 print "Failed to import WebKit committer list, skipping WebKit checks." | 702 print "Failed to import WebKit committer list, skipping WebKit checks." |
703 self.webkit_repo = None | 703 self.webkit_repo = None |
704 return | 704 return |
705 | 705 |
706 if not webkit_account(self.user): | 706 if not webkit_account(self.user): |
707 email = self.user + "@chromium.org" | 707 email = self.user + "@chromium.org" |
708 print "No %s in committers.py, skipping WebKit checks." % email | 708 print "No %s in committers.py, skipping WebKit checks." % email |
709 self.webkit_repo = None | 709 self.webkit_repo = None |
710 | 710 |
711 @staticmethod | 711 @staticmethod |
712 def print_change(change): | 712 def print_change(change, output_format): |
713 print '%s %s' % ( | 713 print output_format % { |
cjhopman
2012/12/17 23:03:51
Could this use string.format() instead of %?
nyquist
2012/12/19 07:08:11
Done.
| |
714 change['review_url'], | 714 'title': change['header'], |
715 change['header'], | 715 'url': change['review_url'] |
716 ) | 716 } |
717 | 717 |
718 @staticmethod | 718 @staticmethod |
719 def print_issue(issue): | 719 def print_issue(issue, output_format): |
cjhopman
2012/12/17 23:08:27
To ensure that the different formatters are always
nyquist
2012/12/19 07:08:11
Done.
| |
720 print '%s %s' % ( | 720 print output_format % { |
721 issue['url'], | 721 'title': issue['header'], |
722 issue['header'], | 722 'url': issue['url'], |
723 ) | 723 } |
724 | 724 |
725 def filter_issue(self, issue, should_filter_by_user=True): | 725 def filter_issue(self, issue, should_filter_by_user=True): |
726 def maybe_filter_username(email): | 726 def maybe_filter_username(email): |
727 return not should_filter_by_user or username(email) == self.user | 727 return not should_filter_by_user or username(email) == self.user |
728 if (maybe_filter_username(issue['author']) and | 728 if (maybe_filter_username(issue['author']) and |
729 self.filter_modified(issue['created'])): | 729 self.filter_modified(issue['created'])): |
730 return True | 730 return True |
731 if (maybe_filter_username(issue['owner']) and | 731 if (maybe_filter_username(issue['owner']) and |
732 (self.filter_modified(issue['created']) or | 732 (self.filter_modified(issue['created']) or |
733 self.filter_modified(issue['modified']))): | 733 self.filter_modified(issue['modified']))): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 for instance in gerrit_instances: | 766 for instance in gerrit_instances: |
767 self.changes += self.gerrit_search(instance, owner=self.user) | 767 self.changes += self.gerrit_search(instance, owner=self.user) |
768 | 768 |
769 for instance in git_instances: | 769 for instance in git_instances: |
770 self.changes += self.git_search(instance, owner=self.user) | 770 self.changes += self.git_search(instance, owner=self.user) |
771 | 771 |
772 def print_changes(self): | 772 def print_changes(self): |
773 if self.changes: | 773 if self.changes: |
774 print '\nChanges:' | 774 print '\nChanges:' |
775 for change in self.changes: | 775 for change in self.changes: |
776 self.print_change(change) | 776 self.print_change(change, self.options.output_format) |
777 | 777 |
778 def get_reviews(self): | 778 def get_reviews(self): |
779 for instance in rietveld_instances: | 779 for instance in rietveld_instances: |
780 self.reviews += self.rietveld_search(instance, reviewer=self.user) | 780 self.reviews += self.rietveld_search(instance, reviewer=self.user) |
781 | 781 |
782 for instance in gerrit_instances: | 782 for instance in gerrit_instances: |
783 reviews = self.gerrit_search(instance, reviewer=self.user) | 783 reviews = self.gerrit_search(instance, reviewer=self.user) |
784 reviews = filter(lambda r: not username(r['owner']) == self.user, reviews) | 784 reviews = filter(lambda r: not username(r['owner']) == self.user, reviews) |
785 self.reviews += reviews | 785 self.reviews += reviews |
786 | 786 |
787 for instance in git_instances: | 787 for instance in git_instances: |
788 self.reviews += self.git_search(instance, reviewer=self.user) | 788 self.reviews += self.git_search(instance, reviewer=self.user) |
789 | 789 |
790 def print_reviews(self): | 790 def print_reviews(self): |
791 if self.reviews: | 791 if self.reviews: |
792 print '\nReviews:' | 792 print '\nReviews:' |
793 for review in self.reviews: | 793 for review in self.reviews: |
794 self.print_change(review) | 794 self.print_change(review, self.options.output_format) |
795 | 795 |
796 def get_issues(self): | 796 def get_issues(self): |
797 for project in google_code_projects: | 797 for project in google_code_projects: |
798 self.issues += self.google_code_issue_search(project) | 798 self.issues += self.google_code_issue_search(project) |
799 | 799 |
800 for instance in bugzilla_instances: | 800 for instance in bugzilla_instances: |
801 self.issues += self.bugzilla_issues(instance, self.user) | 801 self.issues += self.bugzilla_issues(instance, self.user) |
802 | 802 |
803 def process_activities(self): | 803 def process_activities(self): |
804 # If a webkit bug was a review, don't list it as an issue. | 804 # If a webkit bug was a review, don't list it as an issue. |
805 ids = {} | 805 ids = {} |
806 for review in self.reviews + self.changes: | 806 for review in self.reviews + self.changes: |
807 if 'webkit_bug_id' in review: | 807 if 'webkit_bug_id' in review: |
808 ids[review['webkit_bug_id']] = True | 808 ids[review['webkit_bug_id']] = True |
809 | 809 |
810 def duplicate_issue(issue): | 810 def duplicate_issue(issue): |
811 if 'webkit_bug_id' not in issue: | 811 if 'webkit_bug_id' not in issue: |
812 return False | 812 return False |
813 return issue['webkit_bug_id'] in ids | 813 return issue['webkit_bug_id'] in ids |
814 | 814 |
815 self.issues = filter(lambda issue: not duplicate_issue(issue), self.issues) | 815 self.issues = filter(lambda issue: not duplicate_issue(issue), self.issues) |
816 | 816 |
817 def print_issues(self): | 817 def print_issues(self): |
818 if self.issues: | 818 if self.issues: |
819 print '\nIssues:' | 819 print '\nIssues:' |
820 for c in self.issues: | 820 for c in self.issues: |
821 self.print_issue(c) | 821 self.print_issue(c, self.options.output_format) |
822 | 822 |
823 def print_activity(self): | 823 def print_activity(self): |
824 self.print_changes() | 824 self.print_changes() |
825 self.print_reviews() | 825 self.print_reviews() |
826 self.print_issues() | 826 self.print_issues() |
827 | 827 |
828 | 828 |
829 def main(): | 829 def main(): |
830 # Silence upload.py. | 830 # Silence upload.py. |
831 rietveld.upload.verbosity = 0 | 831 rietveld.upload.verbosity = 0 |
(...skipping 22 matching lines...) Expand all Loading... | |
854 parser.add_option( | 854 parser.add_option( |
855 '-Y', '--this_year', action='store_true', | 855 '-Y', '--this_year', action='store_true', |
856 help='Use this year\'s dates') | 856 help='Use this year\'s dates') |
857 parser.add_option( | 857 parser.add_option( |
858 '-w', '--week_of', metavar='<date>', | 858 '-w', '--week_of', metavar='<date>', |
859 help='Show issues for week of the date') | 859 help='Show issues for week of the date') |
860 parser.add_option( | 860 parser.add_option( |
861 '-a', '--auth', | 861 '-a', '--auth', |
862 action='store_true', | 862 action='store_true', |
863 help='Ask to authenticate for instances with no auth cookie') | 863 help='Ask to authenticate for instances with no auth cookie') |
864 | 864 parser.add_option( |
865 '-f', '--output_format', | |
866 dest='output_format', metavar='<format>', | |
867 default='%(url)s %(title)s', | |
868 help='Specifies the format to use when printing your activity.' | |
869 ' Uses standard Python string formatting and defaults to:' | |
870 ' %(url)s %(title)s') | |
cjhopman
2012/12/17 23:08:27
Should the help also specify what named arguments
nyquist
2012/12/19 07:08:11
Done.
| |
865 group = optparse.OptionGroup(parser, 'Activity Types', | 871 group = optparse.OptionGroup(parser, 'Activity Types', |
866 'By default, all activity will be looked up and ' | 872 'By default, all activity will be looked up and ' |
867 'printed. If any of these are specified, only ' | 873 'printed. If any of these are specified, only ' |
868 'those specified will be searched.') | 874 'those specified will be searched.') |
869 group.add_option( | 875 group.add_option( |
870 '-c', '--changes', | 876 '-c', '--changes', |
871 action='store_true', | 877 action='store_true', |
872 help='Show changes.') | 878 help='Show changes.') |
873 group.add_option( | 879 group.add_option( |
874 '-i', '--issues', | 880 '-i', '--issues', |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 print '\n\n\n' | 949 print '\n\n\n' |
944 | 950 |
945 my_activity.print_changes() | 951 my_activity.print_changes() |
946 my_activity.print_reviews() | 952 my_activity.print_reviews() |
947 my_activity.print_issues() | 953 my_activity.print_issues() |
948 return 0 | 954 return 0 |
949 | 955 |
950 | 956 |
951 if __name__ == '__main__': | 957 if __name__ == '__main__': |
952 sys.exit(main()) | 958 sys.exit(main()) |
OLD | NEW |