瀏覽代碼

wxGUI/r.in.wms: better error reporting (patch provided by Stepan Turek)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54970 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 年之前
父節點
當前提交
8838417e65
共有 3 個文件被更改,包括 50 次插入23 次删除
  1. 15 3
      gui/wxpython/web_services/dialogs.py
  2. 22 16
      gui/wxpython/web_services/widgets.py
  3. 13 4
      scripts/r.in.wms/wms_base.py

+ 15 - 3
gui/wxpython/web_services/dialogs.py

@@ -32,7 +32,7 @@ from core             import globalvar
 from core.debug       import Debug
 from core.ws          import RenderWMSMgr
 from core.events      import gUpdateMap
-from core.gcmd        import GMessage, RunCommand, GWarning
+from core.gcmd        import GMessage, GWarning, GError, RunCommand
 from core.utils       import GetSettingsPath, CmdToTuple, CmdTupleToList
 from core.gconsole    import CmdThread, GStderr, EVT_CMD_DONE, EVT_CMD_OUTPUT
 
@@ -75,6 +75,9 @@ class WSDialogBase(wx.Dialog):
         # buttons which are disabled when the dialog is not connected
         self.run_btns = []
 
+        # stores error messages for GError dialog showed when all web service connections were unsuccessful
+        self.error_msgs = ''
+
         self._createWidgets()
         self._doLayout()
 
@@ -372,9 +375,18 @@ class WSDialogBase(wx.Dialog):
         # how many web service panels are finished
         self.finished_panels_num +=  1
 
+        if event.error_msg:
+            self.error_msgs += '\n' + event.error_msg
+
         # if all are finished, show panels, which succeeded in connection
         if self.finished_panels_num == len(self.ws_panels):
             self.UpdateDialogAfterConnection()
+
+            # show error dialog only if connections to all web services were unsuccessful
+            if not self._getConnectedWS() and self.error_msgs:
+                GError(self.error_msgs, parent = self)
+            self.error_msgs = ''
+
             self.Layout()
             self.Fit()
 
@@ -464,7 +476,7 @@ class WSDialogBase(wx.Dialog):
         self.Fit()
 
 class AddWSDialog(WSDialogBase):
-    """!Show web service layer."""
+    """!Dialog for adding web service layer."""
     def __init__(self, parent, gmframe, id = wx.ID_ANY,
                  style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
 
@@ -548,7 +560,7 @@ class AddWSDialog(WSDialogBase):
                          params = None, propwin = prop_win)
 
 class WSPropertiesDialog(WSDialogBase):
