Revision 44f510e1 snf-astakos-app/astakos/im/management/commands/quota.py

b/snf-astakos-app/astakos/im/management/commands/quota.py
42 42
from snf_django.lib.db.transaction import commit_on_success_strict
43 43
from synnefo.webproject.management.commands import SynnefoCommand
44 44
from synnefo.webproject.management import utils
45
from ._common import show_quotas
45
from ._common import show_quotas, style_options, check_style, units
46 46

  
47 47
import logging
48 48
logger = logging.getLogger(__name__)
......
57 57
                    dest='list',
58 58
                    default=False,
59 59
                    help="List all quota (default)"),
60
        make_option('--unit-style',
61
                    default='mb',
62
                    help=("Specify display unit for resource values "
63
                          "(one of %s); defaults to mb") % style_options),
60 64
        make_option('--verify',
61 65
                    action='store_true',
62 66
                    dest='verify',
......
77 81
                    help=("Import base quota from file. "
78 82
                          "The file must contain non-empty lines, and each "
79 83
                          "line must contain a single-space-separated list "
80
                          "of values: <user> <resource name> <capacity>")
84
                          "of values: <user> <resource name> <capacity>. "
85
                          "Capacity can be followed by a unit with no "
86
                          "separating space (e.g 10GB).")
81 87
                    ),
82 88
    )
83 89

  
......
95 101
                raise CommandError(m)
96 102
            self.import_from_file(import_base_quota)
97 103
        else:
98
            self.quotas(sync, verify, user_ident, options["output_format"])
104
            unit_style = options["unit_style"]
105
            check_style(unit_style)
99 106

  
100
    def quotas(self, sync, verify, user_ident, output_format):
107
            self.quotas(sync, verify, user_ident, options["output_format"],
108
                        unit_style)
109

  
110
    def quotas(self, sync, verify, user_ident, output_format, style):
101 111
        list_only = not sync and not verify
102 112

  
103 113
        if user_ident is not None:
......
112 122
            for user in users:
113 123
                info[user.uuid] = user.email
114 124

  
115
            print_data, labels = show_quotas(qh_quotas, astakos_i, info)
125
            print_data, labels = show_quotas(qh_quotas, astakos_i, info,
126
                                             style=style)
116 127
            utils.pprint_table(self.stdout, print_data, labels,
117 128
                               output_format)
118 129

  
......
186 197
                    user = t[0]
187 198
                    resource = t[1]
188 199
                    capacity = t[2]
200
                    try:
201
                        capacity = units.parse(capacity)
202
                    except units.ParseError:
203
                        m = ("Capacity should be an integer, optionally "
204
                             "followed by a unit.")
205
                        raise CommandError(m)
189 206
                except(IndexError, TypeError):
190 207
                    self.stdout.write('Invalid line format: %s:\n' % t)
191 208
                    continue

Also available in: Unified diff