def print_component(comp, verbose=False): print(dr.get_name(comp)) if not verbose: return space = " " * 4 dbl_space = space * 2 d = dr.get_delegate(comp) if d.requires: print(space + "Requires") for r in d.requires: print(dbl_space + dr.get_name(r)) else: print(space + "Requires nothing") if d.at_least_one and d.at_least_one[0]: for one in d.at_least_one: print(space + "At least one of") for o in one: print(dbl_space + dr.get_name(o)) if d.optional: print(space + "Optional") for r in d.optional: print(dbl_space + dr.get_name(r)) print()
def get_content(obj, val): """ Attempts to determine a jinja2 content template for a rule's response. """ # does the rule define a content= kwarg? c = dr.get_delegate(obj).content # otherwise, does the rule module have a CONTENT attribute? if c is None: mod = sys.modules[obj.__module__] c = getattr(mod, "CONTENT", None) if c: # is the content a dictionary? if isinstance(c, dict): # does it contain a make_* class as a key? v = c.get(val.__class__) if v is not None: return v # does it contain an error key? key = val.get_key() if key: v = c.get(key) # is the value a dict that contains make_* classes? if isinstance(v, dict): return v.get(val.__class__) return v else: return c
def dry_run(graph=dr.COMPONENTS[dr.GROUPS.single], broker=None): broker = broker or dr.Broker() for c in broker.instances: yield c for c in dr.run_order(graph): d = dr.get_delegate(c) if d and d.get_missing_dependencies(broker) is None: broker[c] = 1 yield c
def get_content(obj, key): c = dr.get_delegate(obj).content if c is None: mod = sys.modules[obj.__module__] c = getattr(mod, "CONTENT", None) if c: if isinstance(c, dict): if key: return c.get(key) else: return c
def render_links(component): links = dr.get_delegate(component).links or {} if any(links.values()): space = " " * 4 dbl_space = space * 2 output = StringIO() output.write("Links:\n") for key in sorted(links): values = sorted(links[key]) if values: output.write(space + key + ":\n") for v in values: output.write(dbl_space + v + "\n") output.seek(0) return output.read() return ""
def dump_ds(d, space=""): dbl_space = space * 2 delegate = dr.get_delegate(d) try: print(space + "Class: %s" % d.__class__) except: pass try: print(space + "Filtered: %s" % delegate.filterable) except: pass print(space + "Raw: %s" % delegate.raw) print(space + "Multioutput: %s" % delegate.multi_output) if isinstance(d, sf.simple_file): print(space + "Path: %s" % d.path) if isinstance(d, (sf.simple_command, sf.foreach_execute)): print(space + "Command: %s" % d.cmd) if isinstance(d, sf.first_file): print(space + "Paths:") for p in d.paths: print(dbl_space + p) if isinstance(d, sf.glob_file): print(space + "Patterns:") for p in d.patterns: print(dbl_space + p) print(space + "Ignore: %s" % d.ignore) if isinstance(d, sf.foreach_collect): print(space + "Path: %s" % d.path) print(space + "Ignore: %s" % d.ignore) filters = get_filters(d) if filters: print(space + "Filters:") for f in filters: print(dbl_space + f)
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 source_path: absolute path to the source file of the rule tags: the list of tags associated with 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] links = dr.get_delegate(comp).links or {} 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), "tags": list(dr.get_tags(comp)), "datasources": sorted(set(self.get_datasources(comp, broker))), "links": links })
def print_component(comp, verbose=False, specs=False): if (specs or (not specs and not is_type(comp, datasource))): print(dr.get_name(comp)) if not verbose: return space = " " * 4 dbl_space = space * 2 d = dr.get_delegate(comp) print(space + "Type: %s" % dr.get_name(d.type)) if is_type(comp, datasource): dump_ds(comp, space=space) print() if d.requires: print(space + "Requires:") for r in d.requires: print(dbl_space + dr.get_name(r)) else: print(space + "Requires: nothing") if d.at_least_one and d.at_least_one[0]: for one in d.at_least_one: print(space + "At least one of:") for o in one: print(dbl_space + dr.get_name(o)) if d.optional: print(space + "Optional:") for r in d.optional: print(dbl_space + dr.get_name(r)) dependents = dr.get_dependents(comp) if dependents: print(space + "Dependents:") for r in sorted(dependents, key=dr.get_name): print(dbl_space + dr.get_name(r)) print()