changeset 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
files ChangeLog contrib/zeiterfassung
diffstat 2 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Aug 03 15:52:21 2008 +0200
+++ b/ChangeLog	Sun Aug 03 16:11:21 2008 +0200
@@ -1,3 +1,8 @@
+2008-08-03	Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* contrib/zeiterfassung: Added parameter -e | --encoding=.
+	  This enables e.g. the output as latin1 with --encoding=latin1.
+
 2008-08-03	Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* contrib/zeiterfassung: Applied and completed Stephan Holl's
--- a/contrib/zeiterfassung	Sun Aug 03 15:52:21 2008 +0200
+++ b/contrib/zeiterfassung	Sun Aug 03 16:11:21 2008 +0200
@@ -15,6 +15,7 @@
 import sys
 import getopt
 import re
+import codecs
 
 from pysqlite2 import dbapi2 as db
 
@@ -31,6 +32,7 @@
     [--user=|-u <user>]        : Name of user,          default: $USER
     [--database=|-d <database>]: getan database,        default: time.db
     [--project=|-p <key>]      : Key of output project, default: all
+    [--encoding=|-e encoding]  : encoding of output,    default: none
     [--list|-l]                : list all projects
     [--help|-h]                : This text'''
 
@@ -99,11 +101,12 @@
     user          = None
     list_projects = False
     project       = None
+    encoding      = None
 
     opts, args = getopt.getopt(
         sys.argv[1:],
-        'd:u:p:hl',
-        ['database=', 'user=', 'project=', 'help', 'list'])
+        'd:u:p:e:hl',
+        ['database=', 'user=', 'project=', 'encoding=', 'help', 'list'])
 
     for opt, val in opts:
         if opt in ("--database", "-d"):
@@ -112,6 +115,8 @@
             user = val
         elif opt in ("--project", "-p"):
             project = val
+        elif opt in ("--encoding", "-e"):
+            encoding = val
         elif opt in ("--help", "-h"):
             usage()
         elif opt in ("--list", "-l"):
@@ -120,6 +125,10 @@
     if not user:
         user = os.getenv("USER")
 
+    if encoding:
+        Writer = codecs.getwriter(encoding)
+        sys.stdout = Writer(sys.stdout)
+
     if not os.path.isfile(database):
         print >> sys.stderr, "'%s' does not exist or is not a file." % database
         sys.exit(1)
@@ -164,7 +173,7 @@
                             if m:
                                 workpackage = m.group(1)
                                 c = c[m.end():].strip()
-                        print "%s %sh %s %3s [%s] %s" % (
+                        print u"%s %sh %s %3s [%s] %s" % (
                             d.strftime("%d.%m.%Y"),
                             human_time(t),
                             TYPE_OF_ENTRY,
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)