def display_spiders(spiders, click):
table_data = list(TABLE_SPIDERS_MODEL)
for s in spiders:
table_data.append(
[s['id'], s['tags'], s['version'], s['type']]
)
table = SingleTable(table_data)
click.echo(table.table)
python类SingleTable()的实例源码
def output(keybind="", command=""):
'''Output the keybinds in a nice table.
Call fix_table if needed.
'''
headers = ['Keybind', 'Modifier', 'Command']
t_data = []
if binds:
binds.sort()
for l in binds:
if keybind:
if keybind in l[0].lower():
t_data.append(l)
elif command:
if command in l[2].lower():
t_data.append(l)
else:
t_data.append(l)
if t_data:
t_data.insert(0, headers)
table = SingleTable(t_data)
if table.ok:
if args.verbose:
print('Table ok.')
print(table.table)
else:
fix_table(table)
print(table.table)
else:
print('No keybinds found.')
def build(self, objects):
table = SingleTable(self.all_table_rows(objects))
table.justify_columns = self.column_format()
table.inner_row_border = True
return table.table
def report_task(tasks, cfilter=None, title=None,
detailed=False, todos=False, ascii=False):
'''Visual task report'''
tot_work_time = timedelta()
if detailed:
table_data = [['ID', 'Date', 'Interval', 'Tracked', 'Description']]
elif todos:
table_data = [['ID', 'Tracked', 'Description']]
else:
table_data = [['ID', 'Last time', 'Tracked', 'Description']]
for task in tasks:
tot_work_time += task.work_time
if task.last_end_date:
last_time = task.last_end_date
else:
last_time = ''
time = strfdelta(task.work_time, fmt='{H:2}h {M:02}m')
if detailed:
interval = '{begin} -> {end}'.\
format(begin=task.start_time.strftime('%H:%M'),
end=task.end_time.strftime('%H:%M'))
row = [paint(task.tid),
paint(last_time),
paint(interval),
paint(time),
paint(task.name)]
elif todos:
row = [paint(task.tid),
paint(time),
paint(task.name)]
else:
row = [paint(task.tid),
paint(last_time),
paint(time),
paint(task.name)]
table_data.append(row)
if ascii:
table = AsciiTable(table_data)
else:
table = SingleTable(table_data)
info('')
print(table.table)
info('')
if cfilter:
info('{filter}: Tracked time {time}'.format(
filter=cfilter, time=strfdelta(tot_work_time)))
else:
info('Tracked time {time}'.format(time=strfdelta(tot_work_time)))
def get_monitor(ctx, monitor, raw):
with Spinner('Fetching monitor: '):
monitor = newrelic.get_monitor(ctx.obj['ACCOUNT'], monitor)
if raw:
print(json.dumps(monitor))
return
severity = monitor.get('severity', 0)
if severity == 2:
health = click.style(u'?', fg='green')
elif severity == 1:
health = click.style(u'?', fg='yellow')
else:
health = click.style(u'?', fg='red')
monitor['health'] = health
status = monitor['status'].lower()
if status in ('muted', 'disabled'):
status = click.style(u'? {}'.format(status), fg='yellow')
else:
status = click.style(u'? OK', fg='green')
data = [
['Monitor', monitor['id']],
['Status', status],
['Health', health],
['Name', monitor['name']],
['URI', monitor['uri']],
['Type', monitor['type']],
['Locations', ', '.join(monitor['locations'])],
['slaThreshold', monitor['slaThreshold']],
['Emails', ', '.join(monitor['emails'])],
['Frequency', monitor['frequency']],
['Created', monitor['createdAt']],
['Modified', monitor['modifiedAt']],
]
table = SingleTable(data)
table.title = click.style('Monitor', fg='black')
print(table.table)
def show_summary(self):
'''
This shows the summary of the current deployment process to the user.
No more user interaction happens after this point.
'''
# TODO: colors not working properly
green = colorprint('GREEN', bail_result=True)
yellow = colorprint('YELLOW', bail_result=True)
red = colorprint('RED', bail_result=True)
summary_data = [
[
'Detail Item',
'Description'
],
[
green('Package Name: '),
yellow(self.projectdetails['packagename'])
],
[
green('Name: '),
yellow(self.projectdetails['name'] or self.projectdetails['packagename'])
],
[
green('Build Type:'),
yellow('Release' if self.is_release_build else 'Debug')
],
[
green('Deploy version: '),
yellow(self.version) if self.version else red('N/A')
],
[
green('APK Size: '),
yellow('~' + str(self.builddetails['size']) + 'MB')
],
[
green('Signed Status: '),
yellow('Signed' if self.builddetails['is_signed'] else 'Not Signed')
],
[
green('Current deployer: '),
yellow(self.deployer)
],
[
green('Current branch: '),
yellow(git.branch())
]
]
table = SingleTable(summary_data)
print(table.table)