[GRASS-SVN] r47370 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 3 08:48:09 EDT 2011


Author: martinl
Date: 2011-08-03 05:48:08 -0700 (Wed, 03 Aug 2011)
New Revision: 47370

Modified:
   grass/trunk/gui/wxpython/gui_modules/gcmd.py
   grass/trunk/gui/wxpython/gui_modules/goutput.py
   grass/trunk/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: fix encoding strings
      (merge r47368 from relbr64)


Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py	2011-08-03 12:42:05 UTC (rev 47369)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py	2011-08-03 12:48:08 UTC (rev 47370)
@@ -607,7 +607,7 @@
         ps.stdin = None
     
     Debug.msg(3, "gcmd.RunCommand(): decoding string")
-    stdout, stderr = map(lambda x: utils.DecodeString(x) if type(x) is types.StringType else x, ps.communicate())
+    stdout, stderr = map(utils.DecodeString, ps.communicate())
     
     ret = ps.returncode
     Debug.msg(1, "gcmd.RunCommand(): get return code %d" % ret)

Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-08-03 12:42:05 UTC (rev 47369)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-08-03 12:48:08 UTC (rev 47370)
@@ -26,6 +26,7 @@
 import threading
 import Queue
 import codecs
+import locale
 
 import wx
 import wx.stc
@@ -358,20 +359,20 @@
     
     def Redirect(self):
         """!Redirect stdout/stderr
-        
-        @return True redirected
-        @return False failed
         """
         if Debug.GetLevel() == 0 and int(grass.gisenv().get('DEBUG', 0)) == 0:
             # don't redirect when debugging is enabled
             sys.stdout = self.cmd_stdout
             sys.stderr = self.cmd_stderr
-            return True
         else:
-            sys.stdout = sys.__stdout__
-            sys.stderr = sys.__stderr__
-        return False
-
+            enc = locale.getdefaultlocale()[1]
+            if enc:
+                sys.stdout = codecs.getwriter(enc)(sys.__stdout__)
+                sys.stderr = codecs.getwriter(enc)(sys.__stderr__)
+            else:
+                sys.stdout = sys.__stdout__
+                sys.stderr = sys.__stderr__
+        
     def WriteLog(self, text, style = None, wrap = None,
                  switchPage = False):
         """!Generic method for writing log message in 

Modified: grass/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py	2011-08-03 12:42:05 UTC (rev 47369)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py	2011-08-03 12:48:08 UTC (rev 47370)
@@ -291,14 +291,14 @@
         Debug.msg(5, "utils.GetVectorNumberOfLayers(): vector map '%s' not found" % vector)
         return layers
     
-    ret = gcmd.RunCommand('v.db.connect',
-                          parent = parent,
-                          flags = 'g',
-                          read = True,
-                          map = fullname,
-                          fs = ';')
-        
-    if not ret:
+    ret, out, msg = gcmd.RunCommand('v.db.connect',
+                                    getErrorMsg = True,
+                                    read = True,
+                                    flags = 'g',
+                                    map = fullname,
+                                    fs = ';')
+    if ret != 0:
+        sys.stderr.write(_("Vector map <%s>: %s\n") % (fullname, msg))
         return layers
     else:
         Debug.msg(1, "GetVectorNumberOfLayers(): ret %s" % ret)
@@ -651,22 +651,20 @@
     return ret.splitlines()
 
 def DecodeString(string):
-    """!Return decoded string
+    """!Decode string using system encoding
     
-    String is decoded as unicode, on failure
-    are used system locales.
-
     @param string string to be decoded
     
     @return decoded string
     """
-    try:
-        return string.decode('utf-8')
-    except LookupError:
-        enc = locale.getdefaultlocale()[1]
-        if enc:
-            return string.decode(enc)
+    if not string:
+        return string
     
+    enc = locale.getdefaultlocale()[1]
+    if enc:
+        Debug.msg(5, "DecodeString(): enc=%s" % enc)
+        return string.decode(enc)
+    
     return string
 
 def EncodeString(string):
@@ -676,8 +674,11 @@
     
     @return encoded string
     """
+    if not string:
+        return string
     enc = locale.getdefaultlocale()[1]
     if enc:
+        Debug.msg(5, "EncodeString(): enc=%s" % enc)
         return string.encode(enc)
     
     return string



More information about the grass-commit mailing list