[PATCH] utils: Add filter_string function

Richard Purdie <[email protected]>
Newsgroups org.openembedded.lists.bitbake-devel
Message-ID <[email protected]>
There are cases where we would like the filter functionality but
don't want to read the data from a variable. Add a new function,
filter_string to allow this, basically separating filter() into
two functions.

Signed-off-by: Richard Purdie <[email protected]>
---
 lib/bb/utils.py | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 7c5c5e8e65d..b04ff6ffc76 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -1336,21 +1336,18 @@ def contains_any(variable, checkvalues, truevalue, falsevalue, d):
         return truevalue
     return falsevalue
 
-def filter(variable, checkvalues, d):
-    """Return all words in the variable that are present in the ``checkvalues``.
+def filter_string(val, checkvalues):
+    """Return all words in the string that are present in the ``checkvalues``.
 
     Arguments:
 
-    -  ``variable``: the variable name. This will be fetched and expanded (using
-       d.getVar(variable)) and then split into a set().
+    -  ``val``: the string data to filter after being split into a set().
     -  ``checkvalues``: if this is a string it is split on whitespace into a set(),
        otherwise coerced directly into a set().
     -  ``d``: the data store.
 
     Returns a list of string.
     """
-
-    val = d.getVar(variable)
     if not val:
         return ''
     val = set(val.split())
@@ -1360,6 +1357,22 @@ def filter(variable, checkvalues, d):
         checkvalues = set(checkvalues)
     return ' '.join(sorted(checkvalues & val))
 
+def filter(variable, checkvalues, d):
+    """Return all words in the variable that are present in the ``checkvalues``.
+
+    Arguments:
+
+    -  ``variable``: the variable name. This will be fetched and expanded (using
+       d.getVar(variable)) and then split into a set().
+    -  ``checkvalues``: if this is a string it is split on whitespace into a set(),
+       otherwise coerced directly into a set().
+    -  ``d``: the data store.
+
+    Returns a list of string.
+    """
+
+    val = d.getVar(variable)
+    return filter_string(val, checkvalues)
 
 def get_referenced_vars(start_expr, d):
     """
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.