changeset 283:0746534b7f97

Add first draft for a template based getan time evaluation At the end the getan-eval script should replace zeiterfassung.py and wochenbericht.
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 16 Apr 2013 09:47:07 +0200 (2013-04-16)
parents 12aa8208bb36
children 561441fde2ac
files getan/contrib/getan-eval.py getan/templates/wochenbericht
diffstat 2 files changed, 107 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/getan/contrib/getan-eval.py	Tue Apr 16 09:47:07 2013 +0200
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# (c) 2013 by Björn Ricks <bjoern.ricks@intevation.de>
+#
+# This is Free Software licensed under the terms of GPLv3 or later.
+# For details see LICENSE coming with the source of 'getan'.
+#
+
+import os.path
+import sqlite3 as db
+import sys
+
+from datetime import date, datetime, timedelta
+from optparse import OptionParser
+
+from jinja2 import Environment, ChoiceLoader, FileSystemLoader, PackageLoader
+
+from getan.contrib.zeiterfassung import unix_week
+
+DEFAULT_DATABASE = "time.db"
+
+def tolerant_close(c):
+    if c:
+        try:
+            c.close()
+        except:
+            pass
+
+def main():
+    parser = OptionParser()
+    parser.add_option("-d", "--database", dest="database",
+            help="getan database",  metavar="DATABASE")
+    parser.add_option("-t", "--template", dest="template", metavar="TEMPLATE",
+            help="name of getan template")
+    parser.add_option("-u", "--user", dest="user", help="name of user")
+    parser.add_option("-p", "--project", dest="project",
+        help="key of output project")
+    parser.add_option("-w", "--week", type="int", dest="week",
+            help="week of year")
+    parser.add_option("-y", "--year", type="int", dest="year", help="year")
+    parser.add_option("-c", "--lastweek", dest="entries of last working week",
+            action="store_true")
+
+    (options, args) = parser.parse_args()
+
+    if os.path.isfile(DEFAULT_DATABASE):
+        database = os.path.abspath(DEFAULT_DATABASE)
+    else:
+        database = os.path.expanduser(os.path.join("~", ".getan",
+                                      DEFAULT_DATABASE))
+    if options.database:
+        database = options.database
+
+    if options.user:
+        user = options.user
+    else:
+        user = os.getenv("USER")
+
+    year = options.year
+    week = options.week
+    u_week = None
+
+    if not year:
+        year = int(date.today().strftime("%Y"))
+
+    if week is None:
+        week = (datetime.now()-timedelta(7)).isocalendar()[1]
+
+    u_week = "%02d" % unix_week(week, year)
+
+
+    if not os.path.isfile(database):
+        print >> sys.stderr, "'%s' does not exist or is not a file." % database
+        sys.exit(1)
+
+    loader = ChoiceLoader([FileSystemLoader(os.path.expanduser(os.path.join(
+        "~", ".getan", "templates"))),
+        PackageLoader("getan")])
+    env = Environment(loader=loader)
+
+    template_name = options.template or "wochenbericht"
+    template = env.get_template(template_name)
+
+    context = dict()
+    context["user"] = user
+    context["database"] = database
+    context["year"] = year
+    context["week"] = week
+    context["unix_week"] = u_week
+
+    con = None
+    cur = None
+    try:
+        con = db.connect(database)
+        cur = con.cursor()
+    finally:
+        tolerant_close(cur)
+        tolerant_close(con)
+
+    print template.render(context)
+
+if __name__ == '__main__':
+    main()
+
+# vim:set ts=4 sw=4 si et sta sts=4 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/getan/templates/wochenbericht	Tue Apr 16 09:47:07 2013 +0200
@@ -0,0 +1,1 @@
+{{ user }}, (KW {{ week }}, {{ year }})
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)