comparison scripts/getan-eval.py @ 380:20fde79f8e12

Move all scripts in a common scripts directory Currently console scripts were kept in several directories. Now use a common directory for all scripts.
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 05 Jan 2015 10:54:20 +0100
parents getan/contrib/getan-eval.py@82a5dd050436
children da9a400848fd
comparison
equal deleted inserted replaced
379:47890f38e558 380:20fde79f8e12
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # (c) 2013, 2014 by Björn Ricks <bjoern.ricks@intevation.de>
5 #
6 # This is Free Software licensed under the terms of GPLv3 or later.
7 # For details see LICENSE coming with the source of 'getan'.
8
9 import codecs
10 import locale
11 import sys
12
13 from datetime import date, datetime, timedelta
14 from optparse import OptionParser
15
16 from getan.template import render
17
18
19 def main():
20 parser = OptionParser()
21 parser.add_option("-d", "--database", dest="database",
22 help="getan database", metavar="DATABASE")
23 parser.add_option("-t", "--template", dest="template", metavar="TEMPLATE",
24 help="name of getan template")
25 parser.add_option("-u", "--user", dest="user", help="name of user")
26 parser.add_option("-p", "--project", dest="project",
27 help="key of output project")
28 parser.add_option("-w", "--week", type="int", dest="week",
29 help="week of year")
30 parser.add_option("-y", "--year", type="int", dest="year", help="year")
31 parser.add_option("-c", "--lastweek", dest="lastweek",
32 help="entries of last working week",
33 action="store_true")
34 parser.add_option("-m", "--empty", dest="empty",
35 help="show projects without an entries",
36 action="store_true")
37 parser.add_option("--encoding", dest="encoding",
38 help="encoding of output", metavar="ENCODING")
39
40 (options, args) = parser.parse_args()
41
42 if options.lastweek:
43 week = (datetime.now() - timedelta(7)).isocalendar()[1]
44 year = int(date.today().strftime("%Y"))
45 else:
46 year = options.year
47 week = options.week
48
49 template_name = options.template or "wochenbericht"
50
51 if not options.encoding:
52 encoding = locale.getdefaultlocale()[1]
53
54 Writer = codecs.getwriter(encoding)
55 sys.stdout = Writer(sys.stdout)
56
57 print render(database=options.database, user=options.user,
58 template=template_name, year=year, week=week,
59 project=options.project, empty_projects=options.empty)
60
61
62 if __name__ == '__main__':
63 main()
64
65 # vim:set ts=4 sw=4 si et sta sts=4 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)