annotate scripts/getan-report @ 527:fab6ff9b248e

Update README
author Magnus Schieder <mschieder@intevation.de>
date Thu, 24 Jan 2019 12:47:33 +0100
parents 31282f97b807
children d5acadeef0f8
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
526
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
17 from getan.backend import DEFAULT_DATABASE
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
18
347
3a1786947673 Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 283
diff changeset
19
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
20 def main():
490
11d97a40dfa5 Renamed getan-day-report to getan-daily-report.
Magnus Schieder <mschieder@intevation.de>
parents: 486
diff changeset
21 usage='getan-report [options]'
526
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
22 parser = argparse.ArgumentParser(prog='getan', usage=usage,
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
23 description="You can find more information at https://pypi.org/project/getan/")
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
24
526
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
25 parser.add_argument('-d', '--database', dest='database',metavar="DATABASE_FILE",
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
26 help='databasefile (default: ~/.getan/%(default)s)]',
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
27 default=DEFAULT_DATABASE)
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
28 parser.add_argument('-t', '--template', dest='template',
526
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
29 metavar='TEMPLATE',
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
30 help="""name of getan template (wochenbericht,
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
31 zeiterfassung, zeiterfassung2),
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
32 external templates must be stored in
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
33 ~/.getan/templates/ to be able to call them.""")
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
34 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
35 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
36 help='key of output project')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
37 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
38 help='week of year')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
39 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
40 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
41 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
42 action='store_true')
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
43 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
44 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
45 action="store_true")
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
46 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
47 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
48
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
49 args = parser.parse_args()
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
50
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
51 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
52 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
53 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
54 else:
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
55 year = args.year
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
56 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
57
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
58 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
59
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
60 if not args.encoding:
432
8d03d7ada7e1 getan-eval.py: Fixes a possible encoding detection failure.
Bernhard Reiter <bernhard@intevation.de>
parents: 431
diff changeset
61 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
62
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
63 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
64
431
8922713adbe6 getan-eval.py: Improves how 'user' is found.
Bernhard Reiter <bernhard@intevation.de>
parents: 430
diff changeset
65 user = None
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
66 if args.user:
484
40dd1e33c1dd Rename getan-eval.py to getaneval.py
Magnus Schieder <mschieder@intevation.de>
parents: 482
diff changeset
67 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
68
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
69 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
70 template=template_name, year=year, week=week,
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
71 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
72
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
73
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
74 if __name__ == '__main__':
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
75 main()
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
76
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
77 # 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)