Revision 7a0aa449 snf-cyclades-app/synnefo/api/management/commands/flavor-list.py
b/snf-cyclades-app/synnefo/api/management/commands/flavor-list.py | ||
---|---|---|
34 | 34 |
from optparse import make_option |
35 | 35 |
|
36 | 36 |
from django.core.management.base import BaseCommand, CommandError |
37 |
from synnefo.management.common import format_bool, filter_results |
|
37 |
from synnefo.management.common import (format_bool, filter_results, |
|
38 |
pprint_table) |
|
38 | 39 |
|
39 | 40 |
from synnefo.db.models import Flavor |
40 | 41 |
|
... | ... | |
67 | 68 |
if args: |
68 | 69 |
raise CommandError("Command doesn't accept any arguments") |
69 | 70 |
|
70 |
labels = ('id', 'name', 'cpus', 'ram', 'disk', 'template', 'deleted') |
|
71 |
columns = (3, 12, 6, 6, 6, 10, 7) |
|
72 |
|
|
73 |
if not options['csv']: |
|
74 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
|
75 |
self.stdout.write(line + '\n') |
|
76 |
sep = '-' * len(line) |
|
77 |
self.stdout.write(sep + '\n') |
|
78 |
|
|
79 | 71 |
if options['deleted']: |
80 | 72 |
flavors = Flavor.objects.all() |
81 | 73 |
else: |
... | ... | |
85 | 77 |
if filter_by: |
86 | 78 |
flavors = filter_results(flavors, filter_by) |
87 | 79 |
|
88 |
|
|
80 |
headers = ('id', 'name', 'cpus', 'ram', 'disk', 'template', 'deleted') |
|
81 |
table = [] |
|
89 | 82 |
for flavor in flavors.order_by('id'): |
90 | 83 |
id = str(flavor.id) |
91 | 84 |
cpu = str(flavor.cpu) |
... | ... | |
95 | 88 |
fields = (id, flavor.name, cpu, ram, disk, flavor.disk_template, |
96 | 89 |
deleted) |
97 | 90 |
|
98 |
if options['csv']: |
|
99 |
line = '|'.join(fields) |
|
100 |
else: |
|
101 |
line = ' '.join(f.rjust(w) for f, w in zip(fields, columns)) |
|
91 |
table.append(fields) |
|
102 | 92 |
|
103 |
self.stdout.write(line.encode('utf8') + '\n') |
|
93 |
separator = " | " if options['csv'] else None |
|
94 |
pprint_table(self.stdout, table, headers, separator) |
Also available in: Unified diff