[GRASS-SVN] r67609 - in grass/trunk: gui/wxpython/core lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 19 00:52:40 PST 2016


Author: martinl
Date: 2016-01-19 00:52:40 -0800 (Tue, 19 Jan 2016)
New Revision: 67609

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


Modified: grass/trunk/gui/wxpython/core/debug.py
===================================================================
--- grass/trunk/gui/wxpython/core/debug.py	2016-01-19 04:04:23 UTC (rev 67608)
+++ grass/trunk/gui/wxpython/core/debug.py	2016-01-19 08:52:40 UTC (rev 67609)
@@ -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/trunk/gui/wxpython/core/gconsole.py
===================================================================
--- grass/trunk/gui/wxpython/core/gconsole.py	2016-01-19 04:04:23 UTC (rev 67608)
+++ grass/trunk/gui/wxpython/core/gconsole.py	2016-01-19 08:52:40 UTC (rev 67609)
@@ -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/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py	2016-01-19 04:04:23 UTC (rev 67608)
+++ grass/trunk/lib/python/script/core.py	2016-01-19 08:52:40 UTC (rev 67609)
@@ -1525,13 +1525,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