-    """!Show web service property."""
+    """!Dialog for editing web service properties."""
     def __init__(self, parent, layer, ltree, ws_cap_files, cmd, id = wx.ID_ANY,
                  style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
         """

+ 22 - 16
gui/wxpython/web_services/widgets.py

@@ -35,7 +35,7 @@ from   wx.gizmos              import TreeListCtrl
 
 from core              import globalvar
 from core.debug        import Debug
-from core.gcmd         import GWarning, GMessage, GError
+from core.gcmd         import GWarning, GMessage
 from core.gconsole     import CmdThread, GStderr, EVT_CMD_DONE, EVT_CMD_OUTPUT
 
 from web_services.cap_interface import WMSCapabilities, WMTSCapabilities, OnEarthCapabilities
@@ -73,6 +73,9 @@ class WSPanel(wx.Panel):
 
         self.o_layer_name = ''
 
+        # stores err output from r.in.wms during getting capabilities
+        self.cmd_err_str = ''
+
         # stores selected layer from layer list
         self.sel_layers = []
 
@@ -425,12 +428,12 @@ class WSPanel(wx.Panel):
         self.cmd_thread.RunCmd(cap_cmd, stderr = self.cmdStdErr)
 
     def OnCmdOutput(self, event):
-        """!Print cmd output according to debug level.
-
-        @todo Replace with error dialog
+        """!Manage cmd output.
         """
         if Debug.GetLevel() != 0:
-            Debug.msg(1, event.text)
+          Debug.msg(1, event.text)
+        elif event.type != 'message' and event.type != 'warning':
+          self.cmd_err_str += event.text + os.linesep
 
     def _prepareForNewConn(self, url, username, password):
         """!Prepare panel for new connection
@@ -461,8 +464,11 @@ class WSPanel(wx.Panel):
             return
 
         if event.returncode != 0:
-            msg = "Downloading of capabilities file failed."
-            self._postCapParsedEvt(IOError(msg))
+            if self.cmd_err_str:
+                self.cmd_err_str = _("Unable to download %s capabilities file\nfrom <%s>:\n" %  \
+                                         (self.ws.replace('_', ' '), self.conn['url'])) + self.cmd_err_str
+            self._postCapParsedEvt(error_msg = self.cmd_err_str)
+            self.cmd_err_str = ''
             return
 
         self._parseCapFile(self.cap_file)
@@ -473,7 +479,13 @@ class WSPanel(wx.Panel):
         try:
             self.cap = self.ws_drvs[self.ws]['cap_parser'](cap_file)
         except (IOError, ParseError) as error:
-            self._postCapParsedEvt(error)
+            error_msg = _("%s web service was not found in fetched capabilities file from <%s>:\n%s\n" % \
+                        (self.ws, self.conn['url'], str(error)))
+            if Debug.GetLevel() != 0:
+              Debug.msg(1, error_msg)
+              self._postCapParsedEvt(None)
+            else:
+              self._postCapParsedEvt(error_msg = error_msg)
             return
 
         self.is_connected = True
@@ -576,16 +588,10 @@ class WSPanel(wx.Panel):
         """
         return self.is_connected
 
-    def _postCapParsedEvt(self, error):
+    def _postCapParsedEvt(self, error_msg):
         """!Helper function
         """
-        if error:
-            msg = "%s web service was not found in fetched capabilities from '%s'.\n%s\n" % \
-                  (self.ws, self.conn['url'], str(error))
-            Debug.msg(3, msg)
-
-        cap_parsed_event = wxOnCapParsed()
-        cap_parsed_event.SetEventObject(self)
+        cap_parsed_event = wxOnCapParsed(error_msg = error_msg)
         wx.PostEvent(self.receiver, cap_parsed_event)
 
     def CreateCmd(self):

+ 13 - 4
scripts/r.in.wms/wms_base.py

@@ -6,7 +6,7 @@ List of classes:
  - wms_base::GRASSImporter
  - wms_base::WMSDriversInfo
 
-(C) 2012 by the GRASS Development Team
+(C) 2012-2013 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.
@@ -195,9 +195,14 @@ class WMSBase:
             cap = self._fetchDataFromServer(cap_url, options['username'], options['password'])
         except (IOError, HTTPException), e:
             if urllib2.HTTPError == type(e) and e.code == 401:
-                grass.fatal(_("Authorization failed to '%s' when fetching capabilities.") % options['url'])
+                grass.fatal(_("Authorization failed to <%s> when fetching capabilities") % options['url'])
             else:
-                grass.fatal(_("Unable to fetch capabilities from: '%s'") % options['url'])
+                msg = _("Unable to fetch capabilities from <%s>") % (options['url'])
+                
+                if hasattr(e, 'reason'):
+                    msg += _("\nReason: ") + e.reason
+                
+                grass.fatal(msg)
         
         return cap
 
@@ -208,7 +213,11 @@ class WMSBase:
         if username and password:
                     base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
                     request.add_header("Authorization", "Basic %s" % base64string)
-        return urllib2.urlopen(request)
+        
+        try:
+            return urllib2.urlopen(request)
+        except ValueError as error:
+            grass.fatal("%s" % error)
 
     def GetCapabilities(self, options): 
         """!Get capabilities from WMS server