From 37c9bcdb5626d33f1d5f5b6b66b9103ebdc044e6 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Thu, 4 Sep 2008 00:44:26 +0000 Subject: [PATCH] display instance variables one level deep --- direct/src/showbase/ExceptionVarDump.py | 23 ++++++++++++++++++----- direct/src/showbase/PythonUtil.py | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/direct/src/showbase/ExceptionVarDump.py b/direct/src/showbase/ExceptionVarDump.py index 82a49998f6..07339afd44 100755 --- a/direct/src/showbase/ExceptionVarDump.py +++ b/direct/src/showbase/ExceptionVarDump.py @@ -60,19 +60,23 @@ def _varDump__print(exc): sReentry -= 1 oldExcepthook = None -# store these values here so that Task.py can always reliably access these values +# store these values here so that Task.py can always reliably access them # from its main exception handler wantVariableDump = False dumpOnExceptionInit = False -def _excepthookDumpVars(eType, eValue, traceback): +class _AttrNotFound: + pass + +def _excepthookDumpVars(eType, eValue, tb): s = 'DUMPING STACK FRAME VARIABLES' - tb = traceback + origTb = tb #import pdb;pdb.set_trace() foundRun = False while tb is not None: frame = tb.tb_frame code = frame.f_code + names = code.co_names tb = tb.tb_next # skip everything before the 'run' method, those frames have lots of # not-useful information @@ -84,13 +88,22 @@ def _excepthookDumpVars(eType, eValue, traceback): s += '\n File "%s", line %s, in %s' % ( code.co_filename, frame.f_lineno, code.co_name) for name, val in frame.f_locals.iteritems(): - r = fastRepr(val) + r = fastRepr(val, maxLen=10) if type(r) is types.StringType: r = r.replace('\n', '\\n') s += '\n %s=%s' % (name, r) + # check if we should display any immediate attributes of the object + for n in names: + a = getattr(val, n, _AttrNotFound) + if a is not _AttrNotFound: + r = fastRepr(a, maxLen=10) + if type(r) is types.StringType: + r = r.replace('\n', '\\n') + s += '\n %s.%s=%s' % (name, n, r) + s += '\n' notify.info(s) - oldExcepthook(eType, eValue, traceback) + oldExcepthook(eType, eValue, origTb) def install(): global oldExcepthook diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index fca55e29d2..c72326cc63 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -2321,6 +2321,7 @@ def fastRepr(obj, maxLen=200, strFactor=10, _visitedIds=None): return safeRepr(obj) else: r = safeRepr(obj) + maxLen *= strFactor if len(r) > maxLen: r = r[:maxLen] return r