[GRASS-SVN] r58673 - in grass/trunk: gui/wxpython/gui_core gui/wxpython/timeline lib/python/temporal

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 10 17:57:37 PST 2014


Author: huhabla
Date: 2014-01-10 17:57:36 -0800 (Fri, 10 Jan 2014)
New Revision: 58673

Modified:
   grass/trunk/gui/wxpython/gui_core/gselect.py
   grass/trunk/gui/wxpython/timeline/frame.py
   grass/trunk/lib/python/temporal/core.py
Log:
Fixed GUI crash when a fatal error occurs by calling the init() function of the temporal database


Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py	2014-01-10 23:21:39 UTC (rev 58672)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py	2014-01-11 01:57:36 UTC (rev 58673)
@@ -51,6 +51,8 @@
 
 import grass.script as grass
 from   grass.script import task as gtask
+from grass.pygrass import messages
+import grass.temporal as tgis
 
 from gui_core.widgets  import ManageSettingsWidget
 
@@ -334,6 +336,7 @@
         self.extraItems = dict()
         
         self.SetFilter(None)
+        self.tgis_error = False
     
     def SetFilter(self, filter):
         """!Set filter for GIS elements, see e.g. VectorSelect"""
@@ -441,8 +444,10 @@
             return
         
         if element in ('stds', 'strds', 'str3ds', 'stvds'):
-            import grass.temporal as tgis
-            filesdict = tgis.tlist_grouped(elementdict[element], element == 'stds')
+            if self.tgis_error is False:
+                filesdict = tgis.tlist_grouped(elementdict[element], element == 'stds')
+            else:
+                filesdict = None
         else:
             if globalvar.have_mlist:
                 filesdict = grass.mlist_grouped(elementdict[element],
@@ -662,8 +667,13 @@
         if 'type' in kargs:
             self.type = kargs['type']
             if self.type in ('stds', 'strds', 'str3ds', 'stvds'):
-                import grass.temporal as tgis
-                tgis.init()
+                # Initiate the temporal framework. Catch database error
+                # and set the error flag for the stds listing.
+                try:
+                    tgis.init(True)
+                except messages.FatalError, e:
+                    sys.stderr.write("Temporal GIS error:\n%s" % e)
+                    self.tgis_error = True
         if 'mapsets' in kargs:
             self.mapsets = kargs['mapsets']
         if 'nmaps' in kargs:

Modified: grass/trunk/gui/wxpython/timeline/frame.py
===================================================================
--- grass/trunk/gui/wxpython/timeline/frame.py	2014-01-10 23:21:39 UTC (rev 58672)
+++ grass/trunk/gui/wxpython/timeline/frame.py	2014-01-11 01:57:36 UTC (rev 58673)
@@ -72,7 +72,7 @@
     def __init__(self, parent):
         wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=_("Timeline Tool"))
 
-        tgis.init()
+        tgis.init(True)
         self.datasets = []
         self.timeData = {}
         self._layout()

Modified: grass/trunk/lib/python/temporal/core.py
===================================================================
--- grass/trunk/lib/python/temporal/core.py	2014-01-10 23:21:39 UTC (rev 58672)
+++ grass/trunk/lib/python/temporal/core.py	2014-01-11 01:57:36 UTC (rev 58673)
@@ -267,7 +267,7 @@
 raise_on_error = False
 
 def set_raise_on_error(raise_exp=True):
-    """!Define behaviour on fatal error, invoked using the tgis messenger
+    """!Define behavior on fatal error, invoked using the tgis messenger
     interface (msgr.fatal())
     
     The messenger interface will be restarted using the new error policy
@@ -406,7 +406,7 @@
 
 ###############################################################################
 
-def init():
+def init(raise_fatal_error=False):
     """!This function set the correct database backend from GRASS environmental variables
        and creates the grass temporal database structure for raster,
        vector and raster3d maps as well as for the space-time datasets strds,
@@ -432,6 +432,13 @@
 
         ATTENTION: This functions must be called before any spatio-temporal processing
                    can be started
+                   
+        @param raise_fatal_error Set this True to assure that the init() function 
+                                 does not kill a persistent process like the GUI.
+                                 
+                                 If set True a grass.pygrass.messages.FatalError 
+                                 exception will be raised in case a fatal error occurs 
+                                 in the init process, otherwise sys.exit(1) will be called.
     """
     # We need to set the correct database backend and several global variables
     # from the GRASS mapset specific environment variables of g.gisenv and t.connect
@@ -445,13 +452,14 @@
     global current_mapset
     global current_location
     global current_gisdbase
+    
+    raise_on_error = raise_fatal_error
 
     # We must run t.connect at first to create the temporal database and to
     # get the environmental variables
     core.run_command("t.connect", flags="c")
     kv = core.parse_command("t.connect", flags="pg")
     grassenv = core.gisenv()
-    raise_on_error = False
 
     # Set the global variable for faster access
     current_mapset = grassenv["MAPSET"]
@@ -459,7 +467,7 @@
     current_gisdbase = grassenv["GISDBASE"]
 
     # Check environment variable GRASS_TGIS_RAISE_ON_ERROR
-    if os.getenv("GRASS_TGIS_RAISE_ON_ERROR") is "True" or os.getenv("GRASS_TGIS_RAISE_ON_ERROR") is "1":
+    if os.getenv("GRASS_TGIS_RAISE_ON_ERROR") == "True" or os.getenv("GRASS_TGIS_RAISE_ON_ERROR") == "1":
         raise_on_error = True
 
     # Check if the script library raises on error, 
@@ -472,7 +480,7 @@
     # Start the C-library interface server
     _init_tgis_c_library_interface()
     msgr = get_tgis_message_interface()
-    msgr.debug(1, "Inititate the temporal database")
+    msgr.debug(1, "Initiate the temporal database")
 
     # Set the mapset check and the timestamp write
     if grassenv.has_key("TGIS_DISABLE_MAPSET_CHECK"):



More information about the grass-commit mailing list