Пример #1
0
    def show(self, brief=False, formatting=None, values=[]):
        """ Show metadata """
        # Show nothing if there's nothing
        if not self.data:
            return None

        # Custom formatting
        if formatting is not None:
            formatting = re.sub("\\\\n", "\n", formatting)
            name = self.name
            data = self.data
            root = self.root
            evaluated = []
            for value in values:
                evaluated.append(eval(value))
            return formatting.format(*evaluated)

        # Show the name
        output = utils.color(self.name, 'red')
        if brief:
            return output
        # List available attributes
        for key, value in sorted(self.data.items()):
            output += "\n{0}: ".format(utils.color(key, 'yellow'))
            if isinstance(value, type("")):
                output += value
            elif isinstance(value, list) and all(
                [isinstance(item, type("")) for item in value]):
                output += utils.listed(value)
            else:
                output += pretty(value)
            output
        return output + "\n"
Пример #2
0
Файл: cli.py Проект: thrix/fmf
    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
Пример #3
0
 def show(self, brief=False):
     """ Show metadata """
     # Show the name
     output = utils.color(self.name, 'red')
     if brief:
         return output
     # List available attributes
     for key, value in sorted(self.data.iteritems()):
         output += "\n{0}: ".format(utils.color(key, 'yellow'))
         if isinstance(value, basestring):
             output += value
         elif isinstance(value, list) and all(
                 [isinstance(item, basestring) for item in value]):
             output += utils.listed(value)
         else:
             output += pretty(value)
         output
     return output
Пример #4
0
 def test_color(self):
     utils.Coloring().set()
     text = utils.color("text", "lightblue", enabled=True)