annotate scripts/getan-report @ 535:d5acadeef0f8

improve usage message & simply code * Shorten help output for `--database` as the good option name is enough to explain. * Fix typo in help output for `--empty' * Simplyied code by removing `dest` and `metavar` for add_argument where it was not necessary because it was already the default if those parameters are not given. * Add Intevation and Magnus as rights holder and author for 2019 and 2020.
author Bernhard Reiter <bernhard@intevation.de>
date Wed, 08 Jan 2020 09:22:23 +0100
parents 31282f97b807
children 28b1c18c900f
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>
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
5 # 2019, 2020 Intevation GmbH
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
6 # Author(s):
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
7 # * Björn Ricks
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
8 # * Magnus Schieder
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
9 #
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
10 # 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
11 # 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
12
373
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
13 import codecs
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
14 import locale
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
15 import sys
82a5dd050436 Allow to set encoding in getan-eval
Björn Ricks <bjoern.ricks@intevation.de>
parents: 360
diff changeset
16
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
17 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
18 import argparse
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
19
358
2b2e371b9bed Use the new getan.template module in getan-eval.py script
Björn Ricks <bjoern.ricks@intevation.de>
parents: 347
diff changeset
20 from getan.template import render
526
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
21 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
22
347
3a1786947673 Fix coding style for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 283
diff changeset
23
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
24 def main():
490
11d97a40dfa5 Renamed getan-day-report to getan-daily-report.
Magnus Schieder <mschieder@intevation.de>
parents: 486
diff changeset
25 usage='getan-report [options]'
526
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
26 parser = argparse.ArgumentParser(prog='getan', usage=usage,
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
27 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
28
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
29 parser.add_argument('-d', '--database', metavar="DATABASE_FILE",
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
30 help='(default: ~/.getan/%(default)s)]',
526
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
31 default=DEFAULT_DATABASE)
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
32 parser.add_argument('-t', '--template',
526
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
33 help="""name of getan template (wochenbericht,
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
34 zeiterfassung, zeiterfassung2),
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
35 external templates must be stored in
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
36 ~/.getan/templates/ to be able to call them.""")
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
37 parser.add_argument('-u', '--user', help='name of user')
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
38 parser.add_argument('-p', '--project', help='key of output project')
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
39 parser.add_argument('-w', '--week', type=int, help='week of year')
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
40 parser.add_argument('-y', '--year', type=int, help='year')
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
41 parser.add_argument('-c', '--lastweek', help='entries of last working week',
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
42 action='store_true')
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
43 parser.add_argument('-m', '--empty',
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
44 help='show projects without an entry',
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
45 action="store_true")
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
46 parser.add_argument('--encoding', help='encoding of output')
283
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
47
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
48 args = parser.parse_args()
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
49
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
50 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
51 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
52 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
53 else:
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
54 year = args.year
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
55 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
56
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
57 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
58
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
59 if not args.encoding:
432
8d03d7ada7e1 getan-eval.py: Fixes a possible encoding detection failure.
Bernhard Reiter <bernhard@intevation.de>
parents: 431
diff changeset
60 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
61
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
62 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
63
431
8922713adbe6 getan-eval.py: Improves how 'user' is found.
Bernhard Reiter <bernhard@intevation.de>
parents: 430
diff changeset
64 user = None
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
65 if args.user:
484
40dd1e33c1dd Rename getan-eval.py to getaneval.py
Magnus Schieder <mschieder@intevation.de>
parents: 482
diff changeset
66 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
67
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
68 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
69 template=template_name, year=year, week=week,
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
70 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
71
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 if __name__ == '__main__':
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
74 main()
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
75
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
76 # 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)