root / snf-cyclades-app / synnefo / plankton / management / commands / image-show.py @ 77fccdd4
History | View | Annotate | Download (2 kB)
1 | 77fccdd4 | Christos Stavrakakis | # Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 77fccdd4 | Christos Stavrakakis | #
|
3 | 77fccdd4 | Christos Stavrakakis | # Redistribution and use in source and binary forms, with or without
|
4 | 77fccdd4 | Christos Stavrakakis | # modification, are permitted provided that the following conditions
|
5 | 77fccdd4 | Christos Stavrakakis | # are met:
|
6 | 77fccdd4 | Christos Stavrakakis | #
|
7 | 77fccdd4 | Christos Stavrakakis | # 1. Redistributions of source code must retain the above copyright
|
8 | 77fccdd4 | Christos Stavrakakis | # notice, this list of conditions and the following disclaimer.
|
9 | 77fccdd4 | Christos Stavrakakis | #
|
10 | 77fccdd4 | Christos Stavrakakis | # 2. Redistributions in binary form must reproduce the above copyright
|
11 | 77fccdd4 | Christos Stavrakakis | # notice, this list of conditions and the following disclaimer in the
|
12 | 77fccdd4 | Christos Stavrakakis | # documentation and/or other materials provided with the distribution.
|
13 | 77fccdd4 | Christos Stavrakakis | #
|
14 | 77fccdd4 | Christos Stavrakakis | # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
15 | 77fccdd4 | Christos Stavrakakis | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16 | 77fccdd4 | Christos Stavrakakis | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
17 | 77fccdd4 | Christos Stavrakakis | # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
18 | 77fccdd4 | Christos Stavrakakis | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19 | 77fccdd4 | Christos Stavrakakis | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
20 | 77fccdd4 | Christos Stavrakakis | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
21 | 77fccdd4 | Christos Stavrakakis | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
22 | 77fccdd4 | Christos Stavrakakis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
23 | 77fccdd4 | Christos Stavrakakis | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
24 | 77fccdd4 | Christos Stavrakakis | # SUCH DAMAGE.
|
25 | 77fccdd4 | Christos Stavrakakis | #
|
26 | 77fccdd4 | Christos Stavrakakis | # The views and conclusions contained in the software and documentation are
|
27 | 77fccdd4 | Christos Stavrakakis | # those of the authors and should not be interpreted as representing official
|
28 | 77fccdd4 | Christos Stavrakakis | # policies, either expressed or implied, of GRNET S.A.
|
29 | 77fccdd4 | Christos Stavrakakis | #
|
30 | 77fccdd4 | Christos Stavrakakis | |
31 | 77fccdd4 | Christos Stavrakakis | from django.core.management.base import BaseCommand, CommandError |
32 | 77fccdd4 | Christos Stavrakakis | |
33 | 77fccdd4 | Christos Stavrakakis | from synnefo.plankton.backend import ImageBackend |
34 | 77fccdd4 | Christos Stavrakakis | from pprint import pprint |
35 | 77fccdd4 | Christos Stavrakakis | |
36 | 77fccdd4 | Christos Stavrakakis | |
37 | 77fccdd4 | Christos Stavrakakis | class Command(BaseCommand): |
38 | 77fccdd4 | Christos Stavrakakis | args = "<image_id>"
|
39 | 77fccdd4 | Christos Stavrakakis | |
40 | 77fccdd4 | Christos Stavrakakis | def handle(self, *args, **options): |
41 | 77fccdd4 | Christos Stavrakakis | |
42 | 77fccdd4 | Christos Stavrakakis | if len(args) != 1: |
43 | 77fccdd4 | Christos Stavrakakis | raise CommandError("Please provide an image ID") |
44 | 77fccdd4 | Christos Stavrakakis | image_id = args[0]
|
45 | 77fccdd4 | Christos Stavrakakis | |
46 | 77fccdd4 | Christos Stavrakakis | c = ImageBackend("")
|
47 | 77fccdd4 | Christos Stavrakakis | |
48 | 77fccdd4 | Christos Stavrakakis | image = c.get_image(image_id) |
49 | 77fccdd4 | Christos Stavrakakis | if not image: |
50 | 77fccdd4 | Christos Stavrakakis | raise CommandError("Image not Found") |
51 | 77fccdd4 | Christos Stavrakakis | |
52 | 77fccdd4 | Christos Stavrakakis | pprint(image, stream=self.stdout) |