cli.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:neres 作者: glogiotatidis 项目源码 文件源码
def list_locations(ctx, raw):
    with Spinner('Fetching locations: '):
        locations = newrelic.get_locations(ctx.obj['ACCOUNT'])

    if raw:
        print(json.dumps(locations))
        return

    data = [[
        '#',
        'City',
        'Continent',
        'Code',
        'Availability',
        'Accessibility',
    ]]

    for number, location in enumerate(locations.values()):
        available = click.style(u'?', fg='green')
        if not location['available']:
            click.style(u'?', fg='red')

        private = 'Private' if location['private'] else 'Public'

        data.append([
            number,
            location['label'],
            location['continent'],
            location['name'],
            available,
            private,
        ])

    table = SingleTable(data)
    table.title = click.style('Locations', fg='black')

    for i in [0, 4, 5]:
        table.justify_columns[i] = 'right'

    print(table.table)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号