]> SALOME platform Git repositories - tools/sat.git/blobdiff - src/debug.py
Salome HOME
restructuration fileEnviron, option --no_path_init pour sat launcher, gestion des...
[tools/sat.git] / src / debug.py
index 2023d8af738310d743bc46e1331ee0c3bd7d14f5..1f48125014162a65107b92d88c04d26e6ccc4fa0 100755 (executable)
@@ -54,19 +54,30 @@ Show pretty print debug representation from instances of SAT classes
 import os
 import sys
 import traceback
-import StringIO as SIO
 import pprint as PP
 
+# Compatibility python 2/3 for unicode
+try:
+    _test = unicode
+except:
+    unicode = str
+
+# Compatibility python 2/3 for StringIO
+try:
+    from StringIO import StringIO
+except ImportError:
+    from io import StringIO
+
 _debug = [False] #support push/pop for temporary activate debug outputs
 
 _user = os.environ['USER']
 # wambeke is christian at home
-_developpers = ["christian", "wambeke", "crouzet"] # crouzet, kloss ...
+_developers = ["christian", "wambeke"] # crouzet, kloss ...
 
 
-def isDevelopper():
-    """if you are a developper, sometimes you want verbose traces etc."""
-    res = _user in _developpers
+def isDeveloper():
+    """if you are a developer, sometimes you want verbose traces etc."""
+    res = _user in _developers
     return res
 
 def indent(text, amount=2, ch=' '):
@@ -107,8 +118,9 @@ def tofix(title, var="", force=None):
     write sys.stderr a message if _debug[-1]==True or optionaly force=True
     use this only if no logger accessible for classic logger.warning(message)
     """
-    fmt = "\n#### TOFIX: %s:\n%s\n"
-    write(title, var, force, fmt)
+    if _debug[-1] or isDeveloper():
+        fmt = "\n#### TOFIX: %s:\n%s\n"
+        write(title, var, force, fmt)
 
 def push_debug(aBool):
     """set debug outputs activated, or not"""
@@ -127,30 +139,25 @@ def format_exception(msg, limit=None, trace=None):
   """
   Format a stack trace and the exception information.
   as traceback.format_exception(), without color
-  with traceback only if (_debug) or (DBG._user in DBG._developpers)
+  with traceback only if (_debug) or (DBG._user in DBG._developers)
   """
   etype, value, tb = sys.exc_info()
-  if (_debug[-1]) or (_user in _developpers):
-    res = msg
-    if tb:
-      res += "\nTraceback (most recent call last):\n"
-      res += "".join(traceback.format_tb(tb, limit))  # [:-1])
-    res += "\n"
-    res += "\n".join(traceback.format_exception_only(etype, value))
-    return res
-  else:
-    res = msg
-    res += "".join(traceback.format_exception_only(etype, value))
-    return res
+  res = msg
+  if tb:
+    res += "\nTraceback (most recent call last):\n"
+    res += "".join(traceback.format_tb(tb, limit))  # [:-1])
+  res += "\n"
+  res += "\n".join(traceback.format_exception_only(etype, value))
+  return res
 
 def format_color_exception(msg, limit=None, trace=None):
   """
   Format a stack trace and the exception information.
   as traceback.format_exception(), with color
-  with traceback only if (_debug) or (DBG._user in DBG._developpers)
+  with traceback only if _debug or isDeveloper())
   """
   etype, value, tb = sys.exc_info()
-  if (_debug[-1]) or (_user in _developpers):
+  if _debug[-1] or isDeveloper():
     res = "<red>" + msg
     if tb:
       res += "<yellow>\nTraceback (most recent call last):\n"
@@ -168,7 +175,7 @@ def format_color_exception(msg, limit=None, trace=None):
 # utilitaires divers pour debug
 ###############################################
 
-class OutStream(SIO.StringIO):
+class OutStream(StringIO):
     """
     utility class for pyconf.Config output iostream
     """
@@ -178,9 +185,9 @@ class OutStream(SIO.StringIO):
       keep value before lost as self.value
       """
       self.value = self.getvalue()
-      SIO.StringIO.close(self)
+      StringIO.close(self)
     
-class InStream(SIO.StringIO):
+class InStream(StringIO):
     """utility class for pyconf.Config input iostream"""
     pass
 
@@ -234,7 +241,7 @@ def _saveConfigRecursiveDbg(config, aStream, indent, path, nb):
     
     indstr = indent * ' ' # '':no indent, ' ':indent
     strType = str(type(config))
-    if debug: print "saveDbg Type", path, strType
+    if debug: print("saveDbg Type %s %s" % (path, strType))
     
     if "Sequence" in strType:
       for i in range(len(config)):
@@ -259,7 +266,7 @@ def _saveConfigRecursiveDbg(config, aStream, indent, path, nb):
     for key in sorted(data): #order): # data as sort alphabetical, order as initial order
       value = data[key]
       strType = str(type(value))
-      if debug: print 'strType', path, key, strType
+      if debug: print('strType %s %s %s' % (path, key, strType))
       if "Config" in strType:
         _saveConfigRecursiveDbg(value, aStream, indentp, path+"."+key, nbp)
         continue