cloudmesh-common.cloudmesh.common.Tabulate

Module Contents

Classes

Printer

formats supported dict, yaml, json

class cloudmesh-common.cloudmesh.common.Tabulate.Printer

formats supported dict, yaml, json

set table.format=table cms flavor list +———–+———+——-+——–+ | Name | VCPUS | RAM | Disk | |-----------+---------+-------+--------| | m1.tiny | 1 | 512 | 1 | | m1.small | 1 | 2048 | 20 | | m1.medium | 2 | 4096 | 40 | | m1.large | 4 | 8192 | 40 | | m1.xlarge | 8 | 16384 | 40 | +———–+———+——-+——–+

set table.format=grid cms flavor list ╒═══════════╤═════════╤═══════╤════════╕ │ Name │ VCPUS │ RAM │ Disk │ ╞═══════════╪═════════╪═══════╪════════╡ │ m1.tiny │ 1 │ 512 │ 1 │ ├───────────┼─────────┼───────┼────────┤ │ m1.small │ 1 │ 2048 │ 20 │ ├───────────┼─────────┼───────┼────────┤ │ m1.medium │ 2 │ 4096 │ 40 │ ├───────────┼─────────┼───────┼────────┤ │ m1.large │ 4 │ 8192 │ 40 │ ├───────────┼─────────┼───────┼────────┤ │ m1.xlarge │ 8 │ 16384 │ 40 │ ╘═══════════╧═════════╧═══════╧════════╛

static default()
static select(results, order=None, width=None)

selects field in the order as defined in order If order is non, all fileds will be taken

Parameters
  • results – a flat dict

  • order – the order of the fields

  • width

Returns

a list of dicts

static write(results, order=None, header=None, output='table', width=None, humanize=False, max_width=None, sep='.')
static _to_tabulate(d)
Parameters

d – dict of dicts

Returns

list of dicts with the key as name

static flatwrite(table, order=None, header=None, output='table', sort_keys=True, show_none='', humanize=None, sep='.', max_width=48, width=48)

writes the information given in the table :param table: the table of values :param order: the order of the columns :param header: the header for the columns :param output: the format (default is table, values are raw, csv, json, yaml, dict :param sort_keys: if true the table is sorted :param show_none: passed along to the list or dict printer :param sep: uses sep as the separator for csv printer :param width: maximum width for a cell :type width: int :param max_width: deprecated use width :type max_width: int :return:

classmethod attribute(cls, d, header=None, order=None, sort_keys=True, humanize=None, output='table', width=70)

prints a attribute/key value table

Parameters
  • d – A a dict with dicts of the same type. Each key will be a column

  • order – The order in which the columns are printed. The order is specified by the key names of the dict.

  • header (A list of string) – The Header of each of the columns

  • sort_keys (string or a tuple of string (for sorting with multiple columns)) – Key(s) of the dict to be used for sorting. This specify the column(s) in the table for sorting.

  • output – the output format table, csv, dict, json

classmethod csv(cls, d, order=None, header=None, humanize=None, sort_keys=True)

prints a table in csv format

Parameters
  • d (dict) – A a dict with dicts of the same type.

  • order – The order in which the columns are printed. The order is specified by the key names of the dict.

  • header (list or tuple of field names) – The Header of each of the columns

  • sort_keys (bool) – TODO - not yet implemented

Returns

a string representing the table in csv format