Revision 5a0f9d6c snf-astakos-app/astakos/im/management/commands/_common.py
b/snf-astakos-app/astakos/im/management/commands/_common.py | ||
---|---|---|
197 | 197 |
return units.show(number, unit, style) |
198 | 198 |
|
199 | 199 |
|
200 |
def collect_holder_quotas(holder_quotas, h_initial, style=None): |
|
201 |
print_data = [] |
|
202 |
for source, source_quotas in holder_quotas.iteritems(): |
|
203 |
try: |
|
204 |
s_initial = h_initial[source] |
|
205 |
except KeyError: |
|
206 |
continue |
|
207 |
for resource, values in source_quotas.iteritems(): |
|
208 |
try: |
|
209 |
initial = s_initial[resource] |
|
210 |
except KeyError: |
|
211 |
continue |
|
212 |
initial = show_resource_value(initial, resource, style) |
|
213 |
limit = show_resource_value(values['limit'], resource, style) |
|
214 |
usage = show_resource_value(values['usage'], resource, style) |
|
215 |
fields = (source, resource, initial, limit, usage) |
|
216 |
print_data.append(fields) |
|
217 |
return print_data |
|
218 |
|
|
219 |
|
|
220 |
def show_user_quotas(holder_quotas, h_initial, style=None): |
|
221 |
labels = ('source', 'resource', 'base_quota', 'total_quota', 'usage') |
|
222 |
print_data = collect_holder_quotas(holder_quotas, h_initial, style=style) |
|
223 |
return print_data, labels |
|
224 |
|
|
225 |
|
|
200 | 226 |
def show_quotas(qh_quotas, astakos_initial, info=None, style=None): |
201 |
labels = ('source', 'resource', 'base quota', 'total quota', 'usage') |
|
227 |
labels = ('user', 'source', 'resource', 'base_quota', 'total_quota', |
|
228 |
'usage') |
|
202 | 229 |
if info is not None: |
203 |
labels = ('uuid', 'email') + labels
|
|
230 |
labels = ('displayname',) + labels
|
|
204 | 231 |
|
205 | 232 |
print_data = [] |
206 | 233 |
for holder, holder_quotas in qh_quotas.iteritems(): |
207 | 234 |
h_initial = astakos_initial.get(holder) |
235 |
if h_initial is None: |
|
236 |
continue |
|
237 |
|
|
208 | 238 |
if info is not None: |
209 | 239 |
email = info.get(holder, "") |
210 | 240 |
|
211 |
for source, source_quotas in holder_quotas.iteritems(): |
|
212 |
s_initial = h_initial.get(source) if h_initial else None |
|
213 |
for resource, values in source_quotas.iteritems(): |
|
214 |
initial = s_initial.get(resource) if s_initial else None |
|
215 |
initial = show_resource_value(initial, resource, style) |
|
216 |
limit = show_resource_value(values['limit'], resource, style) |
|
217 |
usage = show_resource_value(values['usage'], resource, style) |
|
218 |
fields = (source, resource, initial, limit, usage) |
|
219 |
if info is not None: |
|
220 |
fields = (holder, email) + fields |
|
221 |
|
|
222 |
print_data.append(fields) |
|
241 |
h_data = collect_holder_quotas(holder_quotas, h_initial, style=style) |
|
242 |
if info is not None: |
|
243 |
h_data = [(email, holder) + fields for fields in h_data] |
|
244 |
else: |
|
245 |
h_data = [(holder,) + fields for fields in h_data] |
|
246 |
print_data += h_data |
|
223 | 247 |
return print_data, labels |
Also available in: Unified diff