summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
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:48 +0000
commitcde28486b0e65655fde392fcd7fdb64ac22be85c (patch)
tree1cba72eef990a211fe51790ddbcf53048cd95651 /bitbake/lib
parent8ff0840412a45bf25c34fb770acc9d35b2685c6b (diff)
downloadpoky-cde28486b0e65655fde392fcd7fdb64ac22be85c.tar.gz
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 <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/utils.py22
1 files changed, 22 insertions, 0 deletions
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):
893 893
894 return multiprocessing.Pool(*args, **kwargs) 894 return multiprocessing.Pool(*args, **kwargs)
895 895
896def exec_flat_python_func(func, *args, **kwargs):
897 """Execute a flat python function (defined with def funcname(args):...)"""
898 # Prepare a small piece of python code which calls the requested function
899 # To do this we need to prepare two things - a set of variables we can use to pass
900 # the values of arguments into the calling function, and the list of arguments for
901 # the function being called
902 context = {}
903 funcargs = []
904 # Handle unnamed arguments
905 aidx = 1
906 for arg in args:
907 argname = 'arg_%s' % aidx
908 context[argname] = arg
909 funcargs.append(argname)
910 aidx += 1
911 # Handle keyword arguments
912 context.update(kwargs)
913 funcargs.extend(['%s=%s' % (arg, arg) for arg in kwargs.iterkeys()])
914 code = 'retval = %s(%s)' % (func, ', '.join(funcargs))
915 comp = bb.utils.better_compile(code, '<string>', '<string>')
916 bb.utils.better_exec(comp, context, code, '<string>')
917 return context['retval']