From 18bc90d2d295d336c4dea336f0161e8197a138cd Mon Sep 17 00:00:00 2001 From: "nyquist@chromium.org" Date: Thu, 20 Dec 2012 19:26:47 +0000 Subject: [PATCH] Add support for specifying my_activity.py list format. This adds the possibility to specify the format for your activity through: -f , --output-format= is specified as in strings.format(...). It is also possible to specify the output format for specific activity types. This enables users to use other formats such as Markdown: [%(title)s](%(url)s) This CL also adds support for new variables such as author, and adds a generic framework for adding more variables. BUG=166519 Review URL: https://chromiumcodereview.appspot.com/11607007 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@174203 0039d316-1c4b-4281-b951-d872f2087c98 --- my_activity.py | 109 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 25 deletions(-) diff --git a/my_activity.py b/my_activity.py index 3bd13d7cae..7333984bef 100755 --- a/my_activity.py +++ b/my_activity.py @@ -470,8 +470,8 @@ class MyActivity(object): ret['modified'] = datetime_from_google_code(issue['updated']['$t']) ret['owner'] = '' - if 'issues:owner' in issue: - ret['owner'] = issue['issues:owner'][0]['issues:username'][0]['$t'] + if 'issues$owner' in issue: + ret['owner'] = issue['issues$owner']['issues$username']['$t'] ret['author'] = issue['author'][0]['name']['$t'] if 'shorturl' in project: @@ -708,19 +708,49 @@ class MyActivity(object): print "No %s in committers.py, skipping WebKit checks." % email self.webkit_repo = None - @staticmethod - def print_change(change): - print '%s %s' % ( - change['review_url'], - change['header'], - ) + def print_change(self, change): + self.print_generic(self.options.output_format, + self.options.output_format_changes, + change['header'], + change['review_url'], + change['author']) + + def print_issue(self, issue): + optional_values = { + 'owner': issue['owner'], + } + self.print_generic(self.options.output_format, + self.options.output_format_issues, + issue['header'], + issue['url'], + issue['author'], + optional_values) + + def print_review(self, review): + self.print_generic(self.options.output_format, + self.options.output_format_reviews, + review['header'], + review['review_url'], + review['author']) @staticmethod - def print_issue(issue): - print '%s %s' % ( - issue['url'], - issue['header'], - ) + def print_generic(default_fmt, specific_fmt, + title, url, author, + optional_values=None): + output_format = specific_fmt if specific_fmt is not None else default_fmt + output_format = unicode(output_format) + required_values = { + 'title': title, + 'url': url, + 'author': author, + } + # Merge required and optional values. + if optional_values is not None: + values = dict(required_values.items() + optional_values.items()) + else: + values = required_values + print output_format.format(**values) + def filter_issue(self, issue, should_filter_by_user=True): def maybe_filter_username(email): @@ -791,7 +821,7 @@ class MyActivity(object): if self.reviews: print '\nReviews:' for review in self.reviews: - self.print_change(review) + self.print_review(review) def get_issues(self): for project in google_code_projects: @@ -800,6 +830,12 @@ class MyActivity(object): for instance in bugzilla_instances: self.issues += self.bugzilla_issues(instance, self.user) + def print_issues(self): + if self.issues: + print '\nIssues:' + for issue in self.issues: + self.print_issue(issue) + def process_activities(self): # If a webkit bug was a review, don't list it as an issue. ids = {} @@ -814,12 +850,6 @@ class MyActivity(object): self.issues = filter(lambda issue: not duplicate_issue(issue), self.issues) - def print_issues(self): - if self.issues: - print '\nIssues:' - for c in self.issues: - self.print_issue(c) - def print_activity(self): self.print_changes() self.print_reviews() @@ -862,23 +892,52 @@ def main(): action='store_true', help='Ask to authenticate for instances with no auth cookie') - group = optparse.OptionGroup(parser, 'Activity Types', + activity_types_group = optparse.OptionGroup(parser, 'Activity Types', 'By default, all activity will be looked up and ' 'printed. If any of these are specified, only ' 'those specified will be searched.') - group.add_option( + activity_types_group.add_option( '-c', '--changes', action='store_true', help='Show changes.') - group.add_option( + activity_types_group.add_option( '-i', '--issues', action='store_true', help='Show issues.') - group.add_option( + activity_types_group.add_option( '-r', '--reviews', action='store_true', help='Show reviews.') - parser.add_option_group(group) + parser.add_option_group(activity_types_group) + + output_format_group = optparse.OptionGroup(parser, 'Output Format', + 'By default, all activity will be printed in the ' + 'following format: {url} {title}. This can be ' + 'changed for either all activity types or ' + 'individually for each activity type. The format ' + 'is defined as documented for ' + 'string.format(...). The variables available for ' + 'all activity types are url, title and author. ' + 'Format options for specific activity types will ' + 'override the generic format.') + output_format_group.add_option( + '-f', '--output-format', metavar='', + default=u'{url} {title}', + help='Specifies the format to use when printing all your activity.') + output_format_group.add_option( + '--output-format-changes', metavar='', + default=None, + help='Specifies the format to use when printing changes.') + output_format_group.add_option( + '--output-format-issues', metavar='', + default=None, + help='Specifies the format to use when printing issues. Has support ' + 'for the additional variable owner.') + output_format_group.add_option( + '--output-format-reviews', metavar='', + default=None, + help='Specifies the format to use when printing reviews.') + parser.add_option_group(output_format_group) # Remove description formatting parser.format_description = (