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 collect_rules(self, comp, broker): """ Rule results are stored as dictionaries in the ``self.rules`` list. Each dictionary contains the folowing keys: name: fully qualified name of the rule id: fully qualified rule name with "." replaced with "_" response_type: the class name of the response object (make_info, etc.) body: rendered content for the rule as provided in the rule module. mod_doc: pydoc of the module containing the rule rule_doc: pydoc of the rule rule_path: absolute path to the source file of the rule datasources: sorted list of command or files contributing to the rule """ if comp in broker: name = dr.get_name(comp) rule_id = name.replace(".", "_") val = broker[comp] self.rules.append({ "name": name, "id": rule_id, "response_type": type(val).__name__, "body": render(comp, val), "mod_doc": sys.modules[comp.__module__].__doc__ or "", "rule_doc": comp.__doc__ or "", "source_path": inspect.getabsfile(comp), "datasources": sorted(set(self.get_datasources(comp, broker))) })
def printit(c, v): resp = self.responses[v["type"]] name = "[%s] %s" % (resp.label, dr.get_name(c)) self.print_header(name, 3) print("```", file=self.stream) print(render(c, v), file=self.stream) print("```", file=self.stream) print(file=self.stream)
def printit(c, v): resp = self.responses[v["type"]] name = "[%s] %s" % (resp.label, dr.get_name(c)) underline = "-" * len(name) name = "%s%s%s" % (resp.color, name, Style.RESET_ALL) print(name, file=self.stream) print(underline, file=self.stream) print(render(c, v), file=self.stream) print(file=self.stream)
def printit(c, v): _type = v.get("type") if _type: underline = "-" * len(dr.get_name(c)) resp = self.responses[v["type"]] name = "%s[%s] %s%s" % (resp.color, resp.label, dr.get_name(c), Style.RESET_ALL) if _type != "skip" or (_type == "skip" and self.missing): print(name, file=self.stream) print(underline, file=self.stream) print(render(c, v), file=self.stream) print(file=self.stream)
def printit(c, v): name = None if v["type"] in self.responses: self.counts[v["type"]] += 1 name = self.responses[v["type"]].color + dr.get_name( c) + Style.RESET_ALL if name: print(name) print('-' * len(name)) print(render(c, v)) print()
def printit(c, v): print("```", file=self.stream) print(render(c, v), file=self.stream) print("```", file=self.stream) print(file=self.stream)