import sys
import traceback
import pprint as PP
+import inspect
+import src
# Compatibility python 2/3 for unicode
try:
_debug = [False] #support push/pop for temporary activate debug outputs
-_user = os.environ['USER']
-# wambeke is christian at home
-_developers = ["christian", "wambeke"] # crouzet, kloss ...
-
def isDeveloper():
- """if you are a developer, sometimes you want verbose traces etc."""
- res = _user in _developers
- return res
+ """
+ if you are a developer, sometimes you want verbose traces unconditionally
+ export SAT_DEVELOPER_MODE=1 before launch sat command to do that
+ """
+ res = os.getenv("SAT_DEVELOPER_MODE", "0")
+ if res in "YES yes 1 Y y".split():
+ return True
+ else:
+ return False
def indent(text, amount=2, ch=' '):
"""indent multi lines message"""
# print "NOT isTypeConfig %s" % typ
return False
-def write(title, var="", force=None, fmt="\n#### DEBUG: %s:\n%s\n"):
+def write(title, var="", force=None, fmt=" %s:\n%s\n####\n"):
"""write sys.stderr a message if _debug[-1]==True or optionaly force=True"""
if _debug[-1] or force:
+ callerframerecord = inspect.stack()[1] # get info of the caller
+ frame = callerframerecord[0]
+ info = inspect.getframeinfo(frame)
+ sys.stderr.write("\n#### DEBUG - %s:%s (%s) ####\n" % (info.filename, info.lineno, info.function))
tvar = type(var)
typ = str(tvar)
if isTypeConfig(var):
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():
+ callerframerecord = inspect.stack()[1] # get info of the caller
+ frame = callerframerecord[0]
+ info = inspect.getframeinfo(frame)
+ fmt = "#### TOFIX - " + str(info.filename) + ":" + str(info.lineno) +\
+ " (" + str(info.function) + ") ####\n %s:\n%s\n"
+ write(title, var, force, fmt)
def push_debug(aBool):
"""set debug outputs activated, or not"""
"""
Format a stack trace and the exception information.
as traceback.format_exception(), without color
- with traceback only if (_debug) or (DBG._user in DBG._developers)
+ with traceback only if (_debug) or (DBG.isDeveloper())
"""
etype, value, tb = sys.exc_info()
res = msg
#evaluate = value.resolve(config)
aStream.write("<header>%s%s<reset> : %s <yellow>--> '%s'<reset>\n" % (indstr, path, config, str(config)))
except Exception as e:
- aStream.write("<header>%s%s<reset> : <red>!!! ERROR: %s !!!<reset>\n" % (indstr, path, e.message))
+ aStream.write("<header>%s%s<reset> : <red>!!! ERROR: %s !!!<reset>\n" % (indstr, path, str(e)))
return
'''
evaluate = value.evaluate(config)
aStream.write("%s%s.%s : %s --> '%s'\n" % (indstr, path, key, str(value), evaluate))
except Exception as e:
- aStream.write("%s%s.%s : !!! ERROR: %s !!!\n" % (indstr, path, key, e.message))
+ aStream.write("%s%s.%s : !!! ERROR: %s !!!\n" % (indstr, path, key, str(e)))
continue
if "Reference" in strType:
try:
evaluate = value.resolve(config)
aStream.write("%s%s.%s : %s --> '%s'\n" % (indstr, path, key, str(value), evaluate))
except Exception as e:
- aStream.write("%s%s.%s : !!! ERROR: %s !!!\n" % (indstr, path, key, e.message))
+ aStream.write("%s%s.%s : !!! ERROR: %s !!!\n" % (indstr, path, key, str(e)))
continue
if type(value) in [str, bool, int, type(None), unicode]:
aStream.write("%s%s.%s : '%s'\n" % (indstr, path, key, str(value)))
try:
aStream.write("!!! TODO fix that %s %s%s.%s : %s\n" % (type(value), indstr, path, key, str(value)))
except Exception as e:
- aStream.write("%s%s.%s : !!! %s\n" % (indstr, path, key, e.message))
+ aStream.write("%s%s.%s : !!! %s\n" % (indstr, path, key, str(e)))