14 from textwrap import TextWrapper |
14 from textwrap import TextWrapper |
15 from time import strftime, strptime |
15 from time import strftime, strptime |
16 |
16 |
17 from VirtualMailManager import ENCODING |
17 from VirtualMailManager import ENCODING |
18 from VirtualMailManager.cli import get_winsize, prog, w_err, w_std |
18 from VirtualMailManager.cli import get_winsize, prog, w_err, w_std |
19 from VirtualMailManager.common import human_size, size_in_bytes, version_str |
19 from VirtualMailManager.common import human_size, size_in_bytes, \ |
|
20 version_str, format_domain_default |
20 from VirtualMailManager.constants import __copyright__, __date__, \ |
21 from VirtualMailManager.constants import __copyright__, __date__, \ |
21 __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \ |
22 __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \ |
22 DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, RELOCATED_EXISTS |
23 DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, RELOCATED_EXISTS |
23 from VirtualMailManager.errors import VMMError |
24 from VirtualMailManager.errors import VMMError |
24 from VirtualMailManager.password import list_schemes |
25 from VirtualMailManager.password import list_schemes |
570 else: |
571 else: |
571 raise |
572 raise |
572 else: |
573 else: |
573 if details in (None, 'du'): |
574 if details in (None, 'du'): |
574 info['quota storage'] = _format_quota_usage(info['ql_bytes'], |
575 info['quota storage'] = _format_quota_usage(info['ql_bytes'], |
575 info['uq_bytes'], True) |
576 info['uq_bytes'], True, info['ql_domaindefault']) |
576 info['quota messages'] = _format_quota_usage(info['ql_messages'], |
577 info['quota messages'] = _format_quota_usage(info['ql_messages'], |
577 info['uq_messages']) |
578 info['uq_messages'], domaindefault=info['ql_domaindefault']) |
578 _print_info(ctx, info, _(u'Account')) |
579 _print_info(ctx, info, _(u'Account')) |
579 else: |
580 else: |
580 info[0]['quota storage'] = _format_quota_usage(info[0]['ql_bytes'], |
581 info[0]['quota storage'] = _format_quota_usage(info[0]['ql_bytes'], |
581 info[0]['uq_bytes'], True) |
582 info[0]['uq_bytes'], True, info[0]['ql_domaindefault']) |
582 info[0]['quota messages'] = _format_quota_usage( |
583 info[0]['quota messages'] = \ |
583 info[0]['ql_messages'], info[0]['uq_messages']) |
584 _format_quota_usage(info[0]['ql_messages'], |
|
585 info[0]['uq_messages'], |
|
586 domaindefault=info[0]['ql_domaindefault']) |
584 _print_info(ctx, info[0], _(u'Account')) |
587 _print_info(ctx, info[0], _(u'Account')) |
585 _print_list(info[1], _(u'alias addresses')) |
588 _print_list(info[1], _(u'alias addresses')) |
586 |
589 |
587 |
590 |
588 def user_name(ctx): |
591 def user_name(ctx): |
828 elif ctx.scmd == 'getuser': |
831 elif ctx.scmd == 'getuser': |
829 order = ((u'uid', 1), (u'gid', 1), (u'address', 0)) |
832 order = ((u'uid', 1), (u'gid', 1), (u'address', 0)) |
830 return order |
833 return order |
831 |
834 |
832 |
835 |
833 def _format_quota_usage(limit, used, human=False): |
836 def _format_quota_usage(limit, used, human=False, domaindefault=False): |
834 """Put quota's limit / usage / percentage in a formatted string.""" |
837 """Put quota's limit / usage / percentage in a formatted string.""" |
835 if human: |
838 if human: |
836 q_usage = { |
839 q_usage = { |
837 'used': human_size(used), |
840 'used': human_size(used), |
838 'limit': human_size(limit), |
841 'limit': human_size(limit), |
844 } |
847 } |
845 if limit: |
848 if limit: |
846 q_usage['percent'] = locale.format('%6.2f', 100. / limit * used, True) |
849 q_usage['percent'] = locale.format('%6.2f', 100. / limit * used, True) |
847 else: |
850 else: |
848 q_usage['percent'] = locale.format('%6.2f', 0, True) |
851 q_usage['percent'] = locale.format('%6.2f', 0, True) |
849 return _(u'[%(percent)s%%] %(used)s/%(limit)s') % q_usage |
852 fmt = format_domain_default if domaindefault else lambda s: s |
|
853 return fmt(_(u'[%(percent)s%%] %(used)s/%(limit)s') % q_usage) |
850 |
854 |
851 |
855 |
852 def _print_info(ctx, info, title): |
856 def _print_info(ctx, info, title): |
853 """Print info dicts.""" |
857 """Print info dicts.""" |
854 # TP: used in e.g. 'Domain information' or 'Account information' |
858 # TP: used in e.g. 'Domain information' or 'Account information' |