[GRASS-SVN] r67745 - in grass/branches/releasebranch_7_0: gui/wxpython/core lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 6 11:31:54 PST 2016


Author: martinl
Date: 2016-02-06 11:31:54 -0800 (Sat, 06 Feb 2016)
New Revision: 67745

Modified:
   grass/branches/releasebranch_7_0/gui/wxpython/core/debug.py
   grass/branches/releasebranch_7_0/gui/wxpython/core/gconsole.py
   grass/branches/releasebranch_7_0/lib/python/script/core.py
Log:
fix pythonlib and GUI when debug/wx_debug value is invalid (do not fail, just print warning message)
        (merge r67609 from trunk)


Modified: grass/branches/releasebranch_7_0/gui/wxpython/core/debug.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/core/debug.py	2016-02-06 18:10:33 UTC (rev 67744)
+++ grass/branches/releasebranch_7_0/gui/wxpython/core/debug.py	2016-02-06 19:31:54 UTC (rev 67745)
@@ -39,7 +39,13 @@
     def SetLevel(self):
         """Initialize gui debug level
         """
-        self.debuglevel = int(grass.gisenv().get('WX_DEBUG', 0))
+        try:
+            self.debuglevel = int(grass.gisenv().get('WX_DEBUG', 0))
+            if self.debuglevel < 0 or self.debuglevel > 5:
+                raise ValueError(_("Wx debug level {}.").format(self.debuglevel))
+        except ValueError as e:
+            self.debuglevel = 0
+            sys.stderr.write(_("WARNING: Ignoring unsupported wx debug level (must be >=0 and <=5). {}\n").format(e))
         
     def msg(self, level, message, *args):
         """Print debug message

Modified: grass/branches/releasebranch_7_0/gui/wxpython/core/gconsole.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/core/gconsole.py	2016-02-06 18:10:33 UTC (rev 67744)
+++ grass/branches/releasebranch_7_0/gui/wxpython/core/gconsole.py	2016-02-06 19:31:54 UTC (rev 67745)
@@ -381,7 +381,7 @@
     def Redirect(self):
         """Redirect stdout/stderr
         """
-        if Debug.GetLevel() == 0 and int(grass.gisenv().get('DEBUG', 0)) == 0:
+        if Debug.GetLevel() == 0 and grass.debug_level(force=True) == 0:
             # don't redirect when debugging is enabled
             sys.stdout = self.cmdStdOut
             sys.stderr = self.cmdStdErr

Modified: grass/branches/releasebranch_7_0/lib/python/script/core.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/core.py	2016-02-06 18:10:33 UTC (rev 67744)
+++ grass/branches/releasebranch_7_0/lib/python/script/core.py	2016-02-06 19:31:54 UTC (rev 67745)
@@ -1508,13 +1508,20 @@
 _debug_level = None
 
 
-def debug_level():
+def debug_level(force=False):
     global _debug_level
-    if _debug_level is not None:
+    if not force and _debug_level is not None:
         return _debug_level
     _debug_level = 0
     if find_program('g.gisenv', '--help'):
-        _debug_level = int(gisenv().get('DEBUG', 0))
+        try:
+            _debug_level = int(gisenv().get('DEBUG', 0))
+            if _debug_level < 0 or _debug_level > 5:
+                raise ValueError(_("Debug level {}").format(_debug_level))
+        except ValueError as e:
+            _debug_level = 0
+            sys.stderr.write(_("WARNING: Ignoring unsupported debug level (must be >=0 and <=5). {}\n").format(e))
+            
     return _debug_level
 
 



More information about the grass-commit mailing list