-
Notifications
You must be signed in to change notification settings - Fork 74
/
layout.py
32 lines (28 loc) · 912 Bytes
/
layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding=utf-8
""" Everything about console output's layout """
from prettytable import PrettyTable
from six import print_
def make_table(header, align_map=None, rows=None):
""" Wrapper for pretty table """
table = PrettyTable()
table.horizontal_char = table.vertical_char = table.junction_char = ' '
try:
table.field_names = header
except Exception as err:
print_(header)
raise err
if align_map:
for field, align in zip(header, align_map):
table.align[field] = align
if rows:
for row in rows:
if len(row) < len(table.field_names):
continue
try:
table.add_row(row)
except Exception as err:
print_('fields:', table.field_names)
print_('row:', row)
print_('rows:', rows)
raise err
return table