From cde28486b0e65655fde392fcd7fdb64ac22be85c Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Mon, 8 Dec 2014 10:50:22 +0000 Subject: bitbake: utils: add exec_flat_python_func() Add a function that allows executing a flat python function (defined with def funcname(args): ...). (Bitbake rev: 20e6939ebcb62e08a9a7ad586a915dfe368136a0) Signed-off-by: Paul Eggleton Signed-off-by: Richard Purdie --- bitbake/lib/bb/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'bitbake/lib/bb/utils.py') diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index c6f40711a9..d7c5067613 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/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, '', '') + bb.utils.better_exec(comp, context, code, '') + return context['retval'] -- cgit v1.2.3-54-g00ecf