root / snf-cyclades-app / synnefo / plankton / management / commands / image-list.py @ 225cea18
History | View | Annotate | Download (2.6 kB)
1 | 77fccdd4 | Christos Stavrakakis | # Copyright 2011-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 |
32 | 77fccdd4 | Christos Stavrakakis | from optparse import make_option |
33 | 77fccdd4 | Christos Stavrakakis | |
34 | 225cea18 | Christos Stavrakakis | from synnefo.webproject.management.util import pprint_table |
35 | 77fccdd4 | Christos Stavrakakis | from synnefo.plankton.backend import ImageBackend |
36 | 77fccdd4 | Christos Stavrakakis | |
37 | 77fccdd4 | Christos Stavrakakis | |
38 | 77fccdd4 | Christos Stavrakakis | class Command(BaseCommand): |
39 | 45f19863 | Christos Stavrakakis | help = "List public images or images available to a user."
|
40 | 77fccdd4 | Christos Stavrakakis | option_list = BaseCommand.option_list + ( |
41 | cc92b70f | Christos Stavrakakis | make_option( |
42 | cc92b70f | Christos Stavrakakis | '--user-id',
|
43 | cc92b70f | Christos Stavrakakis | dest='userid',
|
44 | cc92b70f | Christos Stavrakakis | help="List all images available to that user."
|
45 | cc92b70f | Christos Stavrakakis | " If no user is specified, only public images"
|
46 | 45f19863 | Christos Stavrakakis | " are displayed."),
|
47 | cc92b70f | Christos Stavrakakis | ) |
48 | 77fccdd4 | Christos Stavrakakis | |
49 | 77fccdd4 | Christos Stavrakakis | def handle(self, **options): |
50 | 77fccdd4 | Christos Stavrakakis | userid = options['userid']
|
51 | 77fccdd4 | Christos Stavrakakis | |
52 | 77fccdd4 | Christos Stavrakakis | c = ImageBackend(userid) if userid else ImageBackend("") |
53 | 77fccdd4 | Christos Stavrakakis | images = c.list() |
54 | 77fccdd4 | Christos Stavrakakis | images.sort(key=lambda x: x['created_at'], reverse=True) |
55 | 77fccdd4 | Christos Stavrakakis | |
56 | 7a0aa449 | Christos Stavrakakis | headers = ("id", "name", "owner", "public") |
57 | 7a0aa449 | Christos Stavrakakis | table = [] |
58 | 77fccdd4 | Christos Stavrakakis | for img in images: |
59 | cc92b70f | Christos Stavrakakis | fields = (img["id"], img["name"], img["owner"], |
60 | cc92b70f | Christos Stavrakakis | str(img["is_public"])) |
61 | 7a0aa449 | Christos Stavrakakis | table.append(fields) |
62 | 7a0aa449 | Christos Stavrakakis | pprint_table(self.stdout, table, headers) |