Пример #1
0
 def _tbl_output(self,
                 fields,
                 data,
                 alignments=None,
                 humanize_columns=None):
     """
     outputs data based on fields list.
     fields: list(fieldnames)
     data: list of dicts with keys containing field names
     alignments: dict(name: direction)
     humanize_columns: List of columns of file sizes
     """
     tbl = PrettyTable()
     tbl.field_names = fields
     if alignments:
         for key, value in alignments.items():
             tbl.align[key] = value
     for d in data:
         values = []
         for field_name in fields:
             if type(d[field_name]) is datetime:
                 values.append(d[field_name].strftime('%Y-%m-%d %H:%M:%S'))
             elif self.human_readable and humanize_columns and field_name in humanize_columns:
                 values.append(humanize(d[field_name]))
             else:
                 values.append(d[field_name])
         tbl.add_row(values)
     if self.skip_header:
         tbl.header = False
     print(tbl)
Пример #2
0
 def _machine_output(self, fields, data, humanize_columns=None):
     if not self.skip_header:
         print('|'.join(fields))
     for d in data:
         values = []
         for field_name in fields:
             if type(d[field_name]) is datetime:
                 values.append(d[field_name].strftime('%Y-%m-%d %H:%M:%S'))
             elif self.human_readable and humanize_columns and field_name in humanize_columns:
                 values.append(humanize(d[field_name]))
             else:
                 values.append(d[field_name])
         print('|'.join(map(str, values)))