def setUp(self):
     styler = Styler()
     self.table = MultiTable(initial_section=False,
                             column_separator='|', styler=styler,
                             auto_reformat=False)
     self.formatter = TableFormatter(Object(color='off'))
     self.formatter.table = self.table
     self.stream = six.StringIO()
Example #2
0
def tabulate(operation, data):
    """
    Formats a data structure as a table
    :param operation: the title of the table
    :param data: list or dict to print
    """
    if data is None:
        return ""
    table = MultiTable(initial_section=False,
                       column_separator='|',
                       styler=Styler(),
                       auto_reformat=False)

    formatter = TableFormatter(
        type('dummy', (object, ), {
            "color": "on",
            "query": None
        }))
    formatter.table = table
    stream = six.StringIO()
    formatter(operation, data, stream=stream)
    return stream.getvalue()
Example #3
0
from awscli.compat import six
from awscli.formatter import TableFormatter
from awscli.table import MultiTable, ColorizedStyler
import sys
import json


class Object(object):
    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)
        self.query = None

stream = six.StringIO()
styler = ColorizedStyler()
table = MultiTable(initial_section=False,
                   column_separator='|', styler=styler)
formatter = TableFormatter(Object(color='on'))
formatter.table = table


DATA = []

for line in sys.stdin.readlines():
    if line.strip():
        DATA.append(json.loads(line))

formatter(sys.argv[1], DATA, stream=stream)
output = stream.getvalue()
if output: print(output)