浏览代码

wxGUI: attempt to catch error when getting interface description

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@50570 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 年之前
父节点
当前提交
b17e4c77ec
共有 5 个文件被更改,包括 18 次插入6 次删除
  1. 1 1
      gui/wxpython/core/gcmd.py
  2. 2 2
      gui/wxpython/gui_core/forms.py
  3. 7 1
      gui/wxpython/gui_core/goutput.py
  4. 2 2
      lib/python/core.py
  5. 6 0
      lib/python/task.py

+ 1 - 1
gui/wxpython/core/gcmd.py

@@ -140,7 +140,7 @@ class GException(Exception):
         self.value = value
 
     def __str__(self):
-        return str(self.value)
+        return self.value
 
 class Popen(subprocess.Popen):
     """!Subclass subprocess.Popen"""

+ 2 - 2
gui/wxpython/gui_core/forms.py

@@ -2010,8 +2010,8 @@ class GUI:
             global _blackList
             self.grass_task = gtask.parse_interface(gcmd.GetRealCmd(cmd[0]),
                                                     blackList = _blackList)
-        except (grass.ScriptError, ValueError), e: 
-            raise gcmd.GException(e.value)
+        except (grass.ScriptError, ValueError), e:
+            raise gcmd.GException(e)
         
         # if layer parameters previously set, re-insert them into dialog
         if completed is not None:

+ 7 - 1
gui/wxpython/gui_core/goutput.py

@@ -528,7 +528,13 @@ class GMConsole(wx.SplitterWindow):
             
             else:
                 # other GRASS commands (r|v|g|...)
-                task = GUI(show = None).ParseCommand(command)
+                try:
+                    task = GUI(show = None).ParseCommand(command)
+                except GException, e:
+                    GError(parent = self,
+                           message = unicode(e),
+                           showTraceback = False)
+                    return
                 
                 hasParams = False
                 if task:

+ 2 - 2
lib/python/core.py

@@ -61,9 +61,9 @@ STDOUT = subprocess.STDOUT
 class ScriptError(Exception):
     def __init__(self, msg):
         self.value = msg
-    
+        
     def __str__(self):
-        return repr(self.value)
+        return self.value
         
 raise_on_error = False # raise exception instead of calling fatal()
 debug_level = 0        # DEBUG level

+ 6 - 0
lib/python/task.py

@@ -433,6 +433,7 @@ def get_interface_description(cmd):
     try:
         cmdout, cmderr = Popen([cmd, '--interface-description'], stdout = PIPE,
                                stderr = PIPE).communicate()
+        
         # TODO: replace ugly hack bellow
         if not cmdout and sys.platform == 'win32':
             if os.path.splitext(cmd)[1] == '':
@@ -441,6 +442,11 @@ def get_interface_description(cmd):
             os.chdir(os.path.join(os.getenv('GISBASE'), 'scripts'))
             cmdout, cmderr = Popen([sys.executable, cmd, '--interface-description'], stdout = PIPE,
                                    stderr = PIPE).communicate()
+        
+        if cmderr:
+            raise ScriptError, _("Unable to fetch interface description for command '%(cmd)s'."
+                                 "\n\nDetails: %(det)s") % { 'cmd' : cmd, 'det' : decode(cmderr) }
+    
     except OSError, e:
         raise ScriptError, _("Unable to fetch interface description for command '%(cmd)s'."
                              "\n\nDetails: %(det)s") % { 'cmd' : cmd, 'det' : e }