Mercurial > getan
comparison contrib/zeiterfassung @ 10:4f782a05b4dc
contrib/zeiterfassung: Added parameter -e | --encoding=
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 03 Aug 2008 16:11:21 +0200 |
parents | 4e8f5545256d |
children | feb6bb4427fe |
comparison
equal
deleted
inserted
replaced
9:4e8f5545256d | 10:4f782a05b4dc |
---|---|
13 import os | 13 import os |
14 import os.path | 14 import os.path |
15 import sys | 15 import sys |
16 import getopt | 16 import getopt |
17 import re | 17 import re |
18 import codecs | |
18 | 19 |
19 from pysqlite2 import dbapi2 as db | 20 from pysqlite2 import dbapi2 as db |
20 | 21 |
21 from datetime import date | 22 from datetime import date |
22 | 23 |
29 USAGE = '''usage: %s <options> | 30 USAGE = '''usage: %s <options> |
30 with <options> | 31 with <options> |
31 [--user=|-u <user>] : Name of user, default: $USER | 32 [--user=|-u <user>] : Name of user, default: $USER |
32 [--database=|-d <database>]: getan database, default: time.db | 33 [--database=|-d <database>]: getan database, default: time.db |
33 [--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 | |
34 [--list|-l] : list all projects | 36 [--list|-l] : list all projects |
35 [--help|-h] : This text''' | 37 [--help|-h] : This text''' |
36 | 38 |
37 LIST_PROJECTS = ''' | 39 LIST_PROJECTS = ''' |
38 SELECT key, description, active FROM projects | 40 SELECT key, description, active FROM projects |
97 | 99 |
98 database = DEFAULT_DATABASE | 100 database = DEFAULT_DATABASE |
99 user = None | 101 user = None |
100 list_projects = False | 102 list_projects = False |
101 project = None | 103 project = None |
104 encoding = None | |
102 | 105 |
103 opts, args = getopt.getopt( | 106 opts, args = getopt.getopt( |
104 sys.argv[1:], | 107 sys.argv[1:], |
105 'd:u:p:hl', | 108 'd:u:p:e:hl', |
106 ['database=', 'user=', 'project=', 'help', 'list']) | 109 ['database=', 'user=', 'project=', 'encoding=', 'help', 'list']) |
107 | 110 |
108 for opt, val in opts: | 111 for opt, val in opts: |
109 if opt in ("--database", "-d"): | 112 if opt in ("--database", "-d"): |
110 database = val | 113 database = val |
111 elif opt in ("--user", "-u"): | 114 elif opt in ("--user", "-u"): |
112 user = val | 115 user = val |
113 elif opt in ("--project", "-p"): | 116 elif opt in ("--project", "-p"): |
114 project = val | 117 project = val |
118 elif opt in ("--encoding", "-e"): | |
119 encoding = val | |
115 elif opt in ("--help", "-h"): | 120 elif opt in ("--help", "-h"): |
116 usage() | 121 usage() |
117 elif opt in ("--list", "-l"): | 122 elif opt in ("--list", "-l"): |
118 list_projects = True | 123 list_projects = True |
119 | 124 |
120 if not user: | 125 if not user: |
121 user = os.getenv("USER") | 126 user = os.getenv("USER") |
127 | |
128 if encoding: | |
129 Writer = codecs.getwriter(encoding) | |
130 sys.stdout = Writer(sys.stdout) | |
122 | 131 |
123 if not os.path.isfile(database): | 132 if not os.path.isfile(database): |
124 print >> sys.stderr, "'%s' does not exist or is not a file." % database | 133 print >> sys.stderr, "'%s' does not exist or is not a file." % database |
125 sys.exit(1) | 134 sys.exit(1) |
126 | 135 |
162 if c: | 171 if c: |
163 m = WORKPACKAGE.match(c) | 172 m = WORKPACKAGE.match(c) |
164 if m: | 173 if m: |
165 workpackage = m.group(1) | 174 workpackage = m.group(1) |
166 c = c[m.end():].strip() | 175 c = c[m.end():].strip() |
167 print "%s %sh %s %3s [%s] %s" % ( | 176 print u"%s %sh %s %3s [%s] %s" % ( |
168 d.strftime("%d.%m.%Y"), | 177 d.strftime("%d.%m.%Y"), |
169 human_time(t), | 178 human_time(t), |
170 TYPE_OF_ENTRY, | 179 TYPE_OF_ENTRY, |
171 user, | 180 user, |
172 workpackage, | 181 workpackage, |