comparison contrib/zeiterfassung @ 46:5f87604ea5ed

add year option for contrib/zeiterfassung default for year is the current year
author Bjoern Ricks <bricks@intevation.de>
date Mon, 07 Feb 2011 11:28:25 +0100
parents 22aa74768d97
children 3f97954868e4
comparison
equal deleted inserted replaced
44:f10126519797 46:5f87604ea5ed
55 sum(strftime('%s', stop_time) - strftime('%s', start_time)), 55 sum(strftime('%s', stop_time) - strftime('%s', start_time)),
56 'no description' AS description 56 'no description' AS description
57 FROM entries 57 FROM entries
58 WHERE 58 WHERE
59 project_id = :project_id AND 59 project_id = :project_id AND
60 (strftime('%Y', start_time) ) = :year AND
60 (description IS NULL or length(description) = 0) -- trim() function is missing 61 (description IS NULL or length(description) = 0) -- trim() function is missing
61 AND (strftime('%W', start_time) = :week OR strftime('%W', stop_time) = :week) 62 AND (strftime('%W', start_time) = :week OR strftime('%W', stop_time) = :week)
62 GROUP BY round(julianday(start_time)) 63 GROUP BY round(julianday(start_time))
63 UNION 64 UNION
64 SELECT date(start_time) AS s, strftime('%s', stop_time) - strftime('%s', start_time), description 65 SELECT date(start_time) AS s, strftime('%s', stop_time) - strftime('%s', start_time), description
65 FROM entries 66 FROM entries
66 WHERE 67 WHERE
67 project_id = :project_id AND 68 project_id = :project_id AND
69 (strftime('%Y', start_time) ) = :year AND
68 description IS NOT NULL AND length(description) > 0 70 description IS NOT NULL AND length(description) > 0
69 AND (strftime('%W', start_time) = :week OR strftime('%W', stop_time) = :week) 71 AND (strftime('%W', start_time) = :week OR strftime('%W', stop_time) = :week)
70 ORDER BY t 72 ORDER BY t
71 ''' 73 '''
72 74
83 UNION 85 UNION
84 SELECT date(start_time), strftime('%s', stop_time) - strftime('%s', start_time), description 86 SELECT date(start_time), strftime('%s', stop_time) - strftime('%s', start_time), description
85 FROM entries 87 FROM entries
86 WHERE 88 WHERE
87 project_id = :project_id AND 89 project_id = :project_id AND
90 (strftime('%Y', start_time) ) = :year AND
88 description IS NOT NULL AND length(description) > 0 91 description IS NOT NULL AND length(description) > 0
89 ''' 92 '''
90 93
91 def human_time(s): 94 def human_time(s):
92 h = s / 3600 95 h = s / 3600
122 user = None 125 user = None
123 list_projects = False 126 list_projects = False
124 project = None 127 project = None
125 encoding = None 128 encoding = None
126 week = None 129 week = None
130 year = None
127 131
128 opts, args = getopt.getopt( 132 opts, args = getopt.getopt(
129 sys.argv[1:], 133 sys.argv[1:],
130 'd:u:p:e:hl:w:', 134 'd:u:p:e:hl:w:',
131 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=']) 135 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=', 'year='])
132 136
133 for opt, val in opts: 137 for opt, val in opts:
134 if opt in ("--database", "-d"): 138 if opt in ("--database", "-d"):
135 database = val 139 database = val
136 elif opt in ("--user", "-u"): 140 elif opt in ("--user", "-u"):
143 usage() 147 usage()
144 elif opt in ("--list", "-l"): 148 elif opt in ("--list", "-l"):
145 list_projects = True 149 list_projects = True
146 elif opt in ("--week", "-w"): 150 elif opt in ("--week", "-w"):
147 week = val 151 week = val
152 elif opt in ("--year", "-y"):
153 year = val
148 154
149 if not user: 155 if not user:
150 user = os.getenv("USER") 156 user = os.getenv("USER")
157
158 if not year:
159 year = date.today().strftime("%Y")
151 160
152 if encoding: 161 if encoding:
153 Writer = codecs.getwriter(encoding) 162 Writer = codecs.getwriter(encoding)
154 sys.stdout = Writer(sys.stdout) 163 sys.stdout = Writer(sys.stdout)
155 164
183 project_ids = cur.fetchall() 192 project_ids = cur.fetchall()
184 193
185 for project_id, project, proj_desc in project_ids: 194 for project_id, project, proj_desc in project_ids:
186 print "# project: %s (%s)" % (project, proj_desc) 195 print "# project: %s (%s)" % (project, proj_desc)
187 if not week is None: 196 if not week is None:
188 cur.execute(WEEK_ENTRIES, {'project_id': project_id, 'week': week}) 197 cur.execute(WEEK_ENTRIES, {'project_id': project_id, 'week': week, 'year' : year})
189 else: 198 else:
190 cur.execute(ENTRIES, {'project_id': project_id}) 199 cur.execute(ENTRIES, {'project_id': project_id})
191 total = 0 200 total = 0
192 while True: 201 while True:
193 row = cur.fetchone() 202 row = cur.fetchone()
200 if c: 209 if c:
201 m = WORKPACKAGE.match(c) 210 m = WORKPACKAGE.match(c)
202 if m: 211 if m:
203 workpackage = m.group(1) 212 workpackage = m.group(1)
204 c = c[m.end():].strip() 213 c = c[m.end():].strip()
214 c = c.replace('\x1b', '')
205 print "%s %sh %s %-3s [%s] %s" % ( 215 print "%s %sh %s %-3s [%s] %s" % (
206 d.strftime("%d.%m.%Y"), 216 d.strftime("%d.%m.%Y"),
207 human_time(t), 217 human_time(t),
208 TYPE_OF_ENTRY, 218 TYPE_OF_ENTRY,
209 user, 219 user,
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)