Mercurial > getan
annotate scripts/getan-eval.py @ 429:5ee2ce059338
getan-eval.py: improves diagnosis.
* (minor) In case of missing -u/--user parameter, scripts/getan-eval.py
will output an error message.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Mon, 29 May 2017 14:22:06 +0200 |
parents | da9a400848fd |
children | e2b05afaf1bc |
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") |
429
5ee2ce059338
getan-eval.py: improves diagnosis.
Bernhard Reiter <bernhard@intevation.de>
parents:
390
diff
changeset
|
25 parser.add_option("-u", "--user", dest="user", |
5ee2ce059338
getan-eval.py: improves diagnosis.
Bernhard Reiter <bernhard@intevation.de>
parents:
390
diff
changeset
|
26 help="[REQUIRED] name of user") |
283
0746534b7f97
Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 help="entries of last working week", |
347
3a1786947673
Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
283
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 action="store_true") |
373
82a5dd050436
Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents:
360
diff
changeset
|
38 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
|
39 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
|
40 |
0746534b7f97
Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
41 (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
|
42 |
358
2b2e371b9bed
Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents:
347
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 |
0746534b7f97
Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
50 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
|
51 |
373
82a5dd050436
Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents:
360
diff
changeset
|
52 if not options.encoding: |
82a5dd050436
Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents:
360
diff
changeset
|
53 encoding = locale.getdefaultlocale()[1] |
82a5dd050436
Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents:
360
diff
changeset
|
54 |
82a5dd050436
Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents:
360
diff
changeset
|
55 Writer = codecs.getwriter(encoding) |
82a5dd050436
Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents:
360
diff
changeset
|
56 sys.stdout = Writer(sys.stdout) |
82a5dd050436
Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents:
360
diff
changeset
|
57 |
390
da9a400848fd
Fix using umlauts in usernames like Björn for getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents:
380
diff
changeset
|
58 if options.user: |
da9a400848fd
Fix using umlauts in usernames like Björn for getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents:
380
diff
changeset
|
59 user = options.user.decode(encoding) |
429
5ee2ce059338
getan-eval.py: improves diagnosis.
Bernhard Reiter <bernhard@intevation.de>
parents:
390
diff
changeset
|
60 else: |
5ee2ce059338
getan-eval.py: improves diagnosis.
Bernhard Reiter <bernhard@intevation.de>
parents:
390
diff
changeset
|
61 parser.error("You have to give the -u/--user parameter.") |
390
da9a400848fd
Fix using umlauts in usernames like Björn for getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents:
380
diff
changeset
|
62 |
da9a400848fd
Fix using umlauts in usernames like Björn for getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents:
380
diff
changeset
|
63 print render(database=options.database, user=user, |
358
2b2e371b9bed
Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents:
347
diff
changeset
|
64 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
|
65 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
|
66 |
0746534b7f97
Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
67 |
0746534b7f97
Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
68 if __name__ == '__main__': |
0746534b7f97
Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
69 main() |
0746534b7f97
Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
70 |
0746534b7f97
Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
71 # vim:set ts=4 sw=4 si et sta sts=4 : |