[Getan-commits] [PATCH 13 of 16] Use the new getan.template module in getan-eval.py script
Wald Commits
scm-commit at wald.intevation.org
Mon Mar 3 15:00:44 CET 2014
# HG changeset patch
# User Björn Ricks <bjoern.ricks at intevation.de>
# Date 1393853532 -3600
# Node ID 2b2e371b9bed01b7946b2c4529573b9f468107d0
# Parent f13dc9fd62d5caa911b58c640c868c5ec0092d93
Use the new getan.template module in getan-eval.py script
diff -r f13dc9fd62d5 -r 2b2e371b9bed getan/contrib/getan-eval.py
--- a/getan/contrib/getan-eval.py Mon Mar 03 14:31:25 2014 +0100
+++ b/getan/contrib/getan-eval.py Mon Mar 03 14:32:12 2014 +0100
@@ -1,32 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
-# (c) 2013 by Björn Ricks <bjoern.ricks at intevation.de>
+# (c) 2013, 2014 by Björn Ricks <bjoern.ricks at 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
+from getan.template import render
def main():
@@ -41,65 +24,25 @@
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",
+ parser.add_option("-c", "--lastweek", dest="lastweek",
+ help="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)
+ if options.lastweek:
+ week = (datetime.now() - timedelta(7)).isocalendar()[1]
+ year = int(date.today().strftime("%Y"))
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)
+ year = options.year
+ week = options.week
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
+ print render(database=options.database, user=options.user,
+ template=template_name, year=year, week=week,
+ project=options.project)
- 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()
More information about the Getan-commits
mailing list