annotate scripts/getan-report @ 509:f8099adc30f2

updated TODO.
author Magnus Schieder <mschieder@intevation.de>
date Thu, 01 Nov 2018 14:20:56 +0100
parents 11d97a40dfa5
children 31282f97b807
rev   line source
482
999a438474f2 Changed Hashbangs to python3.
Magnus Schieder <mschieder@intevation.de>
parents: 467
diff changeset
1 #!/usr/bin/env python3
283
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
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
14 import argparse
283
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():
490
11d97a40dfa5 Renamed getan-day-report to getan-daily-report.
Magnus Schieder <mschieder@intevation.de>
parents: 486
diff changeset
20 usage='getan-report [options]'
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
21 parser = argparse.ArgumentParser(prog='getan', usage=usage)
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
22
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
23 parser.add_argument('-d', '--database', dest='database',metavar="DATABASE",
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
24 help='metavar="DATABASE')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
25 parser.add_argument('-t', '--template', dest='template',
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
26 metavar='TEMPLATE', help='name of getan template')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
27 parser.add_argument('-u', '--user', dest='user', help='name of user')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
28 parser.add_argument('-p', '--project', dest='project',
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
29 help='key of output project')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
30 parser.add_argument('-w', '--week', type=int, dest='week',
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
31 help='week of year')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
32 parser.add_argument('-y', '--year', type=int, dest='year', help='year')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
33 parser.add_argument('-c', '--lastweek', dest='lastweek',
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
34 help='entries of last working week',
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
35 action='store_true')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
36 parser.add_argument('-m', '--empty', dest='empty',
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
37 help='show projects without an entries',
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
38 action="store_true")
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
39 parser.add_argument('--encoding', dest='encoding',
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
40 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
41
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
42 args = parser.parse_args()
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
43
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
44 if args.lastweek:
358
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
45 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
46 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
47 else:
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
48 year = args.year
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
49 week = args.week
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
50
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
51 template_name = args.template or "wochenbericht"
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
52
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
53 if not args.encoding:
432
8d03d7ada7e1 getan-eval.py: Fixes a possible encoding detection failure.
Bernhard Reiter <bernhard@intevation.de>
parents: 431
diff changeset
54 encoding = locale.getdefaultlocale()[1] or "utf-8"
373
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
55
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
56 sys.stdout = codecs.getwriter(encoding)(sys.stdout.detach())
373
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
57
431
8922713adbe6 getan-eval.py: Improves how 'user' is found.
Bernhard Reiter <bernhard@intevation.de>
parents: 430
diff changeset
58 user = None
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
59 if args.user:
484
40dd1e33c1dd Rename getan-eval.py to getaneval.py
Magnus Schieder <mschieder@intevation.de>
parents: 482
diff changeset
60 user = args.user
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
61
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
62 print(render(database=args.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
63 template=template_name, year=year, week=week,
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
64 project=args.project, empty_projects=args.empty))
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
65
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 if __name__ == '__main__':
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
68 main()
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
69
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
70 # 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)