comparison contrib/zeiterfassung @ 55:a3c0a4fc55fb project-tree

Introcuded a command line argument to skip printing empty projects.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 18 Apr 2011 09:05:42 +0200
parents 22aa74768d97
children
comparison
equal deleted inserted replaced
48:d2cc754b4dcd 55:a3c0a4fc55fb
33 [--database=|-d <database>]: getan database, default: time.db 33 [--database=|-d <database>]: getan database, default: time.db
34 [--project=|-p <key>] : Key of output project, default: all 34 [--project=|-p <key>] : Key of output project, default: all
35 [--encoding=|-e encoding] : encoding of output, default: none 35 [--encoding=|-e encoding] : encoding of output, default: none
36 [--week=]|-w <week>] : week of year 36 [--week=]|-w <week>] : week of year
37 [--list|-l] : list all projects 37 [--list|-l] : list all projects
38 [--skip|-s] : Don't list empty projects, default: False
38 [--help|-h] : This text''' 39 [--help|-h] : This text'''
39 40
40 LIST_PROJECTS = ''' 41 LIST_PROJECTS = '''
41 SELECT key, description, active FROM projects 42 SELECT key, description, active FROM projects
42 ''' 43 '''
122 user = None 123 user = None
123 list_projects = False 124 list_projects = False
124 project = None 125 project = None
125 encoding = None 126 encoding = None
126 week = None 127 week = None
128 skip_empty = False
127 129
128 opts, args = getopt.getopt( 130 opts, args = getopt.getopt(
129 sys.argv[1:], 131 sys.argv[1:],
130 'd:u:p:e:hl:w:', 132 'd:u:p:e:hl:w:s',
131 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=']) 133 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=', 'skip='])
132 134
133 for opt, val in opts: 135 for opt, val in opts:
134 if opt in ("--database", "-d"): 136 if opt in ("--database", "-d"):
135 database = val 137 database = val
136 elif opt in ("--user", "-u"): 138 elif opt in ("--user", "-u"):
143 usage() 145 usage()
144 elif opt in ("--list", "-l"): 146 elif opt in ("--list", "-l"):
145 list_projects = True 147 list_projects = True
146 elif opt in ("--week", "-w"): 148 elif opt in ("--week", "-w"):
147 week = val 149 week = val
150 elif opt in ("--skip", "-s"):
151 skip_empty = True
148 152
149 if not user: 153 if not user:
150 user = os.getenv("USER") 154 user = os.getenv("USER")
151 155
152 if encoding: 156 if encoding:
181 else: 185 else:
182 cur.execute(ALL_PROJECT_IDS); 186 cur.execute(ALL_PROJECT_IDS);
183 project_ids = cur.fetchall() 187 project_ids = cur.fetchall()
184 188
185 for project_id, project, proj_desc in project_ids: 189 for project_id, project, proj_desc in project_ids:
186 print "# project: %s (%s)" % (project, proj_desc)
187 if not week is None: 190 if not week is None:
188 cur.execute(WEEK_ENTRIES, {'project_id': project_id, 'week': week}) 191 cur.execute(WEEK_ENTRIES, {'project_id': project_id, 'week': week})
189 else: 192 else:
190 cur.execute(ENTRIES, {'project_id': project_id}) 193 cur.execute(ENTRIES, {'project_id': project_id})
191 total = 0 194 total = 0
195
196 header = False
197
192 while True: 198 while True:
193 row = cur.fetchone() 199 row = cur.fetchone()
200
201 if not header:
202 if row is not None or not skip_empty:
203 print "# project: %s (%s)" % (project, proj_desc)
204 header = True
205
194 if not row: break 206 if not row: break
195 d = date(*map(int, row[0].split('-'))) 207 d = date(*map(int, row[0].split('-')))
196 t = max(60, row[1]) 208 t = max(60, row[1])
197 c = row[2] 209 c = row[2]
198 total += t 210 total += t
207 human_time(t), 219 human_time(t),
208 TYPE_OF_ENTRY, 220 TYPE_OF_ENTRY,
209 user, 221 user,
210 workpackage, 222 workpackage,
211 c) 223 c)
212 print "# total: %sh\n\n" % human_time(total) 224 if total > 0 or not skip_empty:
225 print "# total: %sh\n\n" % human_time(total)
213 finally: 226 finally:
214 tolerantClose(cur) 227 tolerantClose(cur)
215 tolerantClose(con) 228 tolerantClose(con)
216 229
217 except TermError, e: 230 except TermError, e:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)