Python prettytable.PLAIN_COLUMNS Examples
The following are 8
code examples of prettytable.PLAIN_COLUMNS().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
prettytable
, or try the search function
.
Example #1
Source File: tablefmt.py From treadmill with Apache License 2.0 | 6 votes |
def _make_table(columns, header=False, align=None): """Make a table object for output.""" if not align: align = {} table = prettytable.PrettyTable(columns) for col in columns: table.align[col] = align.get(col, 'l') table.set_style(prettytable.PLAIN_COLUMNS) # For some reason, headers must be disable after set_style. table.header = header table.left_padding_width = 0 table.right_padding_width = 2 return table
Example #2
Source File: utils.py From anchore-cli with Apache License 2.0 | 5 votes |
def plain_column_table(header, align='l'): table = PrettyTable(header) table.set_style(PLAIN_COLUMNS) table.align = align return table
Example #3
Source File: utils_output.py From python-otcclient with MIT License | 5 votes |
def printLevel2(respjson, outformat, mainkey, listkey, subkey=None): if mainkey: parsed = json.loads(respjson) p=defaultprettytable(listkey) if(outformat.startswith("json")) : print(json.dumps(parsed, indent=4, sort_keys=True)) else: if(outformat.startswith("text")): p.set_style(prettytable.PLAIN_COLUMNS) mainId = respjson if mainkey and len(mainkey) > 0: mainId = parsed[mainkey] for n in range(len(mainId)): item = mainId[n] #for item in mainId: if not (subkey is None): item = item[subkey] vals = list() for colkey in listkey: if colkey in item: vals.append(item[colkey]) else: vals.append(" ") p.add_row(vals) print(p.get_string())
Example #4
Source File: utils_output.py From python-otcclient with MIT License | 5 votes |
def printJsonTableTransverse(jsonval, outformat, mainkey): parsed = json.loads(jsonval) if(outformat.startswith("json")): print(json.dumps(parsed, indent=4, sort_keys=True)) else: if(outformat.startswith("text")): x.set_style(prettytable.PLAIN_COLUMNS) if mainkey: id_generator(parsed[mainkey], "") else: id_generator(parsed, "") print(x.get_string())
Example #5
Source File: server.py From Slackor with GNU General Public License v3.0 | 5 votes |
def do_list(self, args): """Lists registered agents""" t = PrettyTable(['ID', 'Hostname', 'User', 'IP Address', 'Version']) t.set_style(PLAIN_COLUMNS) conn = sqlite3.connect('slackor.db') cursor = conn.execute("SELECT id, hostname, user, ip, version from AGENTS") for row in cursor: ID = row[0] hostname = row[1] user = row[2] ipaddr = row[3] version = row[4] t.add_row([ID, hostname, user, ipaddr, version]) print(color(t, "blue")) conn.close()
Example #6
Source File: display.py From gtd.py with BSD 3-Clause "New" or "Revised" License | 5 votes |
def show_cards(self, cards, tsv=False, sort='activity', table_fields=[]): '''Display an iterable of cards all at once. Uses a pretty-printed table by default, but can also print tab-separated values (TSV). Supports the following cli commands: show cards grep :param list(trello.Card)|iterable(trello.Card) cards: cards to show :param bool tsv: display these cards using a tab-separated value format :param str sort: the field name to sort by (must be a valid field name in this table) :param list table_fields: display only these fields ''' # TODO construct the table dynamically instead of filtering down an already-constructed table # TODO implement a custom sorting functions so the table can be sorted by multiple columns table = prettytable.PrettyTable() table.field_names = self.fields.keys() table.align = 'l' if tsv: table.set_style(prettytable.PLAIN_COLUMNS) else: table.hrules = prettytable.FRAME with click.progressbar(list(cards), label='Fetching cards', width=0) as pg: for card in pg: table.add_row([x(card) for x in self.fields.values()]) try: table[0] except IndexError: click.secho('No cards match!', fg='red') raise GTDException(1) if table_fields: print(table.get_string(fields=table_fields, sortby=sort)) else: print(self.resize_and_get_table(table, self.fields.keys(), sort))
Example #7
Source File: gtd.py From gtd.py with BSD 3-Clause "New" or "Revised" License | 5 votes |
def show_boards(ctx, use_json, tsv, by, show_all): '''Show all boards your account can access''' if show_all: boards = ctx.connection.trello.fetch_json('/members/me/boards/?filter=all') else: boards = ctx.connection.boards if use_json: print(json.dumps(boards, sort_keys=True, indent=2)) return else: ctx.display.banner() # Set up a table to hold our boards board_columns = ['name', 'activity', 'members', 'permission', 'url'] if by not in board_columns: click.secho(f'Field {by} is not a valid field: {",".join(board_columns)}', fg='red') raise GTDException(1) table = prettytable.PrettyTable() table.field_names = board_columns table.align = 'l' if tsv: table.set_style(prettytable.PLAIN_COLUMNS) else: table.hrules = prettytable.FRAME for b in boards: table.add_row( [ b['name'], b['dateLastActivity'] or '', len(b['memberships']), b['prefs']['permissionLevel'], b['shortUrl'], ] ) try: table[0] except IndexError: click.secho('You have no boards!', fg='red') print(table.get_string(sortby=by))
Example #8
Source File: objectstorage.py From anchore-engine with Apache License 2.0 | 5 votes |
def list_migrations(): db_conf = db_context() db_preflight(db_conf['params'], db_conf['retries']) with session_scope() as db: tasks = db_tasks.get_all(task_type=ArchiveMigrationTask, session=db, json_safe=True) fields = [ 'id', 'state', 'started_at', 'ended_at', 'migrate_from_driver', 'migrate_to_driver', 'archive_documents_migrated', 'archive_documents_to_migrate', 'last_updated' ] headers = [ 'id', 'state', 'start time', 'end time', 'from', 'to', 'migrated count', 'total to migrate', 'last updated' ] tbl = PrettyTable(field_names=headers) tbl.set_style(PLAIN_COLUMNS) for t in tasks: tbl.add_row([t[x] for x in fields]) logger.info((tbl.get_string(sortby='id')))