Beispiel #1
0
 def format_item(self, item, defaults=None, stencil=None):
     """ Format an item.
     """
     try:
         item_text = fmt.to_console(formatting.format_item(self.options.output_format, item, defaults))
     except (NameError, ValueError, TypeError), exc:
         self.fatal("Trouble with formatting item %r\n\n  FORMAT = %r\n\n  REASON =" % (item, self.options.output_format), exc)
         raise # in --debug mode
Beispiel #2
0
                if self.anneal(mode, matches, orig_matches):
                    matches.sort(key=sort_key,
                                 reverse=self.options.reverse_sort)

        if selection:
            matches = matches[selection[0] - 1:selection[1]]

        if not matches:
            # Think "404 NOT FOUND", but then exit codes should be < 256
            self.return_code = 44

        # Build header stencil
        stencil = None
        if self.options.column_headers and self.plain_output_format and matches:
            stencil = fmt.to_console(
                formatting.format_item(self.options.output_format, matches[0],
                                       self.FORMATTER_DEFAULTS)).split('\t')

        # Tee to ncurses view, if requested
        if self.options.tee_view and (self.options.to_view
                                      or self.options.view_only):
            self.show_in_view(view, matches)

        # Generate summary?
        summary = FieldStatistics(len(matches))
        if self.options.stats or self.options.summary:
            for field in self.get_output_fields():
                try:
                    0 + getattr(matches[0], field)
                except (TypeError, ValueError, IndexError):
                    summary.total[field] = ''
                else:
Beispiel #3
0
 def _template_globber(val, item):
     """Helper."""
     pattern = formatting.format_item(self._template,
                                      item).replace('[', '[[]')
     ##print('!!!', val, '~~~', pattern, '???')
     return fnmatch.fnmatchcase(val, pattern.lower())
Beispiel #4
0
        # possibly find more matches.
        #
        view = config.engine.view(self.options.from_view, matcher)
        matches = list(view.items())
        matches.sort(key=sort_key, reverse=self.options.reverse_sort)
        if selection:
            matches = matches[selection[0]-1:selection[1]]

        if not matches:
            # Think "404 NOT FOUND", but then exit codes should be < 256
            self.return_code = 44

        # Build header stencil
        stencil = None
        if self.options.column_headers and self.plain_output_format and matches:
            stencil = fmt.to_console(formatting.format_item(
                self.options.output_format, matches[0], self.FORMATTER_DEFAULTS)).split('\t')

        # Tee to ncurses view, if requested
        if self.options.tee_view and (self.options.to_view or self.options.view_only):
            self.show_in_view(view, matches)

        # Generate summary?
        summary = FieldStatistics(len(matches))
        if self.options.stats or self.options.summary:
            for field in self.get_output_fields():
                try:
                    0 + getattr(matches[0], field)
                except (TypeError, ValueError, IndexError):
                    summary.total[field] = ''
                else:
                    for item in matches:
Beispiel #5
0
 def update(self):
     self.state.update()
     self._content = formatting.format_item(self.state.TEMPL, self.state)
     self.redraw_canvas()
     return True
Beispiel #6
0
 def update(self):
     self.state.update()
     self._content = formatting.format_item(self.state.TEMPL, self.state)
     self.redraw_canvas()
     return True