diff contrib/zeiterfassung @ 55:a3c0a4fc55fb project-tree

Introcuded a command line argument to skip printing empty projects.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 18 Apr 2011 09:05:42 +0200
parents 22aa74768d97
children
line wrap: on
line diff
--- 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>]       : 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)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)