Преглед на файлове

Fixed GUI crash when a fatal error occurs by calling the init() function of the temporal database

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58673 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert преди 11 години
родител
ревизия
55577880be
променени са 3 файла, в които са добавени 28 реда и са изтрити 10 реда
  1. 14 4
      gui/wxpython/gui_core/gselect.py
  2. 1 1
      gui/wxpython/timeline/frame.py
  3. 13 5
      lib/python/temporal/core.py

+ 14 - 4
gui/wxpython/gui_core/gselect.py

@@ -51,6 +51,8 @@ from core import globalvar
 
 
 import grass.script as grass
 import grass.script as grass
 from   grass.script import task as gtask
 from   grass.script import task as gtask
+from grass.pygrass import messages
+import grass.temporal as tgis
 
 
 from gui_core.widgets  import ManageSettingsWidget
 from gui_core.widgets  import ManageSettingsWidget
 
 
@@ -334,6 +336,7 @@ class TreeCtrlComboPopup(ListCtrlComboPopup):
         self.extraItems = dict()
         self.extraItems = dict()
         
         
         self.SetFilter(None)
         self.SetFilter(None)
+        self.tgis_error = False
     
     
     def SetFilter(self, filter):
     def SetFilter(self, filter):
         """!Set filter for GIS elements, see e.g. VectorSelect"""
         """!Set filter for GIS elements, see e.g. VectorSelect"""
@@ -441,8 +444,10 @@ class TreeCtrlComboPopup(ListCtrlComboPopup):
             return
             return
         
         
         if element in ('stds', 'strds', 'str3ds', 'stvds'):
         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:
         else:
             if globalvar.have_mlist:
             if globalvar.have_mlist:
                 filesdict = grass.mlist_grouped(elementdict[element],
                 filesdict = grass.mlist_grouped(elementdict[element],
@@ -662,8 +667,13 @@ class TreeCtrlComboPopup(ListCtrlComboPopup):
         if 'type' in kargs:
         if 'type' in kargs:
             self.type = kargs['type']
             self.type = kargs['type']
             if self.type in ('stds', 'strds', 'str3ds', 'stvds'):
             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:
         if 'mapsets' in kargs:
             self.mapsets = kargs['mapsets']
             self.mapsets = kargs['mapsets']
         if 'nmaps' in kargs:
         if 'nmaps' in kargs:

+ 1 - 1
gui/wxpython/timeline/frame.py

@@ -72,7 +72,7 @@ class TimelineFrame(wx.Frame):
     def __init__(self, parent):
     def __init__(self, parent):
         wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=_("Timeline Tool"))
         wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=_("Timeline Tool"))
 
 
-        tgis.init()
+        tgis.init(True)
         self.datasets = []
         self.datasets = []
         self.timeData = {}
         self.timeData = {}
         self._layout()
         self._layout()

+ 13 - 5
lib/python/temporal/core.py

@@ -267,7 +267,7 @@ def get_tgis_c_library_interface():
 raise_on_error = False
 raise_on_error = False
 
 
 def set_raise_on_error(raise_exp=True):
 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())
     interface (msgr.fatal())
     
     
     The messenger interface will be restarted using the new error policy
     The messenger interface will be restarted using the new error policy
@@ -406,7 +406,7 @@ atexit.register(stop_subprocesses)
 
 
 ###############################################################################
 ###############################################################################
 
 
-def init():
+def init(raise_fatal_error=False):
     """!This function set the correct database backend from GRASS environmental variables
     """!This function set the correct database backend from GRASS environmental variables
        and creates the grass temporal database structure for raster,
        and creates the grass temporal database structure for raster,
        vector and raster3d maps as well as for the space-time datasets strds,
        vector and raster3d maps as well as for the space-time datasets strds,
@@ -432,6 +432,13 @@ def init():
 
 
         ATTENTION: This functions must be called before any spatio-temporal processing
         ATTENTION: This functions must be called before any spatio-temporal processing
                    can be started
                    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
     # 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
     # from the GRASS mapset specific environment variables of g.gisenv and t.connect
@@ -445,13 +452,14 @@ def init():
     global current_mapset
     global current_mapset
     global current_location
     global current_location
     global current_gisdbase
     global current_gisdbase
+    
+    raise_on_error = raise_fatal_error
 
 
     # We must run t.connect at first to create the temporal database and to
     # We must run t.connect at first to create the temporal database and to
     # get the environmental variables
     # get the environmental variables
     core.run_command("t.connect", flags="c")
     core.run_command("t.connect", flags="c")
     kv = core.parse_command("t.connect", flags="pg")
     kv = core.parse_command("t.connect", flags="pg")
     grassenv = core.gisenv()
     grassenv = core.gisenv()
-    raise_on_error = False
 
 
     # Set the global variable for faster access
     # Set the global variable for faster access
     current_mapset = grassenv["MAPSET"]
     current_mapset = grassenv["MAPSET"]
@@ -459,7 +467,7 @@ def init():
     current_gisdbase = grassenv["GISDBASE"]
     current_gisdbase = grassenv["GISDBASE"]
 
 
     # Check environment variable GRASS_TGIS_RAISE_ON_ERROR
     # 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
         raise_on_error = True
 
 
     # Check if the script library raises on error, 
     # Check if the script library raises on error, 
@@ -472,7 +480,7 @@ def init():
     # Start the C-library interface server
     # Start the C-library interface server
     _init_tgis_c_library_interface()
     _init_tgis_c_library_interface()
     msgr = get_tgis_message_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
     # Set the mapset check and the timestamp write
     if grassenv.has_key("TGIS_DISABLE_MAPSET_CHECK"):
     if grassenv.has_key("TGIS_DISABLE_MAPSET_CHECK"):