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