本文整理汇总了Python中texttable.Texttable.set_deco方法的典型用法代码示例。如果您正苦于以下问题:Python Texttable.set_deco方法的具体用法?Python Texttable.set_deco怎么用?Python Texttable.set_deco使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类texttable.Texttable
的用法示例。
在下文中一共展示了Texttable.set_deco方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def handle(self, explain, default_logging, verbosity):
processors = []
processors.append(run.load_loader())
processors.extend(run.load_steps(None))
processors.extend(run.load_alerts(None))
report = qa.qa_report(
processors, default_logging=default_logging, verbosity=verbosity)
if verbosity > 1:
print(report.full_output())
table = Texttable(max_width=0)
table.set_deco(Texttable.BORDER | Texttable.HEADER | Texttable.VLINES)
table.header(("Indicator", "Value"))
for k, v in report.resume().items():
pv = v if isinstance(v, str) else str(v)
table.add_row([k, pv])
print("\n**** RESUME ****")
print(table.draw())
print("")
if explain:
print("- QA Index (QAI):\n {}".format(
report.qai.__doc__.strip()))
print("")
print(
"- QA Score (QAS) is a cuantitave scale based on rounded QAI:")
print(" " + ", ".join(
["QAS(~{k}%)={v}".format(v=v, k=k*10)
for k, v in sorted(qa.SCORE_COMMENTS.items())]))
print("")
示例2: print_price_data
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def print_price_data(data):
# Current BTC Price
# --------------------
print '\n%s' % colorize('CaVirtex Market\n---------------', colors.CYAN)
status_color = colors.GREEN if data['net'] > 0 else colors.RED
print '\n%s' % colorize('Price', colors.BLUE)
print '\n%s' % colorize('$%.2f CAD/BTC' % data['current_price'], status_color)
# Latest Trades
# ----------------
print '\n%s\n' % colorize('Latest Trades', colors.BLUE)
trades_table = Texttable()
trades_table.set_deco(Texttable.HEADER)
trades_table.set_precision(2)
trades_table.set_cols_dtype(['f', 'f', 'f', 't'])
trades_table.add_rows(data['latest_trades'])
print trades_table.draw()
# Investment Returns
# ---------------------
print '\n%s' % colorize('Your Investment', colors.BLUE)
print '\nNet: %s' % colorize('$%.2f CAD' % data['net'], status_color)
print '\nVOI: %s' % colorize('$%.2f CAD' % data['voi'], status_color)
print '\nROI: %s' % colorize('%.2f%%' % data['roi'], status_color)
示例3: schedule
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def schedule(self, label="default", *argvs, **kwargs):
simulate = kwargs.get("simulate")
reserver = kwargs.get("reserve")
fullInfo = kwargs.get("fullInfo")
if kwargs.get("list"):
tp = TaskPeriod.objects.all()
table = Texttable()
table.set_deco(Texttable.HEADER)
table.header(["Id", "Title", "Label", "Schedule"])
for it in tp:
table.add_row([it.id, it.title, it.label, it.cron])
print(table.draw())
if kwargs.get("template_id"):
template_ids = kwargs.get("template_id")
logger.debug("Schedule template id %s" % template_ids)
filter = {"id__in": template_ids}
self.scheduleByJobTemplates(
filter, label, fullInfo, simulate, reserver)
if kwargs.get("schedule_label"):
period_label = kwargs.get("schedule_label")
filter = {"schedule__label__in": period_label, "is_enable": True}
if not label:
label = period_label
self.scheduleByJobTemplates(
filter, "".join(label), fullInfo, simulate, reserver)
示例4: print_diff_as_table
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def print_diff_as_table(self, include=None, exclude=None,
deco_border=False, deco_header=False,
deco_hlines=False, deco_vlines=False):
diffdict = self.diff(include, exclude)
if not diffdict:
return
from texttable import Texttable
table = Texttable()
deco = 0
if deco_border:
deco |= Texttable.BORDER
if deco_header:
deco |= Texttable.HEADER
if deco_hlines:
deco |= Texttable.HLINES
if deco_vlines:
deco |= Texttable.VLINES
table.set_deco(deco)
sortedkey = sorted(diffdict)
table.add_rows(
[[''] + self._name] +
[[keystr] + [self._getrepr(diffdict[keystr], name)
for name in self._name]
for keystr in sortedkey]
)
print table.draw()
示例5: print_table
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def print_table(prefix, items):
table = Texttable(max_width=160)
table.set_deco(Texttable.HEADER)
table.header(['%s_id' % prefix, '%s_updated' % prefix, '%s_fk' % prefix])
for key, values in items.iteritems():
table.add_row([key, values.get('updated'), values.get('opposite_id')])
print table.draw() + "\n"
示例6: getDescOfEachNoSystemTable
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def getDescOfEachNoSystemTable(self):
'''
returns a String for print
'''
outputString = ""
logging.debug("Getting all no system tables accessible with the current user")
tablesAccessible = self.__execQuery__(query=self.REQ_GET_ALL_NO_SYSTEM_TABLES, ld=['owner', 'table_name'])
if isinstance(tablesAccessible,Exception):
logging.warning("Impossible to execute the request '{0}': {1}".format(self.REQ_GET_ALL_NO_SYSTEM_TABLES, tablesAccessible.generateInfoAboutError(self.REQ_GET_ALL_NO_SYSTEM_TABLES)))
return ""
else:
nbTables = len(tablesAccessible)
colNb = nbTables
if colNb>0 :
pbar,currentColNum = self.getStandardBarStarted(colNb), 0
for aTable in tablesAccessible:
if colNb>0:
currentColNum += 1
pbar.update(currentColNum)
request = self.REQ_GET_COLUMNS_FOR_TABLE.format(aTabl<e['table_name'], aTable['owner'])
columnsAndTypes = self.__execQuery__(query=request, ld=['column_name', 'data_type'])
if isinstance(columnsAndTypes,Exception):
logging.warning("Impossible to execute the request '{0}': {1}".format(request, columnsAndTypes.generateInfoAboutError(request)))
outputString += "\n[+] {0}.{1} ({2}/{3})\n".format(aTable['owner'], aTable['table_name'], currentColNum, colNb)
resultsToTable = [('column_name', 'data_type')]
for aLine in columnsAndTypes:
resultsToTable.append((aLine['column_name'], aLine['data_type']))
table = Texttable(max_width=getScreenSize()[0])
table.set_deco(Texttable.HEADER)
table.add_rows(resultsToTable)
outputString += table.draw()
outputString += '\n'
if colNb>0 : pbar.finish()
return outputString
示例7: top
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def top(db):
count_query = '''
SELECT count(*)
FROM commands
WHERE
timestamp > ?
'''
percentage = 100 / float(execute_scalar(db, count_query, TIMESTAMP))
query = '''
SELECT count(*) AS counts, command
FROM commands
WHERE timestamp > ?
GROUP BY command
ORDER BY counts DESC
LIMIT 20
'''
table = Texttable()
table.set_deco(Texttable.HEADER)
table.set_cols_align(('r', 'r', 'l'))
table.header(('count', '%', 'command'))
for row in db.execute(query, (TIMESTAMP,)):
table.add_row((row[0], int(row[0]) * percentage, row[1]))
print table.draw()
示例8: output_table_list
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def output_table_list(tables):
terminal_size = get_terminal_size()[1]
widths = []
for tab in tables:
for i in range(0, len(tab.columns)):
current_width = len(tab.columns[i].label)
if len(widths) < i + 1:
widths.insert(i, current_width)
elif widths[i] < current_width:
widths[i] = current_width
for row in tab.data:
current_width = len(resolve_cell(row, tab.columns[i].accessor))
if current_width > widths[i]:
widths[i] = current_width
if sum(widths) != terminal_size:
widths[-1] = terminal_size - sum(widths[:-1]) - len(widths) * 3
for tab in tables:
table = Texttable(max_width=terminal_size)
table.set_cols_width(widths)
table.set_deco(0)
table.header([i.label for i in tab.columns])
table.add_rows([[AsciiOutputFormatter.format_value(resolve_cell(row, i.accessor), i.vt) for i in tab.columns] for row in tab.data], False)
six.print_(table.draw() + "\n")
示例9: list_instances
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def list_instances():
table = Texttable( max_width=0 )
table.set_deco( Texttable.HEADER )
table.set_cols_dtype( [ 't', 't', 't', 't', 't', 't', 't', 't' ] )
table.set_cols_align( [ 'l', 'l', 'l', 'l', 'l', 'l', 'l', 't' ] )
if not options.no_header:
### using add_row, so the headers aren't being centered, for easier grepping
table.add_row(
[ '# id', 'Name', 'Type', 'Zone', 'Group', 'State', 'Root', 'Volumes' ] )
instances = get_instances()
for i in instances:
### XXX there's a bug where you can't get the size of the volumes, it's
### always reported as None :(
volumes = ", ".join( [ ebs.volume_id for ebs in i.block_device_mapping.values()
if ebs.delete_on_termination == False ] )
### you can use i.region instead of i._placement, but it pretty
### prints to RegionInfo:us-east-1. For now, use the private version
### XXX EVERY column in this output had better have a non-zero length
### or texttable blows up with 'width must be greater than 0' error
table.add_row( [ i.id, i.tags.get( 'Name', ' ' ), i.instance_type,
i._placement , i.groups[0].name, i.state,
i.root_device_type, volumes or '-' ] )
#PP.pprint( i.__dict__ )
### table.draw() blows up if there is nothing to print
if instances or not options.no_header:
print table.draw()
示例10: output_object
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def output_object(obj):
table = Texttable(max_width=get_terminal_size()[1])
table.set_deco(0)
for item in obj:
table.add_row(['{0} ({1})'.format(item.descr, item.name), AsciiOutputFormatter.format_value(item.value, item.vt)])
print(table.draw())
示例11: output_table
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def output_table(tab):
max_width = get_terminal_size()[1]
table = Texttable(max_width=max_width)
table.set_deco(0)
table.header([i.label for i in tab.columns])
widths = []
number_columns = len(tab.columns)
remaining_space = max_width
# set maximum column width based on the amount of terminal space minus the 3 pixel borders
max_col_width = (remaining_space - number_columns * 3) / number_columns
for i in range(0, number_columns):
current_width = len(tab.columns[i].label)
tab_cols_acc = tab.columns[i].accessor
max_row_width = max(
[len(str(resolve_cell(row, tab_cols_acc))) for row in tab.data ]
)
current_width = max_row_width if max_row_width > current_width else current_width
if current_width < max_col_width:
widths.insert(i, current_width)
# reclaim space not used
remaining_columns = number_columns - i - 1
remaining_space = remaining_space - current_width - 3
if remaining_columns != 0:
max_col_width = (remaining_space - remaining_columns * 3)/ remaining_columns
else:
widths.insert(i, max_col_width)
remaining_space = remaining_space - max_col_width - 3
table.set_cols_width(widths)
table.add_rows([[AsciiOutputFormatter.format_value(resolve_cell(row, i.accessor), i.vt) for i in tab.columns] for row in tab.data], False)
print(table.draw())
示例12: list
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def list ():
api.getCredentials()
log.debug ("Command: List.")
url = "/gists"
gists = api.get(url)
public_count = 0
private_count = 0
table = Texttable(max_width=defaults.max_width)
table.set_deco(Texttable.HEADER | Texttable.HLINES)
table.set_cols_align(["l", "l", "l", "l", "l"])
table.set_cols_width([4, 30, 6, 20, 30])
table.header( ["","Files","Public", "Gist ID", "Description"] )
for (i, gist) in enumerate(gists):
private = False
file_list = ''
for (file, data) in gist['files'].items():
file_list += "'" + file + "' "
if gist['public']:
public_count += 1
else:
private_count += 1
table.add_row( [i+1, file_list, str(gist['public']), gist['id'], gist['description']] )
print table.draw()
print ''
print "You have %i Gists. (%i Private)" % (len(gists), private_count)
示例13: output
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def output(self, data, style=STYLE_PLAIN, filename=None, separator=' '):
"""
Output a dataset with given parameters.
"""
if filename:
xfile = open(filename, 'w')
oldstdout = sys.stdout
sys.stdout = xfile
if style == STYLE_PLAIN:
print separator.join(map(str, data['header']))
elif style == STYLE_TABLE:
table = Texttable()
table.set_deco(Texttable.HEADER)
table.add_row(data['header'])
else:
raise NotImplementedError('Unsupported style')
for aline in data['data']:
if style == STYLE_PLAIN:
print separator.join(map(str, aline))
elif style == STYLE_TABLE:
table.add_row(aline)
else:
raise NotImplementedError('Unsupported style')
if style == STYLE_TABLE:
print table.draw()
if filename: # restore the old value
sys.stdout = oldstdout
示例14: print_histogram
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def print_histogram(self, minimum=5, maximum=100, max_range=10):
table = Texttable()
table.set_deco(Texttable.HEADER)
table.set_cols_align(('l', 'r', 'l'))
table.set_cols_width((10, 3, maximum))
table.header(('range', '#', ''))
start = 0
previous = 0
current_sum = 0
for value, count in sorted(self.histogram.items()):
new_row = \
(value - start) > max_range or \
current_sum >= minimum or \
current_sum + count >= maximum
if new_row:
# passing **locals() is such a hax, don't do this
table.add_row(self._format_histogram_row(**locals()))
start = value
previous = value
current_sum = count
else:
previous = value
current_sum += count
# passing **locals() is such a hax, don't do this
table.add_row(self._format_histogram_row(**locals()))
print table.draw()
示例15: images_to_ascii_table
# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_deco [as 别名]
def images_to_ascii_table(images):
"""Just a method that formats the images to ascii table.
Expects dictionary {host: [images]}
and prints multiple tables
"""
with closing(StringIO()) as out:
for host, values in images.iteritems():
out.write(str(host) + "\n")
t = TextTable()
t.set_deco(TextTable.HEADER)
t.set_cols_dtype(['t'] * 5)
t.set_cols_align(["l"] * 5)
rows = []
rows.append(['Repository', 'Tag', 'Id', 'Created', 'Size'])
for image in values:
rows.append([
image.repository or '<none>',
image.tag or '<none>',
image.id[:12],
time_ago(image.created),
human_size(image.size)
])
t.add_rows(rows)
out.write(t.draw() + "\n\n")
return out.getvalue()