本文整理匯總了Python中terminaltables.DoubleTable方法的典型用法代碼示例。如果您正苦於以下問題:Python terminaltables.DoubleTable方法的具體用法?Python terminaltables.DoubleTable怎麽用?Python terminaltables.DoubleTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類terminaltables
的用法示例。
在下文中一共展示了terminaltables.DoubleTable方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def main():
"""Main function."""
title = 'Jetta SportWagen'
# AsciiTable.
table_instance = AsciiTable(TABLE_DATA, title)
table_instance.justify_columns[2] = 'right'
print(table_instance.table)
print()
# SingleTable.
table_instance = SingleTable(TABLE_DATA, title)
table_instance.justify_columns[2] = 'right'
print(table_instance.table)
print()
# DoubleTable.
table_instance = DoubleTable(TABLE_DATA, title)
table_instance.justify_columns[2] = 'right'
print(table_instance.table)
print()
示例2: get_table
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def get_table(self, arch, pattern, colored=False, verbose=False):
'''
This function is used in sys command (when user want to find a specific syscall)
:param Architecture for syscall table;
:param Searching pattern;
:param Flag for verbose output
:return Return a printable table of matched syscalls
'''
rawtable = self.search(arch, pattern)
if len(rawtable) == 0:
return None
used_hd = self.__fetch_used_headers(rawtable, verbose)
table = [self.__make_colored_row(used_hd, 'yellow,bold', upper=True) if colored else used_hd]
for command in rawtable:
cur_tb_field = []
for hd in used_hd:
value = command[hd]
cur_tb_field.append(self.__make_colored_field(value, hd, verbose=verbose))
table.append(cur_tb_field)
return DoubleTable(table)
示例3: make_table
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def make_table(result):
table_data = [['S.No', 'Name', 'Rating']]
for s_no,res in enumerate(result,1):
row = []
row.extend((Color('{autoyellow}' + str(s_no) + '.' + '{/autoyellow}'),
Color('{autogreen}' + res[0] + '{/autogreen}'),
Color('{autoyellow}' + res[1] + '{/autoyellow}')))
table_data.append(row)
table_instance = DoubleTable(table_data)
table_instance.inner_row_border = True
print(table_instance.table)
print()
示例4: make_table
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def make_table(team1,team2=''):
data=scrape()
table_data=[['Match','Series','Date','Month','Time']]
for i in data[:]:
row=[]
if team1.strip(' ') in i.get('desc') and team2.strip(' ') in i.get('desc') :
row.extend((Color('{autoyellow}'+i.get('desc')+'{/autoyellow}'),Color('{autocyan}'+i.get('srs')[5:]+'{/autocyan}'),Color('{autored}'+i.get('ddt')+'{/autored}'),Color('{autogreen}'+i.get('mnth_yr')+'{/autogreen}'),Color('{autoyellow}'+i.get('tm')+'{/autoyellow}')))
table_data.append(row)
table_instance = DoubleTable(table_data)
table_instance.inner_row_border = True
print(table_instance.table)
print()
示例5: print_result
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def print_result(result):
tableData = []
tableHead = ["Title(name)", "City", "Link / Meetup / Date"]
tableData.append(tableHead)
prevTitle = None
for row in result:
name = "(" + row[0] + ")"
title = colored(row[1], 'green')
city = colored(row[2], 'cyan')
try:
info = row[3:]
except BaseException:
info = None
if len(info) == 0:
tableData.append([title, city, ''])
tableData.append([name, "", ''])
else:
meetup = info[0]
date = info[1]
link = info[2]
date = colored(date, 'yellow')
if title == prevTitle:
tableData.append(['', '', date])
tableData.append([name, '', meetup])
tableData.append(['', '', link])
else:
tableData.append([title, city, date])
tableData.append([name, '', meetup])
tableData.append(['', '', link])
prevTitle = title
print(DoubleTable(tableData).table)
示例6: fetch_table
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def fetch_table(self, pattern, os='linux', arch=X86_32, count=0):
cprint('\n<magenta,bold>[*]</> Connecting to shell-storm.org...')
rowtable = self.fetch(pattern, os, arch, count, True)
return DoubleTable(rowtable)
示例7: archs
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def archs(self):
filtered = []
table = []
archs = sorted(list(self.executor.get_archs()))
cur = [archs[0]]
loc_max = MN_INF
for pos in range(1, len(archs)):
if self.__is_similar(archs[pos], archs[pos-1]):
cur.append(archs[pos])
else:
loc_max = max(loc_max, len(cur))
filtered.append(['<cyan>{}</>'.format(x) for x in cur])
cur = [archs[pos]]
filtered.append(['<cyan>{}</>'.format(x) for x in cur])
loc_max = max(loc_max, len(cur))
table.append(['\r'] * len(filtered))
for i in range(loc_max):
cur_row = []
for j in range(len(filtered)):
cur_row.append('' if i >= len(filtered[j]) else make_colors(filtered[j][i]))
table.append(cur_row)
rtable = DoubleTable(table)
rtable.inner_heading_row_border = False
return rtable.table
示例8: test_single_line
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def test_single_line():
"""Test single-lined cells."""
table_data = [
['Name', 'Color', 'Type'],
['Avocado', 'green', 'nut'],
['Tomato', 'red', 'fruit'],
['Lettuce', 'green', 'vegetable'],
['Watermelon', 'green'],
[],
]
table = DoubleTable(table_data, 'Example')
table.inner_footing_row_border = True
table.justify_columns[0] = 'left'
table.justify_columns[1] = 'center'
table.justify_columns[2] = 'right'
actual = table.table
expected = (
u'\u2554Example\u2550\u2550\u2550\u2550\u2550\u2566\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2566\u2550\u2550'
u'\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\n'
u'\u2551 Name \u2551 Color \u2551 Type \u2551\n'
u'\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256c\u2550\u2550\u2550\u2550'
u'\u2550\u2550\u2550\u256c\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563\n'
u'\u2551 Avocado \u2551 green \u2551 nut \u2551\n'
u'\u2551 Tomato \u2551 red \u2551 fruit \u2551\n'
u'\u2551 Lettuce \u2551 green \u2551 vegetable \u2551\n'
u'\u2551 Watermelon \u2551 green \u2551 \u2551\n'
u'\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256c\u2550\u2550\u2550\u2550'
u'\u2550\u2550\u2550\u256c\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563\n'
u'\u2551 \u2551 \u2551 \u2551\n'
u'\u255a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2569\u2550\u2550\u2550\u2550'
u'\u2550\u2550\u2550\u2569\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255d'
)
assert actual == expected
示例9: test_windows_screenshot
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def test_windows_screenshot(tmpdir):
"""Test on Windows in a new console window. Take a screenshot to verify it works.
:param tmpdir: pytest fixture.
"""
script = tmpdir.join('script.py')
command = [sys.executable, str(script)]
screenshot = PROJECT_ROOT.join('test_double_table.png')
if screenshot.check():
screenshot.remove()
# Generate script.
script_template = dedent(u"""\
from __future__ import print_function
import os, time
from colorclass import Color, Windows
from terminaltables import DoubleTable
Windows.enable(auto_colors=True)
stop_after = time.time() + 20
table_data = [
[Color('{b}Name{/b}'), Color('{b}Color{/b}'), Color('{b}Misc{/b}')],
['Avocado', Color('{autogreen}green{/fg}'), 100],
['Tomato', Color('{autored}red{/fg}'), 0.5],
['Lettuce', Color('{autogreen}green{/fg}'), None],
]
print(DoubleTable(table_data).table)
print('Waiting for screenshot_until_match()...')
while not os.path.exists(r'%s') and time.time() < stop_after:
time.sleep(0.5)
""")
script_contents = script_template % str(screenshot)
script.write(script_contents.encode('utf-8'), mode='wb')
# Setup expected.
sub_images = [str(p) for p in HERE.listdir('sub_double_*.bmp')]
assert sub_images
# Run.
with RunNewConsole(command) as gen:
screenshot_until_match(str(screenshot), 15, sub_images, 1, gen)
示例10: print_fit_parameters
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def print_fit_parameters(self):
"""
Prints a copy of the current state counts.
Used for convenient checking in a command line environment.
For dictionaries containing the raw values, use the `n_*` attributes.
:return:
"""
# create copies to avoid editing
n_initial = copy.deepcopy(self.n_initial)
n_emission = copy.deepcopy(self.n_emission)
n_transition = copy.deepcopy(self.n_transition)
# make nested lists for clean printing
initial = [[str(s)] + [str(n_initial[s])] for s in self.states]
initial.insert(0, ["S_i", "Y_0"])
emissions = [
[str(s)] + [str(n_emission[s][e]) for e in self.emissions]
for s in self.states
]
emissions.insert(0, ["S_i \\ E_i"] + list(map(str, self.emissions)))
transitions = [
[str(s1)] + [str(n_transition[s1][s2]) for s2 in self.states]
for s1 in self.states
]
transitions.insert(0, ["S_i \\ S_j"] + list(map(lambda x: str(x), self.states)))
# format tables
ti = terminaltables.DoubleTable(initial, "Starting state counts")
te = terminaltables.DoubleTable(emissions, "Emission counts")
tt = terminaltables.DoubleTable(transitions, "Transition counts")
ti.padding_left = 1
ti.padding_right = 1
te.padding_left = 1
te.padding_right = 1
tt.padding_left = 1
tt.padding_right = 1
ti.justify_columns[0] = "right"
te.justify_columns[0] = "right"
tt.justify_columns[0] = "right"
# print tables
print("\n")
print(ti.table)
print("\n")
print(te.table)
print("\n")
print(tt.table)
print("\n")
#
return None
示例11: print_probabilities
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def print_probabilities(self):
"""
Prints a copy of the current probabilities.
Used for convenient checking in a command line environment.
For dictionaries containing the raw values, use the `p_*` attributes.
:return:
"""
# create copies to avoid editing
p_initial = copy.deepcopy(self.p_initial)
p_emission = copy.deepcopy(self.p_emission)
p_transition = copy.deepcopy(self.p_transition)
# convert to nested lists for clean printing
p_initial = [[str(s)] + [str(round(p_initial[s], 3))] for s in self.states]
p_emission = [
[str(s)] + [str(round(p_emission[s][e], 3)) for e in self.emissions]
for s in self.states
]
p_transition = [
[str(s1)] + [str(round(p_transition[s1][s2], 3)) for s2 in self.states]
for s1 in self.states
]
p_initial.insert(0, ["S_i", "Y_0"])
p_emission.insert(0, ["S_i \\ E_j"] + [str(e) for e in self.emissions])
p_transition.insert(0, ["S_i \\ E_j"] + [str(s) for s in self.states])
# format tables
ti = terminaltables.DoubleTable(p_initial, "Starting state probabilities")
te = terminaltables.DoubleTable(p_emission, "Emission probabilities")
tt = terminaltables.DoubleTable(p_transition, "Transition probabilities")
te.padding_left = 1
te.padding_right = 1
tt.padding_left = 1
tt.padding_right = 1
te.justify_columns[0] = "right"
tt.justify_columns[0] = "right"
# print tables
print("\n")
print(ti.table)
print("\n")
print(te.table)
print("\n")
print(tt.table)
print("\n")
#
return None
示例12: analyze_bucket
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def analyze_bucket(bucket):
client = boto3.client('s3')
bucket_acl = client.get_bucket_acl(Bucket=bucket)
permission = []
for grants in bucket_acl['Grants']:
if ('URI' in grants['Grantee']) and ('AllUser' in grants['Grantee']['URI']):
permission.append(grants['Permission'])
globalListAccess = 'NO'
globalWriteAccess = 'NO'
points=0
if len(permission) >= 1:
if len(permission) == 1:
if permission[0] == 'READ':
globalListAccess = 'YES'
points+=1
if permission[0] == 'WRITE':
globalWriteAccess = 'YES'
points+=1
if len(permission) > 1:
if permission[0] == 'READ':
globalListAccess = 'YES'
points+=1
if permission[0] == 'WRITE':
globalWriteAccess = 'YES'
points+=1
if permission[1] == 'READ':
globalListAccess = 'YES'
points+=1
if permission[1] == 'WRITE':
globalWriteAccess = 'YES'
points+=1
if globalListAccess == 'YES' or globalWriteAccess == 'YES':
table_data = [
['BucketName', 'GlobalListAccess', 'GlobalWriteAccess'],
[bucket, globalListAccess, globalWriteAccess],
]
table = DoubleTable(table_data)
table.inner_row_border = True
print(table.table)
api.Metric.send(
metric="bucket.exposed",
host="aws.s3.bucket." + bucket,
points=points, #0=ok, 1=read exposed, 2=write exposed
tags=["aws","s3","s3permissions"]
)
示例13: get_lab_info
# 需要導入模塊: import terminaltables [as 別名]
# 或者: from terminaltables import DoubleTable [as 別名]
def get_lab_info(self, lab_hash=None, machine_name=None, all_users=False):
user_name = utils.get_current_user_name() if not all_users else None
machines = self.docker_machine.get_machines_by_filters(lab_hash=lab_hash,
machine_name=machine_name,
user=user_name
)
if not machines:
if not lab_hash:
raise Exception("No machines running.")
else:
raise Exception("Lab is not started.")
machines = sorted(machines, key=lambda x: x.name)
machine_streams = {}
for machine in machines:
machine_streams[machine] = machine.stats(stream=True, decode=True)
table_header = ["LAB HASH", "USER", "MACHINE NAME", "STATUS", "CPU %", "MEM USAGE / LIMIT", "MEM %", "NET I/O"]
stats_table = DoubleTable([])
stats_table.inner_row_border = True
while True:
machines_data = [
table_header
]
for (machine, machine_stats) in machine_streams.items():
try:
result = next(machine_stats)
except StopIteration:
continue
stats = self._get_aggregate_machine_info(result)
machines_data.append([machine.labels['lab_hash'],
machine.labels['user'],
machine.labels["name"],
machine.status,
stats["cpu_usage"],
stats["mem_usage"],
stats["mem_percent"],
stats["net_usage"]
])
stats_table.table_data = machines_data
yield "TIMESTAMP: %s" % datetime.now() + "\n\n" + stats_table.table