Mercurial > getan
changeset 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 | 9dbb6ee443a4 |
children | 9cb57c37369a |
files | contrib/zeiterfassung |
diffstat | 1 files changed, 27 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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>] : Key of output project, default: all [--encoding=|-e encoding] : encoding of output, default: none [--week=]|-w <week>] : week of year + [--year=]|-y <year>] : 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()