comparison contrib/zeiterfassung @ 9:4e8f5545256d

* Applied and completed Stephan Holl's zeiterfassung.bessere-lesbarkeit.patch * fixed small issue with --project= parameter.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 03 Aug 2008 15:52:21 +0200
parents 20414d892f04
children 4f782a05b4dc
comparison
equal deleted inserted replaced
8:20414d892f04 9:4e8f5545256d
26 26
27 WORKPACKAGE = re.compile("^\[(\w*)(\s|\])") 27 WORKPACKAGE = re.compile("^\[(\w*)(\s|\])")
28 28
29 USAGE = '''usage: %s <options> 29 USAGE = '''usage: %s <options>
30 with <options> 30 with <options>
31 [--user=|-u <user>] : Name of user, default: $USER 31 [--user=|-u <user>] : Name of user, default: $USER
32 [--database=|-d <database>]: getan database, default: time.db 32 [--database=|-d <database>]: getan database, default: time.db
33 [--project|-p] : Key of output project, default: all 33 [--project=|-p <key>] : Key of output project, default: all
34 [--list|-l] : list all projects 34 [--list|-l] : list all projects
35 [--help|-h] : This text''' 35 [--help|-h] : This text'''
36 36
37 LIST_PROJECTS = ''' 37 LIST_PROJECTS = '''
38 SELECT key, description, active FROM projects 38 SELECT key, description, active FROM projects
39 ''' 39 '''
40 40
41 PROJECT_ID_BY_KEY = ''' 41 PROJECT_ID_BY_KEY = '''
42 SELECT id FROM projects where key = :key 42 SELECT id, description FROM projects where key = :key
43 ''' 43 '''
44 44
45 ALL_PROJECT_IDS = ''' 45 ALL_PROJECT_IDS = '''
46 SELECT id, key FROM projects; 46 SELECT id, key, description FROM projects
47 ''' 47 '''
48 48
49 ENTRIES = ''' 49 ENTRIES = '''
50 SELECT 50 SELECT
51 date(start_time), 51 date(start_time),
101 project = None 101 project = None
102 102
103 opts, args = getopt.getopt( 103 opts, args = getopt.getopt(
104 sys.argv[1:], 104 sys.argv[1:],
105 'd:u:p:hl', 105 'd:u:p:hl',
106 ['database=', 'user=', 'project', 'help', 'list']) 106 ['database=', 'user=', 'project=', 'help', 'list'])
107 107
108 for opt, val in opts: 108 for opt, val in opts:
109 if opt in ("--database", "-d"): 109 if opt in ("--database", "-d"):
110 database = val 110 database = val
111 elif opt in ("--user", "-u"): 111 elif opt in ("--user", "-u"):
140 if project: 140 if project:
141 cur.execute(PROJECT_ID_BY_KEY, { 'key': project }) 141 cur.execute(PROJECT_ID_BY_KEY, { 'key': project })
142 row = cur.fetchone() 142 row = cur.fetchone()
143 if row is None: 143 if row is None:
144 raise TermError("There is no project with key '%s'" % project) 144 raise TermError("There is no project with key '%s'" % project)
145 project_ids = [[row[0], project]] 145 project_ids = [[row[0], project, row[1]]]
146 else: 146 else:
147 cur.execute(ALL_PROJECT_IDS); 147 cur.execute(ALL_PROJECT_IDS);
148 project_ids = cur.fetchall() 148 project_ids = cur.fetchall()
149 149
150 for project_id, project in project_ids: 150 for project_id, project, proj_desc in project_ids:
151 print "# project: %s" % project 151 print "# project: %s (%s)" % (project, proj_desc)
152 cur.execute(ENTRIES, {'project_id': project_id}) 152 cur.execute(ENTRIES, {'project_id': project_id})
153 total = 0 153 total = 0
154 while True: 154 while True:
155 row = cur.fetchone() 155 row = cur.fetchone()
156 if not row: break 156 if not row: break
169 human_time(t), 169 human_time(t),
170 TYPE_OF_ENTRY, 170 TYPE_OF_ENTRY,
171 user, 171 user,
172 workpackage, 172 workpackage,
173 c) 173 c)
174 print "# total: %sh" % human_time(total) 174 print "# total: %sh\n\n" % human_time(total)
175 finally: 175 finally:
176 tolerantClose(cur) 176 tolerantClose(cur)
177 tolerantClose(con) 177 tolerantClose(con)
178 178
179 except TermError, e: 179 except TermError, e:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)