Kaynağa Gözat

init: change gis_init return code

Previous return code was overlapping with Python when file is not found (e.g. not installed grass-gui).
In theory, it could be even handled separately, but the possible return/exit codes are unclear.


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65851 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 9 yıl önce
ebeveyn
işleme
31fd4b20a4
2 değiştirilmiş dosya ile 19 ekleme ve 8 silme
  1. 7 3
      gui/wxpython/gis_set.py
  2. 12 5
      lib/init/grass.py

+ 7 - 3
gui/wxpython/gis_set.py

@@ -45,6 +45,10 @@ sys.stderr = codecs.getwriter('utf8')(sys.stderr)
 
 
 
 
 class GRASSStartup(wx.Frame):
 class GRASSStartup(wx.Frame):
+    exit_success = 0
+    # 2 is file not found from python interpreter
+    exit_user_requested = 5
+
     """GRASS start-up screen"""
     """GRASS start-up screen"""
     def __init__(self, parent = None, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE):
     def __init__(self, parent = None, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE):
 
 
@@ -998,12 +1002,12 @@ class GRASSStartup(wx.Frame):
 
 
     def ExitSuccessfully(self):
     def ExitSuccessfully(self):
         self.Destroy()
         self.Destroy()
-        sys.exit(0)
+        sys.exit(self.exit_success)
 
 
     def OnExit(self, event):
     def OnExit(self, event):
         """'Exit' button clicked"""
         """'Exit' button clicked"""
         self.Destroy()
         self.Destroy()
-        sys.exit(2)
+        sys.exit(self.exit_user_requested)
 
 
     def OnHelp(self, event):
     def OnHelp(self, event):
         """'Help' button clicked"""
         """'Help' button clicked"""
@@ -1014,7 +1018,7 @@ class GRASSStartup(wx.Frame):
     def OnCloseWindow(self, event):
     def OnCloseWindow(self, event):
         """Close window event"""
         """Close window event"""
         event.Skip()
         event.Skip()
-        sys.exit(2)
+        sys.exit(self.exit_user_requested)
 
 
     def _nameValidationFailed(self, ctrl):
     def _nameValidationFailed(self, ctrl):
         message = _("Name <%(name)s> is not a valid name for location or mapset. "
         message = _("Name <%(name)s> is not a valid name for location or mapset. "

+ 12 - 5
lib/init/grass.py

@@ -941,17 +941,24 @@ def gui_startup(grass_gui):
     if grass_gui in ('wxpython', 'gtext'):
     if grass_gui in ('wxpython', 'gtext'):
         ret = call([os.getenv('GRASS_PYTHON'), wxpath("gis_set.py")])
         ret = call([os.getenv('GRASS_PYTHON'), wxpath("gis_set.py")])
 
 
+    # this if could be simplified to three branches (0, 5, rest)
+    # if there is no need to handle unknown code separately
     if ret == 0:
     if ret == 0:
         pass
         pass
-    elif ret == 1:
+    elif ret in [1, 2]:
+        # 1 probably error comming from gis_set.py
+        # 2 probably file not found from python interpreter
         # formerly we were starting in text mode instead, now we just fail
         # formerly we were starting in text mode instead, now we just fail
         # which is more straightforward for everybody
         # which is more straightforward for everybody
-        fatal(_("Error in GUI startup. If necessary, please "
-                "report this error to the GRASS developers.\n"
+        fatal(_("Error in GUI startup. See messages above (if any)"
+                " and if necessary, please"
+                " report this error to the GRASS developers.\n"
+                "On systems with package manager, make sure you have the right"
+                " GUI package, probably named grass-gui, installed.\n"
                 "To run GRASS GIS in text mode use the -text flag."))
                 "To run GRASS GIS in text mode use the -text flag."))
-    elif ret == 2:
+    elif ret == 5:  # defined in gui/wxpython/gis_set.py
         # User wants to exit from GRASS
         # User wants to exit from GRASS
-        message(_("Received EXIT message from GUI.\nGRASS is not started. Bye."))
+        message(_("Exit was requested in GUI.\nGRASS GIS will not start. Bye."))
         sys.exit(0)
         sys.exit(0)
     else:
     else:
         fatal(_("Invalid return code from GUI startup script.\n"
         fatal(_("Invalid return code from GUI startup script.\n"