aboutsummaryrefslogtreecommitdiff
path: root/kernelci/configs.py
diff options
context:
space:
mode:
authorGuillaume Tucker <guillaume.tucker@collabora.com>2019-07-09 10:16:15 +0100
committerGuillaume Tucker <guillaume.tucker@collabora.com>2019-07-11 13:09:41 +0100
commit32e5c40427bd82c7ea6f8e3c120058e12841beb8 (patch)
tree61a15b77cbff766900b5e11c80a22063df876dfb /kernelci/configs.py
parent7e3514c16e05d6a0dde3fb690e9e6af6c4004f3c (diff)
kernelci.configs: add Regex filter type
Add Regex filter type which acts as a whitelist but with a regular expression that needs to match instead of a list of keywords. This is in particular useful for filtering defconfigs, to be able to whitelist "defconfig" but not any "*defconfig" as the Whitelist would do. Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Diffstat (limited to 'kernelci/configs.py')
-rw-r--r--kernelci/configs.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/kernelci/configs.py b/kernelci/configs.py
index 7ef42aa..de6dd58 100644
--- a/kernelci/configs.py
+++ b/kernelci/configs.py
@@ -15,6 +15,7 @@
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import re
import yaml
@@ -91,6 +92,26 @@ class Whitelist(Filter):
return True
+class Regex(Filter):
+ """Regex filter to only accept certain configurations.
+
+ Regex *items* are a dictionary associating keys with regular expressions.
+ The should be one regular expression for each key, not a list of them. For
+ a configuration to be accepted, its value must match the regular expression
+ for each key specified in the filter items.
+ """
+
+ def __init__(self, *args, **kw):
+ super(Regex, self).__init__(*args, **kw)
+ self._re_items = {k: re.compile(v) for k, v in self._items.iteritems()}
+
+
+ def match(self, **kw):
+ for k, r in self._re_items.iteritems():
+ v = kw.get(k)
+ return v and r.match(v)
+
+
class Combination(Filter):
"""Combination filter to only accept some combined configurations.
@@ -116,6 +137,7 @@ class FilterFactory(YAMLObject):
_classes = {
'blacklist': Blacklist,
'whitelist': Whitelist,
+ 'regex': Regex,
'combination': Combination,
}