[GRASS-SVN] r54219 - in grass/trunk/gui/wxpython: core gmodeler

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 6 04:52:22 PST 2012


Author: martinl
Date: 2012-12-06 04:52:21 -0800 (Thu, 06 Dec 2012)
New Revision: 54219

Modified:
   grass/trunk/gui/wxpython/core/gcmd.py
   grass/trunk/gui/wxpython/core/utils.py
   grass/trunk/gui/wxpython/core/workspace.py
   grass/trunk/gui/wxpython/gmodeler/model.py
Log:
wxGUI: add GetDefaultEncoding
       fix writing workspace and model file


Modified: grass/trunk/gui/wxpython/core/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/core/gcmd.py	2012-12-06 12:29:07 UTC (rev 54218)
+++ grass/trunk/gui/wxpython/core/gcmd.py	2012-12-06 12:52:21 UTC (rev 54219)
@@ -14,6 +14,7 @@
 
 Functions:
  - RunCommand
+ - GetDefaultEncoding
 
 (C) 2007-2008, 2010-2011 by the GRASS Development Team
 
@@ -29,8 +30,8 @@
 import time
 import errno
 import signal
+import traceback
 import locale
-import traceback
 import subprocess
 if subprocess.mswindows:
     from win32file import ReadFile, WriteFile
@@ -67,13 +68,8 @@
     """
     if not string:
         return string
-
-    try:
-        enc = locale.getdefaultlocale()[1]
-    except ValueError, e:
-        sys.stderr.write(_("ERROR: %s\n") % str(e))
-        return string
     
+    enc = GetDefaultEncoding()
     if enc:
         Debug.msg(5, "DecodeString(): enc=%s" % enc)
         return string.decode(enc)
@@ -89,7 +85,8 @@
     """
     if not string:
         return string
-    enc = locale.getdefaultlocale()[1]
+    
+    enc = GetDefaultEncoding()
     if enc:
         Debug.msg(5, "EncodeString(): enc=%s" % enc)
         return string.encode(enc)
@@ -467,14 +464,13 @@
         """!Get error message or ''"""
         if not self.cmdThread.module:
             return _("Unable to exectute command: '%s'") % ' '.join(self.cmd)
-
+        
         for type, msg in self.__ProcessStdErr():
             if type == 'ERROR':
-                enc = locale.getdefaultlocale()[1]
+                enc = GetDefaultEncoding()
                 if enc:
                     return unicode(msg, enc)
-                else:
-                    return msg
+                return msg
         
         return ''
     
@@ -704,3 +700,17 @@
     
     Debug.msg(2, "gcmd.RunCommand(): return result")
     return stdout, _formatMsg(stderr)
+
+def GetDefaultEncoding(forceUTF8 = False):
+    """!Get default system encoding
+    
+    @param forceUTF8 return UTF8 when encoding is not defined
+
+    @return system encoding (can be None)
+    """
+    enc = locale.getdefaultlocale()[1]
+    if forceUTF8 and (enc is None or enc != 'UTF8'):
+        return 'UTF-8'
+    
+    Debug.msg(1, "GetSystemEncoding(): %s" % enc)
+    return enc

Modified: grass/trunk/gui/wxpython/core/utils.py
===================================================================
--- grass/trunk/gui/wxpython/core/utils.py	2012-12-06 12:29:07 UTC (rev 54218)
+++ grass/trunk/gui/wxpython/core/utils.py	2012-12-06 12:52:21 UTC (rev 54219)
@@ -3,7 +3,7 @@
 
 @brief Misc utilities for wxGUI
 
-(C) 2007-2009, 2011 by the GRASS Development Team
+(C) 2007-2009, 2011-2012 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.

Modified: grass/trunk/gui/wxpython/core/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/core/workspace.py	2012-12-06 12:29:07 UTC (rev 54218)
+++ grass/trunk/gui/wxpython/core/workspace.py	2012-12-06 12:52:21 UTC (rev 54219)
@@ -17,13 +17,12 @@
 """
 
 import os
-import locale
 
 import wx
 
 from core.utils     import normalize_whitespace
 from core.settings  import UserSettings
-from core.gcmd      import EncodeString
+from core.gcmd      import EncodeString, GetDefaultEncoding
 from nviz.main      import NvizSettings
 
 class ProcessWorkspaceFile:
@@ -562,8 +561,8 @@
         self.indent = 0
         
         # write header
-        enc = locale.getdefaultlocale()[1]
-        self.file.write('<?xml version="1.0" encoding="%s"?>\n' % enc)
+
+        self.file.write('<?xml version="1.0" encoding="%s"?>\n' % GetDefaultEncoding(forceUTF8 = True))
         self.file.write('<!DOCTYPE gxw SYSTEM "grass-gxw.dtd">\n')
         self.file.write('%s<gxw>\n' % (' ' * self.indent))
         

Modified: grass/trunk/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/model.py	2012-12-06 12:29:07 UTC (rev 54218)
+++ grass/trunk/gui/wxpython/gmodeler/model.py	2012-12-06 12:52:21 UTC (rev 54219)
@@ -31,7 +31,6 @@
 import re
 import mimetypes
 import time
-import locale
 try:
     import xml.etree.ElementTree as etree
 except ImportError:
@@ -42,7 +41,7 @@
 
 from core                import globalvar
 from core                import utils
-from core.gcmd           import GMessage, GException, GError, RunCommand, EncodeString, GWarning
+from core.gcmd           import GMessage, GException, GError, RunCommand, EncodeString, GWarning, GetDefaultEncoding
 from core.settings       import UserSettings
 from gui_core.forms      import GUI, CmdPanel
 from gui_core.widgets    import GNotebook
@@ -1779,8 +1778,7 @@
         
     def _header(self):
         """!Write header"""
-        enc = locale.getdefaultlocale()[1]
-        self.fd.write('<?xml version="1.0" encoding="%s"?>\n' % enc)
+        self.fd.write('<?xml version="1.0" encoding="%s"?>\n' % GetDefaultEncoding(forceUTF8 = True))
         self.fd.write('<!DOCTYPE gxm SYSTEM "grass-gxm.dtd">\n')
         self.fd.write('%s<gxm>\n' % (' ' * self.indent))
         self.indent += 4



More information about the grass-commit mailing list