From cb1be322f8dde28494b0ad124342a44e45f29a06 Mon Sep 17 00:00:00 2001 From: Jaroslav Henner Date: Fri, 19 Oct 2018 17:55:42 +0200 Subject: [PATCH] Add match_items --- cfme/modeling/base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cfme/modeling/base.py b/cfme/modeling/base.py index 2a395105a9..880846929c 100644 --- a/cfme/modeling/base.py +++ b/cfme/modeling/base.py @@ -190,3 +190,18 @@ def parent_of_type(obj, klass): for x in _walk_to_obj_root(obj): if isinstance(x, klass): return x + + +def match_items(items, filter): + ''' Return only items matching filter dict. ''' + for item in items: + for attr_name, val in filter.items(): + if getattr(item, attr_name) != val: + break + else: + yield item + + +def first(items): + ''' Return the first item in the iterable. ''' + return next(iter(items))