annotate scripts/zeiterfassung.py @ 382:7a63212924c3

Rename getan_report.py to getan-report.py All scripts are using the minus symbol do split words.
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 05 Jan 2015 11:04:07 +0100
parents 20fde79f8e12
children b8cd8751cba0
rev   line source
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 #!/usr/bin/env python
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 #
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
4 # zeiterfassung
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5 # -------------
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
6 # (c) 2008 by Sascha L. Teichmann <sascha.teichmann@intevation.de>
128
46ed1b94629d Add copyright statement
Björn Ricks <bjoern.ricks@intevation.de>
parents: 127
diff changeset
7 # (c) 2011, 2012 by Björn Ricks <bjoern.ricks@intevation.de>
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8 #
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9 # Simple script which generates lines for zeiterfassung.txt files.
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10 #
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 # This is Free Software licensed under the terms of GPLv3 or later.
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
12 # For details see LICENSE coming with the source of 'getan'.
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13 #
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14 import sys
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 import getopt
10
4f782a05b4dc contrib/zeiterfassung: Added parameter -e | --encoding=
Sascha L. Teichmann <teichmann@intevation.de>
parents: 9
diff changeset
16 import codecs
127
5b334ab7f1b0 Set default encoding
Björn Ricks <bjoern.ricks@intevation.de>
parents: 126
diff changeset
17 import locale
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
19 from datetime import datetime, timedelta
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
21 from getan.template import render
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23 DEFAULT_DATABASE = "time.db"
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
25 ZEITERFASSUNG_TEMPLATE = "zeiterfassung"
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 USAGE = '''usage: %s <options>
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28 with <options>
9
4e8f5545256d * Applied and completed Stephan Holl's zeiterfassung.bessere-lesbarkeit.patch
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8
diff changeset
29 [--user=|-u <user>] : Name of user, default: $USER
4e8f5545256d * Applied and completed Stephan Holl's zeiterfassung.bessere-lesbarkeit.patch
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8
diff changeset
30 [--database=|-d <database>]: getan database, default: time.db
4e8f5545256d * Applied and completed Stephan Holl's zeiterfassung.bessere-lesbarkeit.patch
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8
diff changeset
31 [--project=|-p <key>] : Key of output project, default: all
10
4f782a05b4dc contrib/zeiterfassung: Added parameter -e | --encoding=
Sascha L. Teichmann <teichmann@intevation.de>
parents: 9
diff changeset
32 [--encoding=|-e encoding] : encoding of output, default: none
13
e347f0de5e22 Applied Stephan Holl's week-option.patch
Sascha L. Teichmann <teichmann@intevation.de>
parents: 11
diff changeset
33 [--week=]|-w <week>] : week of year
51
3f97954868e4 add year option to usage output
Björn Ricks <bjoern.ricks@intevation.de>
parents: 46
diff changeset
34 [--year=]|-y <year>] : year
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 [--list|-l] : list all projects
60
9df5d62e6f7e add switch to show also empty projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 59
diff changeset
36 [--help|-h] : This text
108
e7548b8c6dcc Add option to show entries of last week
Björn Ricks <bjoern.ricks@intevation.de>
parents: 61
diff changeset
37 [--emtpy|-m] : show empty projects
e7548b8c6dcc Add option to show entries of last week
Björn Ricks <bjoern.ricks@intevation.de>
parents: 61
diff changeset
38 [--lastweek|-c] : entries of last working week'''
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39
51
3f97954868e4 add year option to usage output
Björn Ricks <bjoern.ricks@intevation.de>
parents: 46
diff changeset
40
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
41 def usage(exit_code=0):
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
42 print USAGE % sys.argv[0]
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 sys.exit(exit_code)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
44
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
45
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46 def main():
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
47
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
48 database = DEFAULT_DATABASE
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
49 user = None
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 list_projects = False
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
51 project = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
52 encoding = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
53 week = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
54 year = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
55 empty_proj = False
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
56 database = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
57 template = ZEITERFASSUNG_TEMPLATE
122
653767ecb0fe Use current dir time.db if exists if not ~/.getan/time.db
Björn Ricks <bjoern.ricks@intevation.de>
parents: 121
diff changeset
58
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
59 opts, args = getopt.getopt(
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
60 sys.argv[1:],
108
e7548b8c6dcc Add option to show entries of last week
Björn Ricks <bjoern.ricks@intevation.de>
parents: 61
diff changeset
61 'd:u:p:e:hl:w:y:mc',
e7548b8c6dcc Add option to show entries of last week
Björn Ricks <bjoern.ricks@intevation.de>
parents: 61
diff changeset
62 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=',
e7548b8c6dcc Add option to show entries of last week
Björn Ricks <bjoern.ricks@intevation.de>
parents: 61
diff changeset
63 'year=', 'empty', 'lastweek'])
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
64
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
65 for opt, val in opts:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
66 if opt in ("--database", "-d"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
67 database = val
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
68 elif opt in ("--user", "-u"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
69 user = val
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
70 elif opt in ("--project", "-p"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
71 project = val
10
4f782a05b4dc contrib/zeiterfassung: Added parameter -e | --encoding=
Sascha L. Teichmann <teichmann@intevation.de>
parents: 9
diff changeset
72 elif opt in ("--encoding", "-e"):
4f782a05b4dc contrib/zeiterfassung: Added parameter -e | --encoding=
Sascha L. Teichmann <teichmann@intevation.de>
parents: 9
diff changeset
73 encoding = val
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
74 elif opt in ("--help", "-h"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
75 usage()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
76 elif opt in ("--list", "-l"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
77 list_projects = True
46
5f87604ea5ed add year option for contrib/zeiterfassung
Bjoern Ricks <bricks@intevation.de>
parents: 16
diff changeset
78 elif opt in ("--year", "-y"):
5f87604ea5ed add year option for contrib/zeiterfassung
Bjoern Ricks <bricks@intevation.de>
parents: 16
diff changeset
79 year = val
192
9bb175cfaca3 Use unix_week conversion function for zeiterfassung
Björn Ricks <bjoern.ricks@intevation.de>
parents: 191
diff changeset
80 elif opt in ("--week", "-w"):
9bb175cfaca3 Use unix_week conversion function for zeiterfassung
Björn Ricks <bjoern.ricks@intevation.de>
parents: 191
diff changeset
81 week = int(val)
9bb175cfaca3 Use unix_week conversion function for zeiterfassung
Björn Ricks <bjoern.ricks@intevation.de>
parents: 191
diff changeset
82 elif opt in ("--lastweek", "-c") and not week:
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
83 week = (datetime.now() - timedelta(7)).isocalendar()[1]
60
9df5d62e6f7e add switch to show also empty projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 59
diff changeset
84 elif opt in ("--empty", "-m"):
9df5d62e6f7e add switch to show also empty projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 59
diff changeset
85 empty_proj = True
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
86
127
5b334ab7f1b0 Set default encoding
Björn Ricks <bjoern.ricks@intevation.de>
parents: 126
diff changeset
87 if not encoding:
5b334ab7f1b0 Set default encoding
Björn Ricks <bjoern.ricks@intevation.de>
parents: 126
diff changeset
88 encoding = locale.getdefaultlocale()[1]
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
89
127
5b334ab7f1b0 Set default encoding
Björn Ricks <bjoern.ricks@intevation.de>
parents: 126
diff changeset
90 Writer = codecs.getwriter(encoding)
5b334ab7f1b0 Set default encoding
Björn Ricks <bjoern.ricks@intevation.de>
parents: 126
diff changeset
91 sys.stdout = Writer(sys.stdout)
10
4f782a05b4dc contrib/zeiterfassung: Added parameter -e | --encoding=
Sascha L. Teichmann <teichmann@intevation.de>
parents: 9
diff changeset
92
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
93 print render(user=user, database=database, week=week, year=year,
360
1b190fa27482 Allow to render only projects with entries in templates
Björn Ricks <bjoern.ricks@intevation.de>
parents: 359
diff changeset
94 template=template, project=project, empty_projects=empty_proj)
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
95
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
96
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
97 if __name__ == '__main__':
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
98 main()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
99
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
100 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)