def show_rule_report(self, match=None, ignore=None): """ Print a rule report for the matching rules. """ match, ignore = self._desugar_match_ignore(match, ignore) results = defaultdict(dict) for comp, val in self._broker.items(): name = dr.get_name(comp) if plugins.is_rule(comp) and match.test( name) and not ignore.test(name): kind = self._get_rule_value_kind(val) if kind: body = render(comp, val) links = render_links(comp) results[kind][name] = os.linesep.join([body, "", links]) report = [] for kind in ["info", "pass", "fail"]: color = RULE_COLORS.get(kind, "") hits = results.get(kind, {}) for name in sorted(hits): report.append(ansiformat(color, name)) report.append(ansiformat(color, "-" * len(name))) report.append(hits[name]) report.append("") IPython.core.page.page(six.u(os.linesep.join(report)))
def evaluate(self, name): """ Evaluate a component and return its result. Prints diagnostic information in the case of failure. This function is useful when a component's name contains characters that aren't valid for python identifiers so you can't access it with ``models.<name>``. Args: name (str): the name of the component as shown by :func:`Models.find()`. """ comp = self.get(name) or dr.get_component(name) if not comp: return if not plugins.is_rule(comp): self._requested.add((name, comp)) if comp in self._broker: return self._broker[comp] if comp in self._broker.exceptions or comp in self._broker.missing_requirements: self._dump_diagnostics(comp) return val = dr.run(comp, broker=self._broker).get(comp) if comp not in self._broker: if comp in self._broker.exceptions or comp in self._broker.missing_requirements: self._dump_diagnostics(comp) else: print("{} chose to skip.".format(dr.get_name(comp))) return val
def post_process(self): if combiners.hostname.hostname in self.broker: self.hostname = self.broker[combiners.hostname.hostname].fqdn for p, r in self.broker.items(): if plugins.is_rule(p): self.handle_result(p, r)
def post_process(self): self.hostname = self.broker[combiners.hostname.hostname].fqdn for c, exes in self.broker.exceptions.items(): for e in exes: log.warn(self.broker.tracebacks[e]) for p, r in self.broker.items(): if plugins.is_rule(p): self.handle_result(p, r)
def _get_rule_value(self, comp): try: val = self._broker[comp] if plugins.is_rule(comp): _type = val.__class__.__name__ kind = self._get_rule_value_kind(val) color = RULE_COLORS.get(kind, "") return ansiformat(color, " [{}]".format(_type)) except: pass return ""
def observer(c, broker): if ignore_hidden and dr.is_hidden(c): return if c not in broker and c not in broker.exceptions: return ser_name = dr.get_base_module_name(ser) name = dr.get_name(c) c_type = dr.get_component_type(c) doc = {} doc["name"] = name doc["dr_type"] = dr.get_name(c_type) if c_type else None doc["is_rule"] = plugins.is_rule(c) doc["time"] = broker.exec_times.get(c) doc["results"] = marshal(broker.get(c)) doc["errors"] = marshal(broker.exceptions.get(c)) path = os.path.join(output_dir, name + "." + ser_name) try: with open(path, "wb") as f: ser.dump(doc, f) except Exception as boom: log.error("Could not serialize %s to %s: %s" % (name, ser_name, boom)) fs.remove(path)
def get_rules(spec): return [r for r in get_all(spec, method=dr.get_dependents) if is_rule(r)]