annotate scripts/zeiterfassung.py @ 395:4bcf0bf118ff

templates/zeiterfassung2: improved: "category" instead of "project". Fixed missing newline before new workpackage.
author Bernhard Reiter <bernhard@intevation.de>
date Mon, 02 Mar 2015 12:17:28 +0100
parents 617ced8c7a40
children
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>
392
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
29 [--user=|-u <user>] : Name of user, default: $USER
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
30 [--database=|-d <database>]: getan database, default: time.db
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
31 [--project=|-p <key>] : Key of output project, default: all
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
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
392
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
38 [--lastweek|-c] : entries of last working week
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
39 [--template|-t <template>] : jinja2 template to use, default: zeiterfassung
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
40 '''
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
41
51
3f97954868e4 add year option to usage output
Björn Ricks <bjoern.ricks@intevation.de>
parents: 46
diff changeset
42
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
43 def usage(exit_code=0):
392
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
44 print USAGE % sys.argv[0],
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
45 sys.exit(exit_code)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
47
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
48 def main():
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
49
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
50 database = DEFAULT_DATABASE
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
51 user = None
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 list_projects = False
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
53 project = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
54 encoding = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
55 week = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
56 year = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
57 empty_proj = False
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
58 database = None
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
59 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
60
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
61 opts, args = getopt.getopt(
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
62 sys.argv[1:],
392
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
63 'd:u:p:e:hl:w:y:mct:',
108
e7548b8c6dcc Add option to show entries of last week
Björn Ricks <bjoern.ricks@intevation.de>
parents: 61
diff changeset
64 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=',
392
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
65 'year=', 'empty', 'lastweek', 'template='])
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
66
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
67 for opt, val in opts:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
68 if opt in ("--database", "-d"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
69 database = val
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
70 elif opt in ("--user", "-u"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
71 user = val
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
72 elif opt in ("--project", "-p"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
73 project = val
10
4f782a05b4dc contrib/zeiterfassung: Added parameter -e | --encoding=
Sascha L. Teichmann <teichmann@intevation.de>
parents: 9
diff changeset
74 elif opt in ("--encoding", "-e"):
4f782a05b4dc contrib/zeiterfassung: Added parameter -e | --encoding=
Sascha L. Teichmann <teichmann@intevation.de>
parents: 9
diff changeset
75 encoding = val
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
76 elif opt in ("--help", "-h"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
77 usage()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
78 elif opt in ("--list", "-l"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
79 list_projects = True
46
5f87604ea5ed add year option for contrib/zeiterfassung
Bjoern Ricks <bricks@intevation.de>
parents: 16
diff changeset
80 elif opt in ("--year", "-y"):
386
b8cd8751cba0 Fix: year must be an int in template.render function
Björn Ricks <bjoern.ricks@intevation.de>
parents: 380
diff changeset
81 year = int(val)
192
9bb175cfaca3 Use unix_week conversion function for zeiterfassung
Björn Ricks <bjoern.ricks@intevation.de>
parents: 191
diff changeset
82 elif opt in ("--week", "-w"):
9bb175cfaca3 Use unix_week conversion function for zeiterfassung
Björn Ricks <bjoern.ricks@intevation.de>
parents: 191
diff changeset
83 week = int(val)
9bb175cfaca3 Use unix_week conversion function for zeiterfassung
Björn Ricks <bjoern.ricks@intevation.de>
parents: 191
diff changeset
84 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
85 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
86 elif opt in ("--empty", "-m"):
9df5d62e6f7e add switch to show also empty projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 59
diff changeset
87 empty_proj = True
392
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
88 elif opt in ("--template", "-t"):
617ced8c7a40 scripts/zeiterfassung.py: enabled choice of used templates.
Bernhard Reiter <bernhard@intevation.de>
parents: 386
diff changeset
89 template = val
8
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
90
127
5b334ab7f1b0 Set default encoding
Björn Ricks <bjoern.ricks@intevation.de>
parents: 126
diff changeset
91 if not encoding:
5b334ab7f1b0 Set default encoding
Björn Ricks <bjoern.ricks@intevation.de>
parents: 126
diff changeset
92 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
93
127
5b334ab7f1b0 Set default encoding
Björn Ricks <bjoern.ricks@intevation.de>
parents: 126
diff changeset
94 Writer = codecs.getwriter(encoding)
5b334ab7f1b0 Set default encoding
Björn Ricks <bjoern.ricks@intevation.de>
parents: 126
diff changeset
95 sys.stdout = Writer(sys.stdout)
10
4f782a05b4dc contrib/zeiterfassung: Added parameter -e | --encoding=
Sascha L. Teichmann <teichmann@intevation.de>
parents: 9
diff changeset
96
359
5df363bba5cb Change zeiterfassung.py script to use getan.template
Björn Ricks <bjoern.ricks@intevation.de>
parents: 192
diff changeset
97 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
98 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
99
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
100
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
101 if __name__ == '__main__':
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
102 main()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
103
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
104 # 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)