Skip to contentSkip to conversation

bitbake/utils: Add contains helper function

RFC PATCH In review Richard Purdie 1 participant 1 message Jul 11, 2011

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/3 bitbake/utils: Add contains helper function

---
 bitbake/lib/bb/utils.py |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
bitbake/lib/bb/utils.py +16 -0
index 82e5dc4..e19e1c8 100644
@@ -856,3 +856,19 @@ def to_boolean(string, default=None):
         return False
     else:
         raise ValueError("Invalid value for to_boolean: %s" % string)
+
+
+def contains(variable, checkvalues, truevalue, falsevalue, d):
+    val = d.getVar(variable, True)
+    if not val:
+        return falsevalue
+    matches = 0
+    if type(checkvalues).__name__ == "str":
+        checkvalues = [checkvalues]
+    for value in checkvalues:
+        if val.find(value) != -1:
+            matches = matches + 1
+    if matches == len(checkvalues):
+        return truevalue
+    return falsevalue
+
Signature · 1 line
1.7.4.1