comparison contrib/zeiterfassung @ 51:3f97954868e4

add year option to usage output add missing short option -y for --year make year switch optional for listing project depended entries
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 23 Mar 2011 11:04:28 +0100
parents 5f87604ea5ed
children 2f9093b41c5b
comparison
equal deleted inserted replaced
50:9dbb6ee443a4 51:3f97954868e4
32 [--user=|-u <user>] : Name of user, default: $USER 32 [--user=|-u <user>] : Name of user, default: $USER
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 [--year=]|-y <year>] : year
37 [--list|-l] : list all projects 38 [--list|-l] : list all projects
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
71 AND (strftime('%W', start_time) = :week OR strftime('%W', stop_time) = :week) 72 AND (strftime('%W', start_time) = :week OR strftime('%W', stop_time) = :week)
72 ORDER BY t 73 ORDER BY t
73 ''' 74 '''
74 75
75 ENTRIES = ''' 76 ENTRIES = '''
77 SELECT
78 date(start_time),
79 sum(strftime('%s', stop_time) - strftime('%s', start_time)),
80 'no description' AS description
81 FROM entries
82 WHERE
83 project_id = :project_id AND
84 (description IS NULL or length(description) = 0) -- trim() function is missing
85 GROUP BY round(julianday(start_time))
86 UNION
87 SELECT date(start_time), strftime('%s', stop_time) - strftime('%s', start_time), description
88 FROM entries
89 WHERE
90 project_id = :project_id AND
91 description IS NOT NULL AND length(description) > 0
92 '''
93
94 ENTRIES_YEAR = '''
76 SELECT 95 SELECT
77 date(start_time), 96 date(start_time),
78 sum(strftime('%s', stop_time) - strftime('%s', start_time)), 97 sum(strftime('%s', stop_time) - strftime('%s', start_time)),
79 'no description' AS description 98 'no description' AS description
80 FROM entries 99 FROM entries
129 week = None 148 week = None
130 year = None 149 year = None
131 150
132 opts, args = getopt.getopt( 151 opts, args = getopt.getopt(
133 sys.argv[1:], 152 sys.argv[1:],
134 'd:u:p:e:hl:w:', 153 'd:u:p:e:hl:w:y:',
135 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=', 'year=']) 154 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=', 'year='])
136 155
137 for opt, val in opts: 156 for opt, val in opts:
138 if opt in ("--database", "-d"): 157 if opt in ("--database", "-d"):
139 database = val 158 database = val
153 year = val 172 year = val
154 173
155 if not user: 174 if not user:
156 user = os.getenv("USER") 175 user = os.getenv("USER")
157 176
158 if not year: 177 proj_year = year
159 year = date.today().strftime("%Y") 178 if not proj_year:
179 proj_year = date.today().strftime("%Y")
160 180
161 if encoding: 181 if encoding:
162 Writer = codecs.getwriter(encoding) 182 Writer = codecs.getwriter(encoding)
163 sys.stdout = Writer(sys.stdout) 183 sys.stdout = Writer(sys.stdout)
164 184
192 project_ids = cur.fetchall() 212 project_ids = cur.fetchall()
193 213
194 for project_id, project, proj_desc in project_ids: 214 for project_id, project, proj_desc in project_ids:
195 print "# project: %s (%s)" % (project, proj_desc) 215 print "# project: %s (%s)" % (project, proj_desc)
196 if not week is None: 216 if not week is None:
197 cur.execute(WEEK_ENTRIES, {'project_id': project_id, 'week': week, 'year' : year}) 217 cur.execute(WEEK_ENTRIES, {'project_id': project_id, 'week': week, 'year' : proj_year})
218 elif not year:
219 cur.execute(ENTRIES, {'project_id': project_id})
198 else: 220 else:
199 cur.execute(ENTRIES, {'project_id': project_id}) 221 cur.execute(ENTRIES_YEAR, {'project_id': project_id, 'year':proj_year})
200 total = 0 222 total = 0
201 while True: 223 while True:
202 row = cur.fetchone() 224 row = cur.fetchone()
203 if not row: break 225 if not row: break
204 d = date(*map(int, row[0].split('-'))) 226 d = date(*map(int, row[0].split('-')))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)