[GRASS-SVN] r54970 - in grass/trunk: gui/wxpython/web_services scripts/r.in.wms
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 7 06:17:04 PST 2013
Author: martinl
Date: 2013-02-07 06:17:03 -0800 (Thu, 07 Feb 2013)
New Revision: 54970
Modified:
grass/trunk/gui/wxpython/web_services/dialogs.py
grass/trunk/gui/wxpython/web_services/widgets.py
grass/trunk/scripts/r.in.wms/wms_base.py
Log:
wxGUI/r.in.wms: better error reporting (patch provided by Stepan Turek)
Modified: grass/trunk/gui/wxpython/web_services/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/web_services/dialogs.py 2013-02-07 13:43:06 UTC (rev 54969)
+++ grass/trunk/gui/wxpython/web_services/dialogs.py 2013-02-07 14:17:03 UTC (rev 54970)
@@ -32,7 +32,7 @@
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 @@
# 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 @@
# 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 @@
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 @@
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):
"""
Modified: grass/trunk/gui/wxpython/web_services/widgets.py
===================================================================
--- grass/trunk/gui/wxpython/web_services/widgets.py 2013-02-07 13:43:06 UTC (rev 54969)
+++ grass/trunk/gui/wxpython/web_services/widgets.py 2013-02-07 14:17:03 UTC (rev 54970)
@@ -35,7 +35,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
"""
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):
Modified: grass/trunk/scripts/r.in.wms/wms_base.py
===================================================================
--- grass/trunk/scripts/r.in.wms/wms_base.py 2013-02-07 13:43:06 UTC (rev 54969)
+++ grass/trunk/scripts/r.in.wms/wms_base.py 2013-02-07 14:17:03 UTC (rev 54970)
@@ -6,7 +6,7 @@
- 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 @@
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 @@
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
More information about the grass-commit
mailing list