summaryrefslogtreecommitdiffstats
path: root/lib/bb/utils.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2014-12-08 10:50:22 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-12-09 22:15:35 +0000
commit20e6939ebcb62e08a9a7ad586a915dfe368136a0 (patch)
treec1b8ed8c6094b5533a1a0af08578facfef06defe /lib/bb/utils.py
parentbe8f0076667f17587dbcff4b6b6467a7ec29d2b8 (diff)
downloadbitbake-20e6939ebcb62e08a9a7ad586a915dfe368136a0.tar.gz
utils: add exec_flat_python_func()
Add a function that allows executing a flat python function (defined with def funcname(args): ...). Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r--lib/bb/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index c6f40711a..d7c506761 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -893,3 +893,25 @@ def multiprocessingpool(*args, **kwargs):
return multiprocessing.Pool(*args, **kwargs)
+def exec_flat_python_func(func, *args, **kwargs):
+ """Execute a flat python function (defined with def funcname(args):...)"""
+ # Prepare a small piece of python code which calls the requested function
+ # To do this we need to prepare two things - a set of variables we can use to pass
+ # the values of arguments into the calling function, and the list of arguments for
+ # the function being called
+ context = {}
+ funcargs = []
+ # Handle unnamed arguments
+ aidx = 1
+ for arg in args:
+ argname = 'arg_%s' % aidx
+ context[argname] = arg
+ funcargs.append(argname)
+ aidx += 1
+ # Handle keyword arguments
+ context.update(kwargs)
+ funcargs.extend(['%s=%s' % (arg, arg) for arg in kwargs.iterkeys()])
+ code = 'retval = %s(%s)' % (func, ', '.join(funcargs))
+ comp = bb.utils.better_compile(code, '<string>', '<string>')
+ bb.utils.better_exec(comp, context, code, '<string>')
+ return context['retval']