Beispiel #1
0
 def __init__(self, args, table=None):
     super(TableFormatter, self).__init__(args)
     if args.color == 'auto':
         self.table = MultiTable(initial_section=False,
                                 column_separator='|')
     elif args.color == 'off':
         styler = Styler()
         self.table = MultiTable(initial_section=False,
                                 column_separator='|', styler=styler)
     elif args.color == 'on':
         styler = ColorizedStyler()
         self.table = MultiTable(initial_section=False,
                                 column_separator='|', styler=styler)
     else:
         raise ValueError("Unknown color option: %s" % args.color)
 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()
Beispiel #3
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()
Beispiel #4
0
 def setUp(self):
     self.table = MultiTable()
Beispiel #5
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)