From 1ea78fd02fc9ae34753d15944c23b5502ce72aef Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Fri, 10 Apr 2009 01:27:58 +0000 Subject: [PATCH] adding ability to have multiple prefixes in report by specifying them in the Config.prc --- direct/src/showbase/PythonUtil.py | 52 +++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index 048c320f92..4bc78571c5 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -1202,11 +1202,11 @@ def extractProfile(*args, **kArgs): # restore stdout to what it was before sc.destroy() -def getSetterName(valueName, prefix='set'): +def getSetterName(valueName): # getSetterName('color') -> 'setColor' # getSetterName('color', 'get') -> 'getColor' 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 return getattr(targetObj, getSetterName(valueName, prefix)) @@ -3071,7 +3071,7 @@ class ClassTree: 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 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 specified config strings resolve to True. """ + def decorator(f): return f + try: if not (__dev__ or config.GetBool('force-reports', 0)): return decorator @@ -3133,13 +3135,29 @@ def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigPara dConfigParamList = (dConfigParam,) else: 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: 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: return decorator @@ -3166,8 +3184,9 @@ def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigPara 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 = '' @@ -3188,11 +3207,18 @@ def report(types = [], prefix = '', xform = None, notifyFunc = None, dConfigPara if xform: 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: - print outStr + if notifyFunc: + notifyFunc(outStr) + else: + print outStr if 'interests' in types: base.cr.printInterestSets()