[GRASS-SVN] r54221 - in grass/branches/develbranch_6/gui/wxpython: core gmodeler

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 6 05:02:31 PST 2012


Author: martinl
Date: 2012-12-06 05:02:31 -0800 (Thu, 06 Dec 2012)
New Revision: 54221

Modified:
   grass/branches/develbranch_6/gui/wxpython/core/gcmd.py
   grass/branches/develbranch_6/gui/wxpython/core/utils.py
   grass/branches/develbranch_6/gui/wxpython/core/workspace.py
   grass/branches/develbranch_6/gui/wxpython/gmodeler/model.py
Log:
wxGUI: add GetDefaultEncoding
       fix writing workspace and model file
       (merge r54219 & r54220 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/core/gcmd.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/core/gcmd.py	2012-12-06 12:56:41 UTC (rev 54220)
+++ grass/branches/develbranch_6/gui/wxpython/core/gcmd.py	2012-12-06 13:02:31 UTC (rev 54221)
@@ -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 copy
 
 import wx
@@ -74,13 +75,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)
@@ -96,7 +92,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)
@@ -466,14 +463,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 ''
     
@@ -700,3 +696,17 @@
     
     Debug.msg(2, "gcmd.RunCommand(): return result")
     return stdout, _formatMsg(stderr)
+
+def GetDefaultEncoding(forceUTF8 = False):
+    """!Get default system encoding
+    
+    @param forceUTF8 force 'UTF-8' if 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/branches/develbranch_6/gui/wxpython/core/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/core/utils.py	2012-12-06 12:56:41 UTC (rev 54220)
+++ grass/branches/develbranch_6/gui/wxpython/core/utils.py	2012-12-06 13:02:31 UTC (rev 54221)
@@ -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/branches/develbranch_6/gui/wxpython/core/workspace.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/core/workspace.py	2012-12-06 12:56:41 UTC (rev 54220)
+++ grass/branches/develbranch_6/gui/wxpython/core/workspace.py	2012-12-06 13:02:31 UTC (rev 54221)
@@ -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:
@@ -536,8 +535,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/branches/develbranch_6/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gmodeler/model.py	2012-12-06 12:56:41 UTC (rev 54220)
+++ grass/branches/develbranch_6/gui/wxpython/gmodeler/model.py	2012-12-06 13:02:31 UTC (rev 54221)
@@ -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
@@ -1781,8 +1780,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