Browse Source

display instance variables one level deep

Darren Ranalli 17 years ago
parent
commit
37c9bcdb56
2 changed files with 19 additions and 5 deletions
  1. 18 5
      direct/src/showbase/ExceptionVarDump.py
  2. 1 0
      direct/src/showbase/PythonUtil.py

+ 18 - 5
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

+ 1 - 0
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