comparison contrib/zeiterfassung @ 13:e347f0de5e22

Applied Stephan Holl's week-option.patch
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 12 Aug 2008 10:14:59 +0200
parents feb6bb4427fe
children 22aa74768d97
comparison
equal deleted inserted replaced
12:2ccae1e872e9 13:e347f0de5e22
31 with <options> 31 with <options>
32 [--user=|-u <user>] : Name of user, default: $USER 32 [--user=|-u <user>] : Name of user, default: $USER
33 [--database=|-d <database>]: getan database, default: time.db 33 [--database=|-d <database>]: getan database, default: time.db
34 [--project=|-p <key>] : Key of output project, default: all 34 [--project=|-p <key>] : Key of output project, default: all
35 [--encoding=|-e encoding] : encoding of output, default: none 35 [--encoding=|-e encoding] : encoding of output, default: none
36 [--week=]|-w <week>] : week of year
36 [--list|-l] : list all projects 37 [--list|-l] : list all projects
37 [--help|-h] : This text''' 38 [--help|-h] : This text'''
38 39
39 LIST_PROJECTS = ''' 40 LIST_PROJECTS = '''
40 SELECT key, description, active FROM projects 41 SELECT key, description, active FROM projects
44 SELECT id, description FROM projects where key = :key 45 SELECT id, description FROM projects where key = :key
45 ''' 46 '''
46 47
47 ALL_PROJECT_IDS = ''' 48 ALL_PROJECT_IDS = '''
48 SELECT id, key, description FROM projects 49 SELECT id, key, description FROM projects
50 '''
51
52 WEEK_ENTRIES = '''
53 SELECT
54 date(start_time) AS t,
55 sum(strftime('%s', stop_time) - strftime('%s', start_time)),
56 'no description' AS description
57 FROM entries
58 WHERE
59 project_id = :project_id AND
60 (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 GROUP BY round(julianday(start_time))
63 UNION
64 SELECT date(start_time) AS s, strftime('%s', stop_time) - strftime('%s', start_time), description
65 FROM entries
66 WHERE
67 project_id = :project_id AND
68 description IS NOT NULL AND length(description) > 0
69 AND (strftime('%W', start_time) = :week OR strftime('%W', stop_time) = :week)
70 ORDER BY t
49 ''' 71 '''
50 72
51 ENTRIES = ''' 73 ENTRIES = '''
52 SELECT 74 SELECT
53 date(start_time), 75 date(start_time),
99 database = DEFAULT_DATABASE 121 database = DEFAULT_DATABASE
100 user = None 122 user = None
101 list_projects = False 123 list_projects = False
102 project = None 124 project = None
103 encoding = None 125 encoding = None
126 week = None
104 127
105 opts, args = getopt.getopt( 128 opts, args = getopt.getopt(
106 sys.argv[1:], 129 sys.argv[1:],
107 'd:u:p:e:hl', 130 'd:u:p:e:hl:w:',
108 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list']) 131 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list', 'week='])
109 132
110 for opt, val in opts: 133 for opt, val in opts:
111 if opt in ("--database", "-d"): 134 if opt in ("--database", "-d"):
112 database = val 135 database = val
113 elif opt in ("--user", "-u"): 136 elif opt in ("--user", "-u"):
118 encoding = val 141 encoding = val
119 elif opt in ("--help", "-h"): 142 elif opt in ("--help", "-h"):
120 usage() 143 usage()
121 elif opt in ("--list", "-l"): 144 elif opt in ("--list", "-l"):
122 list_projects = True 145 list_projects = True
146 elif opt in ("--week", "-w"):
147 week = val
123 148
124 if not user: 149 if not user:
125 user = os.getenv("USER") 150 user = os.getenv("USER")
126 151
127 if encoding: 152 if encoding:
157 cur.execute(ALL_PROJECT_IDS); 182 cur.execute(ALL_PROJECT_IDS);
158 project_ids = cur.fetchall() 183 project_ids = cur.fetchall()
159 184
160 for project_id, project, proj_desc in project_ids: 185 for project_id, project, proj_desc in project_ids:
161 print "# project: %s (%s)" % (project, proj_desc) 186 print "# project: %s (%s)" % (project, proj_desc)
162 cur.execute(ENTRIES, {'project_id': project_id}) 187 if not week is None:
188 cur.execute(WEEK_ENTRIES, {'project_id': project_id, 'week': week})
189 else:
190 cur.execute(ENTRIES, {'project_id': project_id})
163 total = 0 191 total = 0
164 while True: 192 while True:
165 row = cur.fetchone() 193 row = cur.fetchone()
166 if not row: break 194 if not row: break
167 d = date(*map(int, row[0].split('-'))) 195 d = date(*map(int, row[0].split('-')))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)