# HG changeset patch # User Björn Ricks # Date 1300874668 -3600 # Node ID 3f97954868e48380ed0101f646535fd32bfc0730 # Parent 9dbb6ee443a4b8379aecce732d299acb5b011dc8 add year option to usage output add missing short option -y for --year make year switch optional for listing project depended entries diff -r 9dbb6ee443a4 -r 3f97954868e4 contrib/zeiterfassung --- a/contrib/zeiterfassung Fri Mar 18 16:30:56 2011 +0100 +++ b/contrib/zeiterfassung Wed Mar 23 11:04:28 2011 +0100 @@ -34,6 +34,7 @@ [--project=|-p ] : Key of output project, default: all [--encoding=|-e encoding] : encoding of output, default: none [--week=]|-w ] : week of year + [--year=]|-y ] : year [--list|-l] : list all projects [--help|-h] : This text''' @@ -87,6 +88,24 @@ FROM entries WHERE project_id = :project_id AND + description IS NOT NULL AND length(description) > 0 +''' + +ENTRIES_YEAR = ''' +SELECT + date(start_time), + sum(strftime('%s', stop_time) - strftime('%s', start_time)), + 'no description' AS description +FROM entries +WHERE + project_id = :project_id AND + (description IS NULL or length(description) = 0) -- trim() function is missing +GROUP BY round(julianday(start_time)) +UNION +SELECT date(start_time), strftime('%s', stop_time) - strftime('%s', start_time), description +FROM entries +WHERE + project_id = :project_id AND (strftime('%Y', start_time) ) = :year AND description IS NOT NULL AND length(description) > 0 ''' @@ -131,7 +150,7 @@ opts, args = getopt.getopt( sys.argv[1:], - 'd:u:p:e:hl:w:', + 'd:u:p:e:hl:w:y:', ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=', 'year=']) for opt, val in opts: @@ -155,8 +174,9 @@ if not user: user = os.getenv("USER") - if not year: - year = date.today().strftime("%Y") + proj_year = year + if not proj_year: + proj_year = date.today().strftime("%Y") if encoding: Writer = codecs.getwriter(encoding) @@ -194,9 +214,11 @@ for project_id, project, proj_desc in project_ids: print "# project: %s (%s)" % (project, proj_desc) if not week is None: - cur.execute(WEEK_ENTRIES, {'project_id': project_id, 'week': week, 'year' : year}) + cur.execute(WEEK_ENTRIES, {'project_id': project_id, 'week': week, 'year' : proj_year}) + elif not year: + cur.execute(ENTRIES, {'project_id': project_id}) else: - cur.execute(ENTRIES, {'project_id': project_id}) + cur.execute(ENTRIES_YEAR, {'project_id': project_id, 'year':proj_year}) total = 0 while True: row = cur.fetchone()