Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
row = [el['package'], el['version'], el['license']]
t.add_row(row)
obuf = obuf + t.get_string(sortby='Package')
elif params['query_type'] == 'files':
header = ['Filename', 'Size']
t = PrettyTable(header)
t.set_style(PLAIN_COLUMNS)
t.align = 'l'
for el in payload['content']:
row = [el['filename'], el['size']]
t.add_row(row)
obuf = obuf + t.get_string(sortby='Size', reversesort=True)
elif params['query_type'] in ['npm', 'gem', 'python']:
header = ['Package', 'Version', 'Location']
t = PrettyTable(header)
t.set_style(PLAIN_COLUMNS)
t.align = 'l'
for el in payload['content']:
row = [el['package'], el['version'], el['location']]
t.add_row(row)
obuf = obuf + t.get_string(sortby='Package')
elif params['query_type'] in ['java']:
header = ['Package', 'Specification-Version', 'Implementation-Version', 'Location']
t = PrettyTable(header)
t.set_style(PLAIN_COLUMNS)
t.align = 'l'
for el in payload['content']:
row = [el['package'], el['specification-version'], el['implementation-version'], el['location']]
t.add_row(row)
obuf = obuf + t.get_string(sortby='Package')
elif params['query_type'] in ['manifest', 'dockerfile', 'docker_history']:
try:
]
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')))
field_name = field
if normalize_field_names:
if field_name not in mixed_case_fields:
field_name = field_name.lower()
field_name = field_name.replace(" ", "_").replace("-", "_")
if isinstance(o, dict):
data = o.get(field_name, "")
else:
data = getattr(o, field_name, "")
row.append(data)
pt.add_row(row)
if not print_border or not print_header:
pt.set_style(prettytable.PLAIN_COLUMNS)
pt.left_padding_width = 0
pt.right_padding_width = 1
table_body = pt.get_string(header=print_header,
border=print_border,
**kwargs) + "\n"
table_header = ""
if table_label:
table_width = table_body.index("\n")
table_header = make_table_header(table_label, table_width)
table_header += "\n"
if six.PY3:
if table_header:
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')
latest_records[fulltag] = image_record
else:
lasttagts = dateutil.parser.parse(latest_tag_details[fulltag]['created_at'])
if tagts >= lasttagts:
latest_tag_details[fulltag] = image_detail
latest_records[fulltag] = image_record
filtered_records = list(latest_records.values())
if params['full']:
header = ['Full Tag', 'Image Digest', 'Analysis Status', 'Image ID']
else:
header = ['Full Tag', 'Image Digest', 'Analysis Status']
t = PrettyTable(header)
t.set_style(PLAIN_COLUMNS)
t.align = 'l'
add_rows = []
for image_record in filtered_records:
for image_detail_record in image_record['image_detail']:
image_detail = copy.deepcopy(image_detail_record)
dockerpresent = imageId = fulltag = registy = "None"
dockerfile = image_detail.pop('dockerfile', None)
if dockerfile:
dockerpresent = "Present"
imageId = image_detail.pop('imageId', "None")
fulltag = image_detail.pop('registry', "None") + "/" + image_detail.pop('repo', "None") + ":" + image_detail.pop('tag', "None")
#registry = image_detail.pop('registry', "None")
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))
async def print_results_tabular(results, *args, **kwargs):
sort_key = kwargs["sort"] if "sort" in kwargs else "hostname"
if results:
results.sort(key=lambda x: getattr(x, sort_key))
else:
results = []
table = PrettyTable()
table.set_style(PLAIN_COLUMNS)
table.right_padding_width = 2
columns = OrderedDict(
[
(
"ID",
lambda result: (
colored(result.node_id, "magenta")
if result.is_metadata
else result.node_id
),
),
(
"NAME",
lambda result: colored(result.hostname, attrs=["bold"])
if not result.uptime
def prettyPrintPackages(packages):
pt = PrettyTable()
pt.set_style(PLAIN_COLUMNS)
pt.header = False
terminalWidth, _ = getTerminalSize()
numberOfColumns = terminalWidth / (len(max(packages, key=len)) + 3)
rest = terminalWidth % (len(max(packages, key=len)) + 3)
headers = []
for i in range(numberOfColumns):
headers.append(str(i))
pt.field_names = headers
for i in range(numberOfColumns):
pt.align[str(i)] = "l"
i = 0
while i < len(packages):
row = []
for j in range(0, numberOfColumns):
try:
row.append(" [" + str(i) +"]" + packages[i])
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