Revision b75a7e53

b/snf-astakos-app/astakos/im/management/commands/resource-list.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from optparse import make_option
35

  
36
from django.core.management.base import NoArgsCommand
37

  
38 34
from astakos.im.models import Resource
35
from synnefo.webproject.management.commands import ListCommand
39 36

  
40 37

  
41
class Command(NoArgsCommand):
38
class Command(ListCommand):
42 39
    help = "List resources"
43

  
44
    option_list = NoArgsCommand.option_list + (
45
        make_option('-c',
46
                    action='store_true',
47
                    dest='csv',
48
                    default=False,
49
                    help="Use pipes to separate values"),
50
    )
51

  
52
    def handle_noargs(self, **options):
53
        resources = Resource.objects.select_related().all()
54

  
55
        labels = ('id', 'service', 'name')
56
        columns = (3, 40, 40)
57

  
58
        if not options['csv']:
59
            line = ' '.join(l.rjust(w) for l, w in zip(labels, columns))
60
            self.stdout.write(line + '\n')
61
            sep = '-' * len(line)
62
            self.stdout.write(sep + '\n')
63

  
64
        for r in resources:
65
            fields = (str(r.id), r.service.name, r.name)
66

  
67
            if options['csv']:
68
                line = '|'.join(fields)
69
            else:
70
                line = ' '.join(f.rjust(w) for f, w in zip(fields, columns))
71

  
72
            self.stdout.write(line + '\n')
40
    object_class = Resource
41

  
42
    FIELDS = {
43
        "id": ("id", "ID"),
44
        "name": ("name", "Resource Name"),
45
        "service": ("service", "Service"),
46
        "unit": ("unit", "Unit"),
47
        "limit": ("uplimit", "Base Quota"),
48
        "description": ("desc", "Description"),
49
    }
50

  
51
    fields = ["id", "name", "service", "unit", "limit", "description"]

Also available in: Unified diff