629 """returns a tuple with (key, 1||0) tuples. Used by functions, which |
638 """returns a tuple with (key, 1||0) tuples. Used by functions, which |
630 get a dict from the handler.""" |
639 get a dict from the handler.""" |
631 order = () |
640 order = () |
632 if ctx.scmd == 'domaininfo': |
641 if ctx.scmd == 'domaininfo': |
633 order = ((u'domainname', 0), (u'gid', 1), (u'transport', 0), |
642 order = ((u'domainname', 0), (u'gid', 1), (u'transport', 0), |
634 (u'domaindir', 0), (u'aliasdomains', 0), (u'accounts', 0), |
643 (u'domaindir', 0), (u'quota limit', 0), (u'aliasdomains', 0), |
635 (u'aliases', 0), (u'relocated', 0)) |
644 (u'accounts', 0), (u'aliases', 0), (u'relocated', 0)) |
636 elif ctx.scmd == 'userinfo': |
645 elif ctx.scmd == 'userinfo': |
637 dc12 = ctx.cget('misc.dovecot_version') >= 0x10200b02 |
646 dc12 = ctx.cget('misc.dovecot_version') >= 0x10200b02 |
638 sieve = (u'managesieve', u'sieve')[dc12] |
647 sieve = (u'managesieve', u'sieve')[dc12] |
639 if ctx.argc == 4 and ctx.args[3] != u'aliases' or \ |
648 if ctx.argc == 4 and ctx.args[3] != u'aliases' or \ |
640 ctx.cget('account.disk_usage'): |
649 ctx.cget('account.disk_usage'): |
641 order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), |
650 order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), |
642 (u'home', 0), (u'mail_location', 0), (u'disk usage', 0), |
651 (u'home', 0), (u'mail_location', 0), |
|
652 (u'quota usage', 0), (u'disk usage', 0), |
643 (u'transport', 0), (u'smtp', 1), (u'pop3', 1), |
653 (u'transport', 0), (u'smtp', 1), (u'pop3', 1), |
644 (u'imap', 1), (sieve, 1)) |
654 (u'imap', 1), (sieve, 1)) |
645 else: |
655 else: |
646 order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), |
656 order = ((u'address', 0), (u'name', 0), (u'uid', 1), (u'gid', 1), |
647 (u'home', 0), (u'mail_location', 0), (u'transport', 0), |
657 (u'home', 0), (u'mail_location', 0), (u'quota usage', 0), |
648 (u'smtp', 1), (u'pop3', 1), (u'imap', 1), (sieve, 1)) |
658 (u'transport', 0), (u'smtp', 1), (u'pop3', 1), |
|
659 (u'imap', 1), (sieve, 1)) |
649 elif ctx.scmd == 'getuser': |
660 elif ctx.scmd == 'getuser': |
650 order = ((u'uid', 1), (u'gid', 1), (u'address', 0)) |
661 order = ((u'uid', 1), (u'gid', 1), (u'address', 0)) |
651 return order |
662 return order |
|
663 |
|
664 |
|
665 def _format_quota_usage(ql_bytes, ql_messages, qu_bytes, qu_messages): |
|
666 """Put quota limits / usage / percentage in a formatted string.""" |
|
667 q_usage = { |
|
668 'bytes_used': human_size(qu_bytes), |
|
669 'bytes_limit': human_size(ql_bytes), |
|
670 'msgs_used': qu_messages, |
|
671 'msgs_limit': ql_messages, |
|
672 } |
|
673 if ql_bytes: |
|
674 q_usage['bytes_percent'] = 100. / ql_bytes * qu_bytes |
|
675 else: |
|
676 q_usage['bytes_percent'] = 0. |
|
677 if ql_messages: |
|
678 q_usage['msgs_percent'] = 100. / ql_messages * qu_messages |
|
679 else: |
|
680 q_usage['msgs_percent'] = 0. |
|
681 |
|
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 |
652 |
688 |
653 |
689 |
654 def _print_info(ctx, info, title): |
690 def _print_info(ctx, info, title): |
655 """Print info dicts.""" |
691 """Print info dicts.""" |
656 # TP: used in e.g. 'Domain information' or 'Account information' |
692 # TP: used in e.g. 'Domain information' or 'Account information' |