From 99238ec72374eed6db9705d3acb090cfb0cc56c4 Mon Sep 17 00:00:00 2001 From: SEINLET Nicolas Date: Fri, 5 Oct 2012 21:21:42 +0200 Subject: [PATCH 1/2] possibility to check if previous log hour exists instead of 4 hours --- bin/gitlog2timesheet.py | 47 ++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/bin/gitlog2timesheet.py b/bin/gitlog2timesheet.py index 6e50797..9c25dba 100644 --- a/bin/gitlog2timesheet.py +++ b/bin/gitlog2timesheet.py @@ -38,21 +38,40 @@ def gitlog(location = None): def logmessage(name = None, email = None, when = None, message = None, repo = None, commitfactor = 4, format="text"): logmessage = "" t=datetime.datetime.fromtimestamp(when) - d=t-datetime.timedelta(hours=commitfactor) - + nonecalculated = True + if options.previouslog: + prevlogkey = name + if prevlogkey in prevlogs: + nonecalculated = False + d=max(prevlogs[prevlogkey],t-datetime.timedelta(hours=commitfactor)) + #print unicode(prevlogs[prevlogkey])+"|"+unicode(t-datetime.timedelta(hours=commitfactor))+"|"+unicode(d) + + if nonecalculated: + d=t-datetime.timedelta(hours=commitfactor) + if options.total: - projectkey= repo+":"+name - if projectkey in projecttime: - projecttime[projectkey] += commitfactor + if options.previouslog: + timetoadd=((t-d).seconds/3600.0) else: - projecttime[projectkey] = commitfactor - + timetoadd=commitfactor + + projectkey= repo+":"+name + + if projectkey in projecttime: + projecttime[projectkey] += timetoadd + else: + projecttime[projectkey] = timetoadd + + if options.previouslog: + prevlogkey= name + prevlogs[prevlogkey]=t + if format == "text": logmessage = "From "+d.ctime()+" to "+t.ctime() + "\n" logmessage += " "+name+" ("+email+") worked on "+ repo +"\n" logmessage += " and did the following: "+ message elif format == "csv": - logmessage = d.ctime()+"|"+t.ctime()+"|"+unicode(commitfactor)+"|"+name+"|"+message + logmessage = d.ctime()+"|"+t.ctime()+"|"+unicode(round(timetoadd,2))+"|"+name+"|"+message return logmessage usage = "usage: %s path_to_git_repos" % sys.argv[0] @@ -62,19 +81,23 @@ parser.add_option("-w", "--commitfactor", dest="commitfactor", help="work time f parser.add_option("-t", "--total", action="store_true", dest="total", help="total hours worked for each user per repository/project", default=False) parser.add_option("-f", "--outputformat", dest="format", help="output format text, csv (default is text)", default="text", type="string") parser.add_option("-u", "--user", dest="user", help="limit timesheet to the user specified", default=None, type="string") +parser.add_option("-p", "--previouslog", action="store_true", dest="previouslog", help="user previous date, or work time factor if less, for commit duration", default=False) (options, args) = parser.parse_args() if options.total: projecttime = {} - + +if options.previouslog: + prevlogs={} + for repo in args: if not os.path.exists(repo): continue val = gitlog(location = repo) if options.debug: print val - for line in val: + for line in reversed(val): try: (name, email, when, message) = line.split("|") except: @@ -87,6 +110,6 @@ for repo in args: if options.total: for x in projecttime: if options.format == "text": - print x + "->" + unicode(projecttime[x])+" hours." + print x + "->" + unicode(int(round(projecttime[x],0)))+" hours." elif options.format == "csv": - print x.split(":")[0]+"|"+x.split(":")[1]+"|"+unicode(projecttime[x]) + print x.split(":")[0]+"|"+x.split(":")[1]+"|"+unicode(int(round(projecttime[x],0))) From 4e51c5f1d2a78af072d5dfa21d4de6e1290b2d87 Mon Sep 17 00:00:00 2001 From: SEINLET Nicolas Date: Fri, 5 Oct 2012 21:36:18 +0200 Subject: [PATCH 2/2] update doc --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 92e53f6..27ff64b 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ Usage -f FORMAT, --outputformat=FORMAT output format text, csv (default is text) -u USER, --user=USER limit timesheet to the user specified + -p, --previouslog user previous date, or work time factor if less, + for commit duration Sample output