Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle_fs_status(self, cmd):
output = ""
fs_filter = cmd.get('fs', None)
mds_versions = defaultdict(list)
fsmap = self.get("fs_map")
for filesystem in fsmap['filesystems']:
if fs_filter and filesystem['mdsmap']['fs_name'] != fs_filter:
continue
rank_table = PrettyTable(
("Rank", "State", "MDS", "Activity", "dns", "inos"),
hrules=prettytable.FRAME
)
mdsmap = filesystem['mdsmap']
client_count = 0
for rank in mdsmap["in"]:
up = "mds_{0}".format(rank) in mdsmap["up"]
if up:
gid = mdsmap['up']["mds_{0}".format(rank)]
info = mdsmap['info']['gid_{0}'.format(gid)]
dns = self.get_latest("mds", info['name'], "mds_mem.dn")
inos = self.get_latest("mds", info['name'], "mds_mem.ino")
if rank == 0:
client_count = self.get_latest("mds", info['name'],
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))
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))
def format_nested_list_of_dict(l, column_names):
pt = prettytable.PrettyTable(caching=False, print_empty=False,
header=True, hrules=prettytable.FRAME,
field_names=column_names)
for d in l:
pt.add_row(list(map(lambda k: d[k], column_names)))
return pt.get_string()
header = ['Bin Id', 'Bin size (Mbp)']
for bamId in sortedBamIds:
header += [bamId + ': mapped reads']
header += [bamId + ': % mapped reads']
header += [bamId + ': % binned populations']
header += [bamId + ': % community']
if bTabTable:
print('\t'.join(header))
else:
pTable = prettytable.PrettyTable(header)
pTable.float_format = '.2'
pTable.align = 'c'
pTable.align[header[0]] = 'l'
pTable.hrules = prettytable.FRAME
pTable.vrules = prettytable.NONE
for binId in sortedBinIds:
row = [binId]
row += [float(binSize[binId]) / 1e6]
for bamId in sortedBamIds:
row += [readsMappedToBin[binId][bamId]]
row += [perMappedReads[binId][bamId] * 100.0]
if DefaultValues.UNBINNED in perMappedReads:
unbinnedPercentage = perMappedReads[DefaultValues.UNBINNED][bamId]
else:
unbinnedPercentage = 0
if binId == DefaultValues.UNBINNED:
def format_table(table, hrules=False, align="l"):
if not hrules:
hrules = prettytable.FRAME
else:
hrules = prettytable.ALL
header = [click.style(x, fg="red", bold=True) for x in table[0]]
t = prettytable.PrettyTable(header, hrules=hrules)
t.align = align
for index, row in enumerate(table[1:]):
row = [str(x) for x in row]
row[0] = click.style(row[0], fg="yellow")
t.add_row(row)
return t
def table(columns, data, hrules=True):
"""Print a table"""
columns = map(lambda x: colorize(x, attrs="bold"), columns)
table = prettytable.PrettyTable(
hrules=prettytable.ALL if hrules else prettytable.FRAME, field_names=columns
)
for row in data:
table.add_row(row)
table.align = "l"
print(table)
descriptors = query['performance_counter_descriptors']
if query == self.RBD_IMAGE_ID_QUERY:
column_names = ["pool_id", "rbd image_id"]
else:
column_names = ["client_id"]
for d in descriptors:
desc = d
if d in ['write_bytes', 'read_bytes']:
desc += '/sec'
elif d in ['write_latency', 'read_latency']:
desc += '(msec)'
column_names.append(desc)
table = prettytable.PrettyTable(tuple(column_names),
hrules=prettytable.FRAME)
for c in res['counters']:
if query == self.RBD_IMAGE_ID_QUERY:
row = [c['k'][0][0], c['k'][1][1]]
else:
row = [c['k'][0][0]]
counters = c['c']
for i in range(len(descriptors)):
if descriptors[i] in ['write_bytes', 'read_bytes']:
bps = counters[i][0] / (now - last_update)
row.append(get_human_readable(bps))
elif descriptors[i] in ['write_latency', 'read_latency']:
lat = 0
if counters[i][1] > 0:
lat = 1.0 * counters[i][0] / counters[i][1] / 1000000
row.append("%.2f" % lat)
else:
def format_nested_list_of_dict(l, column_names):
pt = prettytable.PrettyTable(caching=False, print_empty=False,
header=True, hrules=prettytable.FRAME,
field_names=column_names)
# Sort by values of first column
if l is not None:
l.sort(key=lambda k: k.get(column_names[0]))
for d in l:
pt.add_row(list(map(lambda k: d[k], column_names)))
return pt.get_string()