From 89ad8bfe5a0c1db80eabe7b28327d95ff03241dc Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sat, 26 May 2012 12:08:45 +0200 Subject: [PATCH] Old Python script to generate timesheet committed. Markov chain generation removed (until now) --- README | 52 ++++++++++++++++++++++++++++++++ bin/gitlog2timesheet.py | 66 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 README create mode 100644 bin/gitlog2timesheet.py diff --git a/README b/README new file mode 100644 index 0000000..def6544 --- /dev/null +++ b/README @@ -0,0 +1,52 @@ +gilog2timesheet +=============== + +gitlog2timesheet is a tool to general timesheet from git logs. + +Usage +----- + + Usage: gitlog2timesheet.py path_to_git_repo(s) ... + + Options: + -h, --help show this help message and exit + -d, --debug output debug messages + -w COMMITFACTOR, --commitfactor=COMMITFACTOR + work time factor per commit, default is 4 hours + +Sample output +------------- + + + gitlog2timesheet.py /home/adulau/git/forban + + From Mon Apr 9 15:12:02 2012 to Mon Apr 9 16:12:02 2012 + Alexandre Dulaunoy (a@foo.be) worked on forban + and did the following: Fixed #12 test if loot directory exists + + From Mon Apr 9 13:30:30 2012 to Mon Apr 9 14:30:30 2012 + Alexandre Dulaunoy (a@foo.be) worked on forban + and did the following: Fixed #9 lootcleanup added + + From Mon Apr 9 12:41:42 2012 to Mon Apr 9 13:41:42 2012 + Alexandre Dulaunoy (a@foo.be) worked on forban + and did the following: Fixed #10 The browsing is now naturally sorted. + + From Sun Apr 8 10:35:10 2012 to Sun Apr 8 11:35:10 2012 + Alexandre Dulaunoy (a@foo.be) worked on forban + and did the following: Fixed #7 cleanup mode added + +Software required +----------------- + +* Python 2.4 and up +* git + +Note +---- + +Usually assuming that a commit has an amount of time spent on it is usually wrong. + +But the tool is usually used for organizational structure requiring timesheet in a +strict format like who did what and when. You have been warned. + diff --git a/bin/gitlog2timesheet.py b/bin/gitlog2timesheet.py new file mode 100644 index 0000000..d44febc --- /dev/null +++ b/bin/gitlog2timesheet.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# +# gitlog2timesheet - generate timesheet from git log +# +# Copyright (C) 2009-2012 Alexandre Dulaunoy (a AT foo.be) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import subprocess +import os.path +import sys +import datetime +from optparse import OptionParser + +def gitlog(location = None): + if location is None or not os.path.exists(location): + return None + l = [] + cmd = ["git", "log", "--no-merges", "--simplify-merges", "--format=%an|%ae|%at|%s"] + p = subprocess.Popen(cmd,cwd=location,stdout=subprocess.PIPE) + output = p.stdout.read() + for line in output.split("\n"): + l.append(line) + return l + +def logmessage(name = None, email = None, when = None, message = None, repo = None, commitfactor = 4): + logmessage = "" + t=datetime.datetime.fromtimestamp(when) + d=t-datetime.timedelta(hours=commitfactor) + + logmessage = "From "+d.ctime()+" to "+t.ctime() + "\n" + logmessage += " "+name+" ("+email+") worked on "+ repo +"\n" + logmessage += " and did the following: "+ message +"\n" + return logmessage + +usage = "usage: %s path_to_git_repos" % sys.argv[0] +parser = OptionParser(usage) +parser.add_option("-d", "--debug", action="store_true" ,dest="debug", help="output debug messages", default=False) +parser.add_option("-w", "--commitfactor", dest="commitfactor", help="work time factor per commit, default is 4 hours",default=4, type="int") + +(options, args) = parser.parse_args() + +for repo in args: + val = gitlog(location = repo) + if options.debug: + print val + for line in val: + try: + (name, email, when, message) = line.split("|") + except: + continue + print logmessage(name=unicode(name), email=email, when=float(when), commitfactor = options.commitfactor, message=unicode(message), repo = os.path.basename(os.path.normpath(repo))) + +