def main(cmdline=None): """ Parse options, gather metadata, print requested data """ # Parse command line arguments options, arguments = Options().parse(cmdline) if not arguments: arguments = ["."] output = "" # Enable debugging output if options.debug: utils.log.setLevel(utils.LOG_DEBUG) # Show metadata for each path given counter = 0 for path in arguments: if options.verbose: utils.info("Checking {0} for metadata.".format(path)) tree = fmf.Tree(path) for node in tree.prune(options.whole, options.keys, options.names, options.filters): show = node.show(options.brief, options.formatting, options.values) if show is not None: print(show, end="") output += show counter += 1 # Print summary if options.verbose: utils.info("Found {0}.".format(utils.listed(counter, "object"))) return output
def show(self, brief=False): """ Show metadata for each path given """ output = [] for path in self.options.paths or ["."]: if self.options.verbose: utils.info("Checking {0} for metadata.".format(path)) tree = fmf.Tree(path) for node in tree.prune(self.options.whole, self.options.keys, self.options.names, self.options.filters, self.options.conditions): if brief: show = node.show(brief=True) else: show = node.show(brief=False, formatting=self.options.formatting, values=self.options.values) # List source files when in debug mode if self.options.debug: for source in node.sources: show += utils.color("{0}\n".format(source), "blue") if show is not None: output.append(show) # Print output and summary if brief or self.options.formatting: joined = "".join(output) else: joined = "\n".join(output) print(joined, end="") if self.options.verbose: utils.info("Found {0}.".format(utils.listed(len(output), "object"))) self.output = joined
def test_smoke(self): utils.Logging('fmf').set(utils.LOG_ALL) utils.info("something") utils.log.info("info") utils.log.debug("debug") utils.log.cache("cache") utils.log.data("data") utils.log.all("all")
def main(cmdline=None): """ Parse options, gather metadata, print requested data """ # Parse command line arguments options, arguments = Options().parse(cmdline) if not arguments: arguments = ["."] output = "" # Enable debugging output if options.debug: utils.log.setLevel(utils.LOG_DEBUG) # Show metadata for each path given counter = 0 for path in arguments: if options.verbose: utils.info("Checking {0} for metadata.".format(path)) tree = fmf.Tree(path) for node in tree.climb(options.whole): # Select only nodes with key content if not all([key in node.data for key in options.keys]): continue # Select nodes with name matching regular expression if options.names and not any( [re.search(name, node.name) for name in options.names]): continue # Apply advanced filters if given try: if not all([utils.filter(filter, node.data) for filter in options.filters]): continue # Handle missing attribute as if filter failed except utils.FilterError: continue show = node.show(brief=options.brief) print(show) output += show + "\n" counter += 1 # Print summary if options.verbose: utils.info("Found {0}.".format(utils.listed(counter, "object"))) return output