Parcourir la source

wxGUI: handle CalledModuleError coming from checking db connection in d.vect dialog (backport of https://trac.osgeo.org/grass/changeset/62691 which replaces https://trac.osgeo.org/grass/changeset/62614, https://trac.osgeo.org/grass/ticket/2326, https://trac.osgeo.org/grass/ticket/2474, author: annakrat)

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@62789 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras il y a 10 ans
Parent
commit
4a4dfd5001
1 fichiers modifiés avec 8 ajouts et 5 suppressions
  1. 8 5
      gui/wxpython/gui_core/gselect.py

+ 8 - 5
gui/wxpython/gui_core/gselect.py

@@ -52,6 +52,7 @@ from core import globalvar
 
 import grass.script as grass
 from   grass.script import task as gtask
+from grass.exceptions import CalledModuleError
 try:
     from grass.pygrass import messages
 except ImportError as e:
@@ -727,12 +728,14 @@ class VectorDBInfo:
 
     def _CheckDBConnection(self):
         """Check DB connection"""
-        # if map is not defined (happens with vnet initialization)
-        if not self.map:
-            return False
         nuldev = file(os.devnull, 'w+')
-        self.layers = grass.vector_db(map=self.map, stderr=nuldev)
-        nuldev.close()
+        # if map is not defined (happens with vnet initialization) or it doesn't exist
+        try:
+            self.layers = grass.vector_db(map=self.map, stderr=nuldev)
+        except CalledModuleError:
+            return False
+        finally:  # always close nuldev
+            nuldev.close()
 
         return bool(len(self.layers.keys()) > 0)