# HG changeset patch # User Ingo Weinzierl # Date 1303110342 -7200 # Node ID a3c0a4fc55fbc97d200cb75ad896f832531a1b2b # Parent d2cc754b4dcda064a590f0e136900a616f49ec95 Introcuded a command line argument to skip printing empty projects. diff -r d2cc754b4dcd -r a3c0a4fc55fb ChangeLog --- a/ChangeLog Mon Feb 28 19:32:40 2011 +0100 +++ b/ChangeLog Mon Apr 18 09:05:42 2011 +0200 @@ -1,3 +1,9 @@ +2011-04-18 Ingo Weinzierl + + * contrib/zeiterfassung: Introcuded a new command line argument + "--skip|-s" to skip printing projects that have no entry for the + specified time range. + 2011-02-28 Ingo Weinzierl * getan/states.py: Bugfix: Projects with children are no longer selectable diff -r d2cc754b4dcd -r a3c0a4fc55fb contrib/zeiterfassung --- a/contrib/zeiterfassung Mon Feb 28 19:32:40 2011 +0100 +++ b/contrib/zeiterfassung Mon Apr 18 09:05:42 2011 +0200 @@ -35,6 +35,7 @@ [--encoding=|-e encoding] : encoding of output, default: none [--week=]|-w ] : week of year [--list|-l] : list all projects + [--skip|-s] : Don't list empty projects, default: False [--help|-h] : This text''' LIST_PROJECTS = ''' @@ -124,11 +125,12 @@ project = None encoding = None week = None + skip_empty = False opts, args = getopt.getopt( sys.argv[1:], - 'd:u:p:e:hl:w:', - ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=']) + 'd:u:p:e:hl:w:s', + ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week=', 'skip=']) for opt, val in opts: if opt in ("--database", "-d"): @@ -145,6 +147,8 @@ list_projects = True elif opt in ("--week", "-w"): week = val + elif opt in ("--skip", "-s"): + skip_empty = True if not user: user = os.getenv("USER") @@ -183,14 +187,22 @@ project_ids = cur.fetchall() 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}) else: cur.execute(ENTRIES, {'project_id': project_id}) total = 0 + + header = False + while True: row = cur.fetchone() + + if not header: + if row is not None or not skip_empty: + print "# project: %s (%s)" % (project, proj_desc) + header = True + if not row: break d = date(*map(int, row[0].split('-'))) t = max(60, row[1]) @@ -209,7 +221,8 @@ user, workpackage, c) - print "# total: %sh\n\n" % human_time(total) + if total > 0 or not skip_empty: + print "# total: %sh\n\n" % human_time(total) finally: tolerantClose(cur) tolerantClose(con)