From de2a36cba6dff2fa8a6a93187ff30ba717a159bc Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Mon, 9 Jun 2008 21:24:15 +0200 Subject: [PATCH] gitstats: Added dispatching to the author module Also added a stub for aggregateActivity which will aggregate the activity for each author into a short summary. This way when listing activity for all authors the screen doesn't turn into a chaos of file:activity pairs. --- src/git_stats/author.py | 76 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/src/git_stats/author.py b/src/git_stats/author.py index d840494..35b8127 100644 --- a/src/git_stats/author.py +++ b/src/git_stats/author.py @@ -1,7 +1,13 @@ #!/usr/bin/env python +import os +import sys + +from optparse import OptionParser from git_python import Git +from git_stats import commit + class Activity: """Simple storage class containing stats on the activity in one file.""" @@ -97,38 +103,82 @@ def activityInArea(log, filterid): # Return the result return activityByPath -def activity(id): +def activity(id, field, startFrom): """Shows the activity for the specified developer in the current repo. Params: id: The id of the developer, currently only e-mail address is accepted. + field: The field to filter on. + startfrom: The commit to start logging from. """ git = Git(".") - result = git.log("--numstat", "--pretty=format:%ae") + result = git.log("--numstat", "--pretty=format:%" + field, startFrom) log = result.splitlines(True) activity = activityInArea(log, id) + result = [] + for key, value in activity.iteritems(): - print(str(key) + " = " + str(value)) + result.append(str(key) + " = " + str(value)) + + return result + +def aggregateActivity(idFilter, field, startFrom): + """Aggregates the activity for all developers + + Args: + idFilter: The id to filter on, if None all developers will be shown. + field: The field to filter on. + """ + + result = [] + + # TODO, implement + + return result def dispatch(*args): """Dispatches author related commands """ - pass + progname = os.path.basename(sys.argv[0]) + " author" -if __name__ == '__main__': - path = "testrepo.log" - - # Open the log file - file = open(path) + parser = OptionParser(option_class=commit.CommitOption, prog=progname) - log = file.readlines() + parser.add_option( + "-a", "--aggregate", + action="store_true", + help="aggregate the results") - activity = activityInArea(log, "sverre@rabbelier.nl") + parser.add_option( + "-d", "--developer", + help="the id to filter on") - for key, value in activity.iteritems(): - print(str(key) + " = " + str(value)) + parser.add_option( + "-i", "--id", + help="the one/two letter identifier specifying which field to filter on") + + parser.add_option( + "-s", "--start-from", + type="commit", + metavar="COMMIT", + help="the commit to start logging from") + + parser.set_default("id", "ae") + parser.set_default("start_from", "HEAD") + + (options, args) = parser.parse_args(list(args)) + + if not options.aggregate and not options.developer: + parser.error("When not specifying a developer the -a switch is required") + + if options.aggregate: + result = aggregateActivity(options.developer, options.id, options.start_from) + else: + result = activity(options.developer, options.id, options.start_from) + + for line in result: + print(line) -- 2.11.4.GIT