Revision a1a4cbfb snf-cyclades-app/synnefo/plankton/management/commands/image-show.py

b/snf-cyclades-app/synnefo/plankton/management/commands/image-show.py
29 29
#
30 30

  
31 31
from django.core.management.base import BaseCommand, CommandError
32
from optparse import make_option
33 32

  
34
from synnefo.plankton.backend import ImageBackend
35
from pprint import pprint
33
from synnefo.plankton.utils import image_backend
34
from synnefo.webproject.management import utils
36 35

  
37 36

  
38 37
class Command(BaseCommand):
39 38
    args = "<image_id>"
40 39
    help = "Display available information about an image"
41
    option_list = BaseCommand.option_list + (
42
        make_option(
43
            '--user-id',
44
            dest='userid',
45
            help="The ID of the owner of the Image."),
46
    )
47 40

  
48 41
    def handle(self, *args, **options):
49 42

  
......
51 44
            raise CommandError("Please provide an image ID")
52 45
        image_id = args[0]
53 46

  
54
        userid = options['userid']
55
        c = ImageBackend(userid) if userid else ImageBackend("")
56

  
57
        image = c.get_image(image_id)
58
        if not image:
59
            raise CommandError("Image not Found")
60

  
61
        pprint(image, stream=self.stdout)
47
        with image_backend(None) as backend:
48
            images = backend._list_images(None)
49
            try:
50
                image = filter(lambda x: x["id"] == image_id, images)[0]
51
            except IndexError:
52
                raise CommandError("Image not found. Use snf-manage image-list"
53
                                   " to get the list of all images.")
54
        utils.pprint_table(out=self.stdout, table=[image.values()], headers=image.keys(), vertical=True)

Also available in: Unified diff