469 relocated_info(ctx) |
469 relocated_info(ctx) |
470 else: |
470 else: |
471 raise |
471 raise |
472 else: |
472 else: |
473 if details in (None, 'du'): |
473 if details in (None, 'du'): |
474 info['quota usage'] = _format_quota_usage(info['ql_bytes'], |
474 info['quota storage'] = _format_quota_usage(info['ql_bytes'], |
475 info['ql_messages'], info['uq_bytes'], info['uq_messages']) |
475 info['uq_bytes'], True) |
|
476 info['quota messages'] = _format_quota_usage(info['ql_messages'], |
|
477 info['uq_messages']) |
476 _print_info(ctx, info, _(u'Account')) |
478 _print_info(ctx, info, _(u'Account')) |
477 else: |
479 else: |
478 info[0]['quota usage'] = _format_quota_usage(info[0]['ql_bytes'], |
480 info[0]['quota storage'] = _format_quota_usage(info[0]['ql_bytes'], |
479 info[0]['ql_messages'], info[0]['uq_bytes'], |
481 info['uq_bytes'], True) |
480 info[0]['uq_messages']) |
482 info[0]['quota messages'] = _format_quota_usage( |
|
483 info[0]['ql_messages'], info[0]['uq_messages']) |
481 _print_info(ctx, info[0], _(u'Account')) |
484 _print_info(ctx, info[0], _(u'Account')) |
482 _print_list(info[1], _(u'alias addresses')) |
485 _print_list(info[1], _(u'alias addresses')) |
483 |
486 |
484 |
487 |
485 def user_name(ctx): |
488 def user_name(ctx): |
647 sieve = (u'managesieve', u'sieve')[dc12] |
650 sieve = (u'managesieve', u'sieve')[dc12] |
648 if ctx.argc == 4 and ctx.args[3] != u'aliases' or \ |
651 if ctx.argc == 4 and ctx.args[3] != u'aliases' or \ |
649 ctx.cget('account.disk_usage'): |
652 ctx.cget('account.disk_usage'): |
650 order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), |
653 order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), |
651 (u'home', 0), (u'mail_location', 0), |
654 (u'home', 0), (u'mail_location', 0), |
652 (u'quota usage', 0), (u'disk usage', 0), |
655 (u'quota storage', 0), (u'quota messages', 0), |
653 (u'transport', 0), (u'smtp', 1), (u'pop3', 1), |
656 (u'disk usage', 0), (u'transport', 0), (u'smtp', 1), |
654 (u'imap', 1), (sieve, 1)) |
657 (u'pop3', 1), (u'imap', 1), (sieve, 1)) |
655 else: |
658 else: |
656 order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), |
659 order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), |
657 (u'home', 0), (u'mail_location', 0), (u'quota usage', 0), |
660 (u'home', 0), (u'mail_location', 0), |
|
661 (u'quota storage', 0), (u'quota messages', 0), |
658 (u'transport', 0), (u'smtp', 1), (u'pop3', 1), |
662 (u'transport', 0), (u'smtp', 1), (u'pop3', 1), |
659 (u'imap', 1), (sieve, 1)) |
663 (u'imap', 1), (sieve, 1)) |
660 elif ctx.scmd == 'getuser': |
664 elif ctx.scmd == 'getuser': |
661 order = ((u'uid', 1), (u'gid', 1), (u'address', 0)) |
665 order = ((u'uid', 1), (u'gid', 1), (u'address', 0)) |
662 return order |
666 return order |
663 |
667 |
664 |
668 |
665 def _format_quota_usage(ql_bytes, ql_messages, qu_bytes, qu_messages): |
669 def _format_quota_usage(limit, used, human=False): |
666 """Put quota limits / usage / percentage in a formatted string.""" |
670 """Put quota's limit / usage / percentage in a formatted string.""" |
667 q_usage = { |
671 if human: |
668 'bytes_used': human_size(qu_bytes), |
672 q_usage = { |
669 'bytes_limit': human_size(ql_bytes), |
673 'used': human_size(used), |
670 'msgs_used': qu_messages, |
674 'limit': human_size(limit), |
671 'msgs_limit': ql_messages, |
675 } |
672 } |
676 else: |
673 if ql_bytes: |
677 q_usage = { |
674 q_usage['bytes_percent'] = 100. / ql_bytes * qu_bytes |
678 'used': used, |
675 else: |
679 'limit': limit, |
676 q_usage['bytes_percent'] = 0. |
680 } |
677 if ql_messages: |
681 if limit: |
678 q_usage['msgs_percent'] = 100. / ql_messages * qu_messages |
682 q_usage['percent'] = 100. / limit * used |
679 else: |
683 else: |
680 q_usage['msgs_percent'] = 0. |
684 q_usage['percent'] = 0. |
681 |
685 return _(u'[%(percent)6.2f%%] %(used)s/%(limit)s') % q_usage |
682 # TP: example of quota usage message: |
|
683 # XXX file in XXX |
|
684 txt = _(u'Storage: %(bytes_used)s/%(bytes_limit)s (%(bytes_percent).2f%%) ' |
|
685 'Messages: %(msgs_used)u/%(msgs_limit)u (%(msgs_percent).2f%%)') \ |
|
686 % q_usage |
|
687 return txt |
|
688 |
686 |
689 |
687 |
690 def _print_info(ctx, info, title): |
688 def _print_info(ctx, info, title): |
691 """Print info dicts.""" |
689 """Print info dicts.""" |
692 # TP: used in e.g. 'Domain information' or 'Account information' |
690 # TP: used in e.g. 'Domain information' or 'Account information' |