[Getan-commits] [PATCH] Allow to set encoding in getan-eval

Wald Commits scm-commit at wald.intevation.org
Mon Mar 10 09:39:10 CET 2014


# HG changeset patch
# User Björn Ricks <bjoern.ricks at intevation.de>
# Date 1394440747 -3600
# Node ID 82a5dd0504362110c008ff0f0a6534d15bd458fb
# Parent  a805aaed97dd252a1f59eb14cbcca37ec3d3388a
Allow to set encoding in getan-eval

Per default the current locales encoding will be used if no encoding is set via
command line switch.

diff -r a805aaed97dd -r 82a5dd050436 getan/contrib/getan-eval.py
--- a/getan/contrib/getan-eval.py	Mon Mar 10 09:23:08 2014 +0100
+++ b/getan/contrib/getan-eval.py	Mon Mar 10 09:39:07 2014 +0100
@@ -6,6 +6,10 @@
 # This is Free Software licensed under the terms of GPLv3 or later.
 # For details see LICENSE coming with the source of 'getan'.
 
+import codecs
+import locale
+import sys
+
 from datetime import date, datetime, timedelta
 from optparse import OptionParser
 
@@ -30,6 +34,8 @@
     parser.add_option("-m", "--empty", dest="empty",
                       help="show projects without an entries",
                       action="store_true")
+    parser.add_option("--encoding", dest="encoding",
+                      help="encoding of output", metavar="ENCODING")
 
     (options, args) = parser.parse_args()
 
@@ -42,6 +48,12 @@
 
     template_name = options.template or "wochenbericht"
 
+    if not options.encoding:
+        encoding = locale.getdefaultlocale()[1]
+
+    Writer = codecs.getwriter(encoding)
+    sys.stdout = Writer(sys.stdout)
+
     print render(database=options.database, user=options.user,
                  template=template_name, year=year, week=week,
                  project=options.project, empty_projects=options.empty)


More information about the Getan-commits mailing list