Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def print_string(results_dict):
"""
creates an easy printable string from a results dict
"""
max_hlen = 42
hlen = 7 + len(' '.join(list(results_dict)))
maxlen = (max_hlen-7) // len(results_dict) -2
table = prettytable.PrettyTable(header=True, vrules=prettytable.NONE)
table.border = False
table.padding_width = 1
cv = True if type(results_dict[list(results_dict.keys())[0]][0]) is list else False
if cv:
table.add_column('', ['VAcc', 'V-F1', 'TAcc', 'T-F1'])
else:
table.add_column('', ['CAcc', 'C-F1', 'RAcc', 'R-F1'])
for exp in results_dict:
res = results_dict[exp]
scores = []
if cv:
for fold in res:
scores.append(fold[:4])
scores = np.mean(scores,0)
else:
def testHrulesNone(self):
default = self.x.get_string()
override = self.x.get_string(hrules=NONE)
self.assertTrue(default != override)
for match in rule.matches:
if match.name == 'comment' and match.comment == container.name:
dport = [m.dport for m in rule.matches if m.name in ['tcp', 'udp']][0]
to_ip, to_port = rule.target.to_destination.split(':')
dnat_rules.append((rule.protocol, (rule.dst, dport), (to_ip, to_port)))
except iptc.IPTCError:
container.logger.warn('An arror occured searching the netfiler rules')
return dnat_rules
if containers == None:
containers = self.containers
table = prettytable.PrettyTable(['Def.', 'Name', 'FQDN', 'State', 'IPs', 'Ports'])
table.align = 'l'
table.hrules = prettytable.HEADER
table.vrules = prettytable.NONE
for container in containers:
defined = container.defined
name = container.name
state = container.state
fqdn = '' if 'fqdn' not in container.yml else container.yml['fqdn']
ips = '-'
if container.running:
ips = ','.join(container.get_ips())
dnat_rules = get_netfiler_rules(container)
ports = '\n'.join(['%s:%s->%s/%s' % (dip.split('/')[0], dport, to_port, proto) for proto, (dip, dport), (to_ip, to_port) in dnat_rules])
table.add_row(['%s%s%s' % (container.color, x, Fore.RESET) for x in [defined, name, fqdn, state, ips, ports]])
print(table)
def _get_pretty_table(self, fields):
"""! @brief Returns a PrettyTable object with formatting options set."""
pt = prettytable.PrettyTable(fields)
pt.align = 'l'
pt.header = not self._args.no_header
pt.border = True
pt.hrules = prettytable.HEADER
pt.vrules = prettytable.NONE
return pt
table_generator = OrderedDict([
("ID", lambda x: x.id),
("name", lambda x: x.name),
("host", lambda x: x.hostname),
("active", lambda x: x.active),
("tasks", lambda x: x.task_count),
("cpu", lambda x: x.cpu_allocated),
("mem", lambda x: x.mem_allocated),
("disk", lambda x: x.disk_allocated),
])
tb = prettytable.PrettyTable(
[x.upper() for x in table_generator.keys()],
border=False,
max_table_width=term.width,
hrules=prettytable.NONE,
vrules=prettytable.NONE,
left_padding_width=0,
right_padding_width=1
)
def format_row(framework):
return [fn(framework) for fn in table_generator.values()]
for framework in MASTER.frameworks(active_only=not args.inactive):
tb.add_row(format_row(framework))
if tb.rowcount == 0:
cli.header('You have no frameworks')
else:
print(tb)
def format_no_tty(table):
"""Converts SoftLayer.CLI.formatting.Table instance to a prettytable."""
for i, row in enumerate(table.rows):
for j, item in enumerate(row):
table.rows[i][j] = format_output(item, fmt='raw')
ptable = table.prettytable()
for col in table.columns:
ptable.align[col] = 'l'
ptable.hrules = prettytable.NONE
ptable.border = False
ptable.header = False
ptable.left_padding_width = 0
ptable.right_padding_width = 2
return ptable
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:
row += ['NA']
# cpus_limit
("cpu", lambda x: x.cpu_limit),
# mem_rss / mem_limit
("%mem", get_memory),
# executor.name
("command", lambda x: x.command),
("user", lambda x: x.user),
# task_id
("id", lambda x: x["id"]),
])
tb = prettytable.PrettyTable(
[x.upper() for x in table_generator.keys()],
border=False,
max_table_width=term.width,
hrules=prettytable.NONE,
vrules=prettytable.NONE,
left_padding_width=0,
right_padding_width=1
)
def format_row(task):
try:
return [fn(task) for fn in table_generator.values()]
except exceptions.SlaveDoesNotExist:
return None
for row in parallel.by_slave(
format_row,
MASTER.tasks(active_only=(not args.inactive), fltr=args.task)):
if row:
tb.add_row(row)
table = PrettyTable()
table.field_names = output_fields
table.align = 'l'
table.border = (args.format == 'markdown' or args.format == 'rst' or
args.format == 'confluence' or args.format == 'json')
table.header = True
if args.format == 'markdown':
table.junction_char = '|'
table.hrules = RULE_HEADER
elif args.format == 'rst':
table.junction_char = '+'
table.hrules = RULE_ALL
elif args.format == 'confluence':
table.junction_char = '|'
table.hrules = RULE_NONE
elif args.format == 'json':
table = JsonPrettyTable(table.field_names)
elif args.format == 'json-license-finder':
table = JsonLicenseFinderTable(table.field_names)
elif args.format == 'csv':
table = CSVPrettyTable(table.field_names)
elif args.format == 'plain-vertical':
table = PlainVerticalTable(table.field_names)
return table
("ID", lambda x: x.id),
("name", lambda x: x.name),
("host", lambda x: x.hostname),
("active", lambda x: x.active),
("tasks", lambda x: x.task_count),
("cpu", lambda x: x.cpu_allocated),
("mem", lambda x: x.mem_allocated),
("disk", lambda x: x.disk_allocated),
])
tb = prettytable.PrettyTable(
[x.upper() for x in table_generator.keys()],
border=False,
max_table_width=term.width,
hrules=prettytable.NONE,
vrules=prettytable.NONE,
left_padding_width=0,
right_padding_width=1
)
def format_row(framework):
return [fn(framework) for fn in table_generator.values()]
for framework in MASTER.frameworks(active_only=not args.inactive):
tb.add_row(format_row(framework))
if tb.rowcount == 0:
cli.header('You have no frameworks')
else:
print(tb)