Browse Source

better exception wrapping for __dev__ builtin in report()

Josh Wilson 19 years ago
parent
commit
804d0dde03
1 changed files with 54 additions and 53 deletions
  1. 54 53
      direct/src/showbase/PythonUtil.py

+ 54 - 53
direct/src/showbase/PythonUtil.py

@@ -2492,68 +2492,69 @@ class ClassTree:
 
 
 def report(types = [], notifyFunc = None, dConfigParam = []):
+    def decorator(f):
+        return f
     try:
-        def decorator(f):
-            __dev__
-            def wrap(*args,**kwargs):
-                aargs = args
-                kkwargs = kwargs
-                rArgs = [`x`+', ' for x in args] + [ x + ' = ' + '%s, ' % `y` for x,y in kwargs.items()]
-                
-                if not rArgs:
-                    rArgs = '()'
-                else:
-                    rArgs = '(' + reduce(str.__add__,rArgs)[:-2] + ')'
-
-                outStr = f.func_name + rArgs
-
-                if 'frameCount' in types:
-                    outStr = '%8d : %s' % (globalClock.getFrameCount(), outStr)
-
-                if 'timeStamp' in types:
-                    outStr = '%5.3f : %s' % (globalClock.getFrameTime(), outStr)
+        if not __dev__:
+            return decorator            
+    except NameError,e:
+        return decorator
 
-                if 'avLocation' in types:
-                    outStr = '%s : %s' % (outStr, str(localAvatar.getLocation()))
+    def decorator(f):
+        def wrap(*args,**kwargs):
+            aargs = args
+            kkwargs = kwargs
+            rArgs = [`x`+', ' for x in args] + [ x + ' = ' + '%s, ' % `y` for x,y in kwargs.items()]
+            
+            if not rArgs:
+                rArgs = '()'
+            else:
+                rArgs = '(' + reduce(str.__add__,rArgs)[:-2] + ')'
+                
+            outStr = f.func_name + rArgs
+            
+            if 'frameCount' in types:
+                outStr = '%8d : %s' % (globalClock.getFrameCount(), outStr)
+                
+            if 'timeStamp' in types:
+                outStr = '%5.3f : %s' % (globalClock.getFrameTime(), outStr)
 
-                # determine whether we should print
-                doPrint = False
-                if not dConfigParam:
-                    doPrint = True
-                else:
-                    if isinstance(dConfigParam,str):
+            if 'avLocation' in types:
+                outStr = '%s : %s' % (outStr, str(localAvatar.getLocation()))
+                
+            # determine whether we should print
+            doPrint = False
+            if not dConfigParam:
+                doPrint = True
+            else:
+                if isinstance(dConfigParam,str):
+                    if(config.GetBool(dConfigParam, 0)):
+                        doPrint = True
+                elif isinstance(dConfigParam, (list,tuple)):
+                    for param in dConfigParam:
                         if(config.GetBool(dConfigParam, 0)):
                             doPrint = True
-                    elif isinstance(dConfigParam, (list,tuple)):
-                        for param in dConfigParam:
-                            if(config.GetBool(dConfigParam, 0)):
-                                doPrint = True
-                                break
-
-                if doPrint:
-                    if notifyFunc:
-                        notifyFunc(outStr)
-                    else:
-                        print outStr
+                            break
+
+            if doPrint:
+                if notifyFunc:
+                    notifyFunc(outStr)
+                else:
+                    print outStr
 
-                    if 'printInterests' in types:
-                        base.cr.printInterestSets()
+                if 'printInterests' in types:
+                    base.cr.printInterestSets()
                     
-                    if 'stackTrace' in types:
-                        print StackTrace()
+                if 'stackTrace' in types:
+                    print StackTrace()
 
-                return f(*args,**kwargs)
+            return f(*args,**kwargs)
 
-            wrap.func_name = f.func_name
-            wrap.func_dict = f.func_dict
-            wrap.func_doc = f.func_doc
-            return wrap
-    except NameError,e:
-        print e
-        print 'Error decorating %s in %s with @report' % (f.func_name, f.__module__)
-        def decorator(f):
-            return f
-        
+        wrap.func_name = f.func_name
+        wrap.func_dict = f.func_dict
+        wrap.func_doc = f.func_doc
+        return wrap
+    
     return decorator
 
 def getBase():