def where(self, name, value=None): """ Selects current nodes based on name and value queries of child nodes. If any immediate children match the queries, the parent is included in the results. The :py:func:``where_query`` function can be used to construct queries that act on the children as a whole instead of one at a time. Example: >>> from insights.parsr.query import where_query as q >>> from insights.parsr.query import from_dict >>> r = from_dict(load_config()) >>> r = conf.status.conditions.where(q("status", "False") | q("type", "Progressing")) >>> r.message >>> r = conf.status.conditions.where(q("status", "False") | q("type", "Progressing")) >>> r.message >>> r.lastTransitionTime.values ['2019-08-04T23:17:08Z', '2019-08-04T23:32:14Z'] """ if isinstance(name, _EntryQuery): query = name elif isinstance(name, Boolean): query = child_query(name, value) elif callable(name): query = SimpleQuery(pred(name)) else: query = child_query(name, value) results = [] seen = set() for c in self.children: if c not in seen and query.test(c): results.append(c) return Result(children=results)
def _desugar_name(q): if q is None: return NameQuery(TRUE) if isinstance(q, NameQuery): return q if isinstance(q, Boolean): return NameQuery(q) if callable(q): return NameQuery(pred(q)) return NameQuery(eq(q))
def _desugar_attr(q): if isinstance(q, Boolean): return q if callable(q): return pred(q) return eq(q)
def __init__(self, expr): if not isinstance(expr, Boolean): expr = pred(expr) self.expr = expr