[GRASS-SVN] r62827 - in grass/branches/releasebranch_7_0: gui/wxpython/dbmgr gui/wxpython/mapdisp lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 19 19:33:49 PST 2014


Author: annakrat
Date: 2014-11-19 19:33:49 -0800 (Wed, 19 Nov 2014)
New Revision: 62827

Modified:
   grass/branches/releasebranch_7_0/gui/wxpython/dbmgr/vinfo.py
   grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/frame.py
   grass/branches/releasebranch_7_0/lib/python/script/vector.py
Log:
pythonlib/wxGUI: better error handling of vector_what (merge from trunk, r62826)

Modified: grass/branches/releasebranch_7_0/gui/wxpython/dbmgr/vinfo.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/dbmgr/vinfo.py	2014-11-20 03:32:50 UTC (rev 62826)
+++ grass/branches/releasebranch_7_0/gui/wxpython/dbmgr/vinfo.py	2014-11-20 03:33:49 UTC (rev 62827)
@@ -20,7 +20,7 @@
 import wx
 
 from gui_core.gselect import VectorDBInfo as VectorDBInfoBase
-from core.gcmd        import RunCommand
+from core.gcmd        import RunCommand, GError
 from core.settings    import UserSettings
 from core.utils import _
 import grass.script as grass
@@ -92,9 +92,14 @@
         line = None
         nselected = 0
 
-        data = grass.vector_what(map = self.map,
-                                 coord = (float(queryCoords[0]), float(queryCoords[1])),
-                                 distance = float(qdist))
+        try:
+            data = grass.vector_what(map=self.map,
+                                     coord=(float(queryCoords[0]), float(queryCoords[1])),
+                                     distance=float(qdist))
+        except grass.ScriptError:
+            GError(parent=None,
+                   message=_("Failed to query vector map <{map}>. "
+                             "Check database settings and topology.").format(map=self.map))
 
         if len(data) < 1 or all(('Table' not in record) for record in data):
             return None

Modified: grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/frame.py	2014-11-20 03:32:50 UTC (rev 62826)
+++ grass/branches/releasebranch_7_0/gui/wxpython/mapdisp/frame.py	2014-11-20 03:33:49 UTC (rev 62827)
@@ -868,8 +868,13 @@
             rastQuery = grass.raster_what(map=rast, coord=(east, north))
         if vect:
             encoding = UserSettings.Get(group='atm', key='encoding', subkey='value')
-            vectQuery = grass.vector_what(map=vect, coord=(east, north), distance=qdist,
-                                          encoding=encoding)
+            try:
+                vectQuery = grass.vector_what(map=vect, coord=(east, north), distance=qdist,
+                                              encoding=encoding)
+            except grass.ScriptError:
+                GError(parent=self,
+                       message=_("Failed to query vector map(s) <{maps}>. "
+                                 "Check database settings and topology.").format(maps=','.join(vect)))
         self._QueryMapDone()
         if 'Id' in vectQuery:
             self._queryHighlight(vectQuery)

Modified: grass/branches/releasebranch_7_0/lib/python/script/vector.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/vector.py	2014-11-20 03:32:50 UTC (rev 62826)
+++ grass/branches/releasebranch_7_0/lib/python/script/vector.py	2014-11-20 03:33:49 UTC (rev 62827)
@@ -24,6 +24,7 @@
 
 from utils import parse_key_val
 from core import *
+from grass.exceptions import CalledModuleError
 
 
 def vector_db(map, **args):
@@ -348,8 +349,11 @@
     if ttype:
         cmdParams['type'] = ','.join(ttype)
 
-    ret = read_command('v.what',
-                       **cmdParams).strip()
+    try:
+        ret = read_command('v.what',
+                           **cmdParams).strip()
+    except CalledModuleError, e:
+        raise ScriptError(e.msg)
 
     if "LC_ALL" in os.environ:
         os.environ["LC_ALL"] = locale
@@ -377,7 +381,10 @@
     if sys.version_info[0:2] > (2, 6):
         kwargs['object_pairs_hook'] = orderedDict
 
-    result = json.loads(ret, **kwargs)
+    try:
+        result = json.loads(ret, **kwargs)
+    except ValueError:
+        raise ScriptError(_("v.what output is not valid JSON format:\n {ret}").format(ret=ret))
 
     for vmap in result['Maps']:
         cats = vmap.pop('Categories', None)



More information about the grass-commit mailing list