annotate 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
rev   line source
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
1 #!/usr/bin/env python
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
3 #
358
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
4 # (c) 2013, 2014 by Björn Ricks <bjoern.ricks@intevation.de>
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
5 #
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
6 # This is Free Software licensed under the terms of GPLv3 or later.
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
7 # For details see LICENSE coming with the source of 'getan'.
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
8
373
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
9 import codecs
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
10 import locale
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
11 import sys
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
12
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
13 from datetime import date, datetime, timedelta
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
14 from optparse import OptionParser
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
15
358
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
16 from getan.template import render
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
17
347
3a1786947673 Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 283
diff changeset
18
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
19 def main():
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
20 parser = OptionParser()
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
21 parser.add_option("-d", "--database", dest="database",
347
3a1786947673 Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 283
diff changeset
22 help="getan database", metavar="DATABASE")
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
23 parser.add_option("-t", "--template", dest="template", metavar="TEMPLATE",
347
3a1786947673 Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 283
diff changeset
24 help="name of getan template")
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
25 parser.add_option("-u", "--user", dest="user", help="name of user")
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
26 parser.add_option("-p", "--project", dest="project",
347
3a1786947673 Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 283
diff changeset
27 help="key of output project")
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
28 parser.add_option("-w", "--week", type="int", dest="week",
347
3a1786947673 Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 283
diff changeset
29 help="week of year")
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
30 parser.add_option("-y", "--year", type="int", dest="year", help="year")
358
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
31 parser.add_option("-c", "--lastweek", dest="lastweek",
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
32 help="entries of last working week",
347
3a1786947673 Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 283
diff changeset
33 action="store_true")
360
1b190fa27482 Allow to render only projects with entries in templates
Björn Ricks <bjoern.ricks@intevation.de>
parents: 358
diff changeset
34 parser.add_option("-m", "--empty", dest="empty",
1b190fa27482 Allow to render only projects with entries in templates
Björn Ricks <bjoern.ricks@intevation.de>
parents: 358
diff changeset
35 help="show projects without an entries",
1b190fa27482 Allow to render only projects with entries in templates
Björn Ricks <bjoern.ricks@intevation.de>
parents: 358
diff changeset
36 action="store_true")
373
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
37 parser.add_option("--encoding", dest="encoding",
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
38 help="encoding of output", metavar="ENCODING")
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
39
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
40 (options, args) = parser.parse_args()
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
41
358
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
42 if options.lastweek:
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
43 week = (datetime.now() - timedelta(7)).isocalendar()[1]
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
44 year = int(date.today().strftime("%Y"))
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
45 else:
358
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
46 year = options.year
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
47 week = options.week
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
48
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
49 template_name = options.template or "wochenbericht"
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
50
373
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
51 if not options.encoding:
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
52 encoding = locale.getdefaultlocale()[1]
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
53
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
54 Writer = codecs.getwriter(encoding)
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
55 sys.stdout = Writer(sys.stdout)
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
56
358
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
57 print render(database=options.database, user=options.user,
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
58 template=template_name, year=year, week=week,
360
1b190fa27482 Allow to render only projects with entries in templates
Björn Ricks <bjoern.ricks@intevation.de>
parents: 358
diff changeset
59 project=options.project, empty_projects=options.empty)
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
60
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
61
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
62 if __name__ == '__main__':
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
63 main()
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
64
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
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)