annotate contrib/zeiterfassung @ 8:20414d892f04

Added script to generate lines for zeiterfassung.txt
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 01 Aug 2008 18:13:31 +0200
parents
children 4e8f5545256d
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>
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
7 #
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8 # 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
9 #
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10 # 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
11 # 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
12 #
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13 import os
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14 import os.path
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 import sys
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16 import getopt
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 import re
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19 from pysqlite2 import dbapi2 as db
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21 from datetime import date
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
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 TYPE_OF_ENTRY = "-"
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 WORKPACKAGE = re.compile("^\[(\w*)(\s|\])")
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29 USAGE = '''usage: %s <options>
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 with <options>
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 [--user=|-u <user>] : Name of user, default: $USER
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32 [--database=|-d <database>]: getan database, default: time.db
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33 [--project|-p] : Key of output project, default: all
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
34 [--list|-l] : list all projects
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 [--help|-h] : This text'''
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
36
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 LIST_PROJECTS = '''
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38 SELECT key, description, active FROM projects
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39 '''
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
40
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
41 PROJECT_ID_BY_KEY = '''
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
42 SELECT id FROM projects where key = :key
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 '''
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
44
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
45 ALL_PROJECT_IDS = '''
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46 SELECT id, key FROM projects;
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
47 '''
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
48
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
49 ENTRIES = '''
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 SELECT
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
51 date(start_time),
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 sum(strftime('%s', stop_time) - strftime('%s', start_time)),
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
53 'no description'
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
54 FROM entries
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
55 WHERE
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
56 project_id = :project_id AND
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
57 (description IS NULL or length(description) = 0) -- trim() function is missing
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
58 GROUP BY round(julianday(start_time))
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
59 UNION
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
60 SELECT date(start_time), strftime('%s', stop_time) - strftime('%s', start_time), description
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
61 FROM entries
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
62 WHERE
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
63 project_id = :project_id AND
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
64 description IS NOT NULL AND length(description) > 0
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
65 '''
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 def human_time(s):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
68 s_h = s % 3600
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
69 h = s / 3600
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
70 m = s_h / 60
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
71 if (s_h % 60) >= 30:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
72 m += 1
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
73 if m == 60:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
74 m = 0
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
75 h += 1
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
76 return "%2d:%02d" % (h, m)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
77
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
78 class TermError(Exception):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
79
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
80 def __init__(self, msg):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
81 Exception.__init__(self)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
82 self.msg = msg
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
83
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
84 def __str__(self):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
85 return repr(self.msg)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
86
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
87 def tolerantClose(c):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
88 if c:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
89 try: c.close()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
90 except: pass
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
91
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
92 def usage(exit_code = 0):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
93 print USAGE % sys.argv[0]
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
94 sys.exit(exit_code)
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 def main():
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
97
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
98 database = DEFAULT_DATABASE
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
99 user = None
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
100 list_projects = False
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
101 project = None
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
102
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
103 opts, args = getopt.getopt(
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
104 sys.argv[1:],
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
105 'd:u:p:hl',
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
106 ['database=', 'user=', 'project', 'help', 'list'])
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
107
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
108 for opt, val in opts:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
109 if opt in ("--database", "-d"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
110 database = val
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
111 elif opt in ("--user", "-u"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
112 user = val
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
113 elif opt in ("--project", "-p"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
114 project = val
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
115 elif opt in ("--help", "-h"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
116 usage()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
117 elif opt in ("--list", "-l"):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
118 list_projects = True
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
119
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
120 if not user:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
121 user = os.getenv("USER")
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
122
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
123 if not os.path.isfile(database):
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
124 print >> sys.stderr, "'%s' does not exist or is not a file." % database
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
125 sys.exit(1)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
126
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
127 con, cur = None, None
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
128 try:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
129 try:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
130 con = db.connect(database)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
131 cur = con.cursor()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
132
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
133 if list_projects:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
134 cur.execute(LIST_PROJECTS)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
135 while True:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
136 row = cur.fetchone()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
137 if not row: break
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
138 print "%s %s %s" % (row[0], row[2] and "*" or "-", row[1])
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
139 else:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
140 if project:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
141 cur.execute(PROJECT_ID_BY_KEY, { 'key': project })
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
142 row = cur.fetchone()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
143 if row is None:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
144 raise TermError("There is no project with key '%s'" % project)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
145 project_ids = [[row[0], project]]
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
146 else:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
147 cur.execute(ALL_PROJECT_IDS);
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
148 project_ids = cur.fetchall()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
149
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
150 for project_id, project in project_ids:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
151 print "# project: %s" % project
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
152 cur.execute(ENTRIES, {'project_id': project_id})
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
153 total = 0
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
154 while True:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
155 row = cur.fetchone()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
156 if not row: break
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
157 d = date(*map(int, row[0].split('-')))
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
158 t = max(60, row[1])
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
159 c = row[2]
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
160 total += t
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
161 workpackage = "----"
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
162 if c:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
163 m = WORKPACKAGE.match(c)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
164 if m:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
165 workpackage = m.group(1)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
166 c = c[m.end():].strip()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
167 print "%s %sh %s %3s [%s] %s" % (
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
168 d.strftime("%d.%m.%Y"),
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
169 human_time(t),
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
170 TYPE_OF_ENTRY,
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
171 user,
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
172 workpackage,
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
173 c)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
174 print "# total: %sh" % human_time(total)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
175 finally:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
176 tolerantClose(cur)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
177 tolerantClose(con)
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
178
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
179 except TermError, e:
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
180 print >> sys.stderr, "error: %s" % e.msg
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
181
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
182 if __name__ == '__main__':
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
183 main()
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
184
20414d892f04 Added script to generate lines for zeiterfassung.txt
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
185 # 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)