base.bbclass: add 'any' and 'all' functions.
PATCH 1/1 base.bbclass: add 'any' and 'all' functions.
Python 2.5+ has these functions built-in, but we don't yet require 2.5+.
--- classes/base.bbclass | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
classes/base.bbclass +15 -0
@@ -1,5 +1,20 @@ BB_DEFAULT_TASK ?= "build" +# Useful Python 2.5+ built-in functions +def any(iterable): + """ Return True if any element of the iterable is true. If the iterable is empty, return False. """ + for element in iterable: + if element: + return True + return False + +def all(iterable): + """ Return True if all elements of the iterable are true (or if the iterable is empty). """ + for element in iterable: + if not element: + return False + return True + python () { env = {} for v in d.keys():
Signature · 1 line
1.6.6
Quoted 2 lines · On Tuesday 19 January 2010 21:01:07 Chris Larson wrote:
Python 2.5+ has these functions built-in, but we don't yet require 2.5+.
do we use all/any in the metadata? or is MVista using? If the answer is yes then... I'm acking the patch.
Quoted 7 lines · On Sun, Jan 24, 2010 at 3:48 AM, Holger Hans Peter Freyther <…
Quoted 2 lines · On Tuesday 19 January 2010 21:01:07 Chris Larson wrote:
Python 2.5+ has these functions built-in, but we don't yet require 2.5+.
do we use all/any in the metadata? or is MVista using? If the answer is yes then... I'm acking the patch.
We don't yet. I've used it in some classes and .inc files in MVL6 that I plan on pushing to OE. They're much more useful than you'd think. As an example, I had some code where I had a list of path prefixes which were allowed, and wanted to check a filename against them:
if any(path.startswith(prefix + "/") for prefix in allowedpaths):
Signature · 7 lines
Chris Larson clarson at kergoth dot com clarson at mvista dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Software Engineer MontaVista Software, Inc.