Exemple #1
0
    def _add_to_stash(self, rec):
        """Add record to stash

        :type rec: Record
        """
        self._stash.append(rec)
        for key, val in rec.items():
            w0 = self._widths.get(key, len(key))
            w = max(w0, len(str(val)))
            self._widths[key] = w
            if Keyword.is_id(key):
                if val not in self._ids:
                    self._update_prefixlen(val)
                self._ids.add(val)
                self._newids.add(val)
Exemple #2
0
 def _print_page(self, n=None):
     """Print one page, remove rows from stash."""
     # header
     columns = self._header()
     # body
     if n is None:
         n = self._pagelen - self._pagepos
     for i in range(n):
         rec = self._stash[i]
         row = []
         for name, fmtstr in columns:
             if Keyword.is_id(name):
                 s = rec.get(name, '')[:self._idpre]
             else:
                 s = str(rec.get(name, ''))
             row.append(fmtstr.format(s))
         self._out.write(' '.join(row) + '\n')
         # shorten stash
     self._stash = self._stash[n:]
Exemple #3
0
 def _shorten_ids(self):
     """Shorten id's to prefix."""
     for name, w in self._widths.items():
         if Keyword.is_id(name):
             self._widths[name] = max(len(name), self._idpre)