VirtualMailManager/cli/subcommands.py
branchv0.6.x
changeset 398 3e5ed678d535
parent 397 cf661a40266d
child 401 00a8c12a3da3
equal deleted inserted replaced
397:cf661a40266d 398:3e5ed678d535
   255             aliasdomain_info(ctx)
   255             aliasdomain_info(ctx)
   256         else:
   256         else:
   257             raise
   257             raise
   258     else:
   258     else:
   259         if not details:
   259         if not details:
       
   260             info['quota limit'] = _(u'Storage: %s Messages %u') % (
       
   261                     human_size(info['bytes']), info['messages'])
   260             _print_info(ctx, info, _(u'Domain'))
   262             _print_info(ctx, info, _(u'Domain'))
   261         else:
   263         else:
       
   264             info[0]['quota limit'] = _(u'Storage: %s Messages %u') % (
       
   265                     human_size(info[0]['bytes']), info[0]['messages'])
   262             _print_info(ctx, info[0], _(u'Domain'))
   266             _print_info(ctx, info[0], _(u'Domain'))
   263             if details == u'accounts':
   267             if details == u'accounts':
   264                 _print_list(info[1], _(u'accounts'))
   268                 _print_list(info[1], _(u'accounts'))
   265             elif details == u'aliasdomains':
   269             elif details == u'aliasdomains':
   266                 _print_list(info[1], _(u'alias domains'))
   270                 _print_list(info[1], _(u'alias domains'))
   465             relocated_info(ctx)
   469             relocated_info(ctx)
   466         else:
   470         else:
   467             raise
   471             raise
   468     else:
   472     else:
   469         if details in (None, 'du'):
   473         if details in (None, 'du'):
       
   474             info['quota usage'] = _format_quota_usage(info['ql_bytes'],
       
   475                     info['ql_messages'], info['uq_bytes'], info['uq_messages'])
   470             _print_info(ctx, info, _(u'Account'))
   476             _print_info(ctx, info, _(u'Account'))
   471         else:
   477         else:
       
   478             info[0]['quota usage'] = _format_quota_usage(info[0]['ql_bytes'],
       
   479                     info[0]['ql_messages'], info[0]['uq_bytes'],
       
   480                     info[0]['uq_messages'])
   472             _print_info(ctx, info[0], _(u'Account'))
   481             _print_info(ctx, info[0], _(u'Account'))
   473             _print_list(info[1], _(u'alias addresses'))
   482             _print_list(info[1], _(u'alias addresses'))
   474 
   483 
   475 
   484 
   476 def user_name(ctx):
   485 def user_name(ctx):
   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'