Jelajahi Sumber

adding ability to have multiple prefixes in report by specifying them in the Config.prc

Josh Wilson 16 tahun lalu
induk
melakukan
1ea78fd02f
1 mengubah file dengan 39 tambahan dan 13 penghapusan
  1. 39 13
      direct/src/showbase/PythonUtil.py

+ 39 - 13
direct/src/showbase/PythonUtil.py

@@ -1202,11 +1202,11 @@ def extractProfile(*args, **kArgs):
     # restore stdout to what it was before
     # restore stdout to what it was before
     sc.destroy()
     sc.destroy()
 
 
-def getSetterName(valueName, prefix='set'):
+def getSetterName(valueName):
     # getSetterName('color') -> 'setColor'
     # getSetterName('color') -> 'setColor'
     # getSetterName('color', 'get') -> 'getColor'
     # getSetterName('color', 'get') -> 'getColor'
     return '%s%s%s' % (prefix, string.upper(valueName[0]), valueName[1:])
     return '%s%s%s' % (prefix, string.upper(valueName[0]), valueName[1:])
-def getSetter(targetObj, valueName, prefix='set'):
+def getSetter(targetObj, valueName):
     # getSetter(smiley, 'pos') -> smiley.setPos
     # getSetter(smiley, 'pos') -> smiley.setPos
     return getattr(targetObj, getSetterName(valueName, prefix))
     return getattr(targetObj, getSetterName(valueName, prefix))
 
 
@@ -3071,7 +3071,7 @@ class ClassTree:
         return self._getStr()
         return self._getStr()
 
 
 
 
-def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigParam = []):
+def report(types = [], xform = None, notifyFunc = None, dConfigParam = []):
     """
     """
     This is a decorator generating function.  Use is similar to
     This is a decorator generating function.  Use is similar to
     a @decorator, except you must be sure to call it as a function.
     a @decorator, except you must be sure to call it as a function.
@@ -3117,8 +3117,10 @@ def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigPara
                   specify this param, it will only print if one of the
                   specify this param, it will only print if one of the
                   specified config strings resolve to True.
                   specified config strings resolve to True.
     """
     """
+
     def decorator(f):
     def decorator(f):
         return f
         return f
+    
     try:
     try:
         if not (__dev__ or config.GetBool('force-reports', 0)):
         if not (__dev__ or config.GetBool('force-reports', 0)):
             return decorator
             return decorator
@@ -3133,13 +3135,29 @@ def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigPara
                 dConfigParamList = (dConfigParam,)
                 dConfigParamList = (dConfigParam,)
             else:
             else:
                 dConfigParamList = dConfigParam
                 dConfigParamList = dConfigParam
-            for param in dConfigParamList:
-                if(config.GetBool('want-%s-report' % (param,), 0)):
-                    doPrint = True
-                    break
 
 
+            dConfigParamList = [param for param in dConfigParamList \
+                                if config.GetBool('want-%s-report' % (param,), 0)]
+                
+            doPrint = bool(dConfigParamList)
+            pass
+        
         if not doPrint:
         if not doPrint:
             return decorator
             return decorator
+
+        # Determine any prefixes defined in our Config.prc.
+        if prefix:
+            prefixes = set([prefix])
+        else:
+            prefixes = set()
+            pass
+        
+        for param in dConfigParamList:
+            prefix = config.GetString('prefix-%s-report' % (param,), '')
+            if prefix:
+                prefixes.add(prefix)
+                pass
+            pass
         
         
     except NameError,e:
     except NameError,e:
         return decorator
         return decorator
@@ -3166,8 +3184,9 @@ def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigPara
 
 
             outStr = '%s%s' % (f.func_name, rArgs)
             outStr = '%s%s' % (f.func_name, rArgs)
 
 
-            if prefix:
-                outStr = '%s %s' % (prefix, outStr)
+            # Insert prefix place holder, if needed
+            if prefixes:
+                outStr = '%%s %s' % (outStr,)
 
 
             preStr = ''
             preStr = ''
 
 
@@ -3188,11 +3207,18 @@ def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigPara
 
 
             if xform:
             if xform:
                 outStr = '%s : %s' % (outStr, xform(args[0]))
                 outStr = '%s : %s' % (outStr, xform(args[0]))
-                
-            if notifyFunc:
-                notifyFunc(outStr)
+
+            if prefixes:
+                for prefix in prefixes:
+                    if notifyFunc:
+                        notifyFunc(outStr % (prefix,))
+                    else:
+                        print outStr % (prefix,)
             else:
             else:
-                print outStr
+                if notifyFunc:
+                    notifyFunc(outStr)
+                else:
+                    print outStr
 
 
             if 'interests' in types:
             if 'interests' in types:
                 base.cr.printInterestSets()
                 base.cr.printInterestSets()