Revision 7a0aa449 snf-cyclades-app/synnefo/plankton/management/commands/image-list.py
b/snf-cyclades-app/synnefo/plankton/management/commands/image-list.py | ||
---|---|---|
31 | 31 |
from django.core.management.base import BaseCommand |
32 | 32 |
from optparse import make_option |
33 | 33 |
|
34 |
from synnefo.management.common import pprint_table |
|
34 | 35 |
from synnefo.plankton.backend import ImageBackend |
35 | 36 |
|
36 | 37 |
|
... | ... | |
42 | 43 |
|
43 | 44 |
def handle(self, **options): |
44 | 45 |
userid = options['userid'] |
45 |
write = self.stdout.write |
|
46 | 46 |
|
47 | 47 |
c = ImageBackend(userid) if userid else ImageBackend("") |
48 | 48 |
images = c.list() |
49 | 49 |
images.sort(key=lambda x: x['created_at'], reverse=True) |
50 | 50 |
|
51 |
fields = ("id", "name", "owner", "public") |
|
52 |
columns = (40, 30, 30, 7) |
|
53 |
sep = "-" * 107 |
|
54 |
line = "".join(f.rjust(c) for f, c in zip(fields, columns)) |
|
55 |
write(line + "\n") |
|
56 |
write(sep + "\n") |
|
51 |
headers = ("id", "name", "owner", "public") |
|
52 |
table = [] |
|
57 | 53 |
for img in images: |
58 |
fields = (img["id"], img["name"], img["owner"], img["is_public"]) |
|
59 |
line = "".join(str(f).rjust(c) for f, c in zip(fields, columns)) |
|
60 |
write(line + "\n") |
|
54 |
fields = (img["id"], img["name"], img["owner"], str(img["is_public"])) |
|
55 |
table.append(fields) |
|
56 |
pprint_table(self.stdout, table, headers) |
Also available in: Unified diff