annotate scripts/getan-report @ 567:1d4c20db7eac

dump version number and add CHANGES entry
author Bernhard Reiter <bernhard@intevation.de>
date Tue, 01 Jun 2021 16:07:01 +0200
parents d44ee9cd7261
children e7b36e596751
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",
551
d44ee9cd7261 Overworked standard database transfer parameter
Magnus Schieder <mschieder@intevation.de>
parents: 550
diff changeset
30 help='(default: ~/.getan/'+ DEFAULT_DATABASE + ")")
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
31 parser.add_argument('-t', '--template',
526
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
32 help="""name of getan template (wochenbericht,
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
33 zeiterfassung, zeiterfassung2),
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
34 external templates must be stored in
31282f97b807 Reworked the --help function
Magnus Schieder <mschieder@intevation.de>
parents: 490
diff changeset
35 ~/.getan/templates/ to be able to call them.""")
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
36 parser.add_argument('-u', '--user', help='name of user')
550
28b1c18c900f Specify project keys in getan-report with SQL patterns
Magnus Schieder <mschieder@intevation.de>
parents: 535
diff changeset
37 parser.add_argument('-p', '--project', help='key (sql pattern) of output project')
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
38 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
39 parser.add_argument('-y', '--year', type=int, help='year')
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
40 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
41 action='store_true')
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
42 parser.add_argument('-m', '--empty',
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
43 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
44 action="store_true")
535
d5acadeef0f8 improve usage message & simply code
Bernhard Reiter <bernhard@intevation.de>
parents: 526
diff changeset
45 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
46
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
47 args = parser.parse_args()
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
48
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
49 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
50 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
51 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
52 else:
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
53 year = args.year
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
54 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
55
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
56 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
57
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
58 if not args.encoding:
432
8d03d7ada7e1 getan-eval.py: Fixes a possible encoding detection failure.
Bernhard Reiter <bernhard@intevation.de>
parents: 431
diff changeset
59 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
60
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
61 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
62
431
8922713adbe6 getan-eval.py: Improves how 'user' is found.
Bernhard Reiter <bernhard@intevation.de>
parents: 430
diff changeset
63 user = None
463
24ccca2442b1 optparse to argparse Migration for scripts/getan-eval.py.
Magnus Schieder <mschieder@intevation.de>
parents: 432
diff changeset
64 if args.user:
484
40dd1e33c1dd Rename getan-eval.py to getaneval.py
Magnus Schieder <mschieder@intevation.de>
parents: 482
diff changeset
65 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
66
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
67 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
68 template=template_name, year=year, week=week,
467
59d9c5840273 Porting Python 2 to Python 3.
Magnus Schieder <mschieder@intevation.de>
parents: 463
diff changeset
69 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
70
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 if __name__ == '__main__':
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
73 main()
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
74
0746534b7f97 Add first draft for a template based getan time evaluation
Björn Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
75 # 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)