VirtualMailManager/cli/subcommands.py
changeset 611 8e9b0046bc8f
parent 609 56ec275911f2
child 618 d8736bb80bdc
equal deleted inserted replaced
610:b6c4e77046b9 611:8e9b0046bc8f
   537 
   537 
   538 def list_users(ctx):
   538 def list_users(ctx):
   539     """list all user accounts / search user accounts by pattern"""
   539     """list all user accounts / search user accounts by pattern"""
   540     return list_addresses(ctx, TYPE_ACCOUNT)
   540     return list_addresses(ctx, TYPE_ACCOUNT)
   541 
   541 
       
   542 
   542 def list_aliases(ctx):
   543 def list_aliases(ctx):
   543     """list all aliases / search aliases by pattern"""
   544     """list all aliases / search aliases by pattern"""
   544     return list_addresses(ctx, TYPE_ALIAS)
   545     return list_addresses(ctx, TYPE_ALIAS)
       
   546 
   545 
   547 
   546 def list_relocated(ctx):
   548 def list_relocated(ctx):
   547     """list all relocated records / search relocated records by pattern"""
   549     """list all relocated records / search relocated records by pattern"""
   548     return list_addresses(ctx, TYPE_RELOCATED)
   550     return list_addresses(ctx, TYPE_RELOCATED)
   549 
   551 
   642             raise
   644             raise
   643     else:
   645     else:
   644         if details in (None, 'du'):
   646         if details in (None, 'du'):
   645             info['quota storage'] = _format_quota_usage(info['ql_bytes'],
   647             info['quota storage'] = _format_quota_usage(info['ql_bytes'],
   646                     info['uq_bytes'], True, info['ql_domaindefault'])
   648                     info['uq_bytes'], True, info['ql_domaindefault'])
   647             info['quota messages'] = _format_quota_usage(info['ql_messages'],
   649             info['quota messages'] = \
   648                     info['uq_messages'], domaindefault=info['ql_domaindefault'])
   650                 _format_quota_usage(info['ql_messages'],
       
   651                                     info['uq_messages'],
       
   652                                     domaindefault=info['ql_domaindefault'])
   649             _print_info(ctx, info, _(u'Account'))
   653             _print_info(ctx, info, _(u'Account'))
   650         else:
   654         else:
   651             info[0]['quota storage'] = _format_quota_usage(info[0]['ql_bytes'],
   655             info[0]['quota storage'] = _format_quota_usage(info[0]['ql_bytes'],
   652                     info[0]['uq_bytes'], True, info[0]['ql_domaindefault'])
   656                     info[0]['uq_bytes'], True, info[0]['ql_domaindefault'])
   653             info[0]['quota messages'] = \
   657             info[0]['quota messages'] = \
   846     'catchalldelete': cmd('catchalldelete', 'cad', catchall_delete,
   850     'catchalldelete': cmd('catchalldelete', 'cad', catchall_delete,
   847                        'fqdn [destination]',
   851                        'fqdn [destination]',
   848                        _(u'delete the specified catch-all destination or all '
   852                        _(u'delete the specified catch-all destination or all '
   849                          u'of a domain\'s destinations')),
   853                          u'of a domain\'s destinations')),
   850     'catchallinfo': cmd('catchallinfo', 'cai', catchall_info, 'fqdn',
   854     'catchallinfo': cmd('catchallinfo', 'cai', catchall_info, 'fqdn',
   851                      _(u'show the catch-all destination(s) of the specified domain')),
   855                         _(u'show the catch-all destination(s) of the '
       
   856                           u'specified domain')),
   852     # Domain commands
   857     # Domain commands
   853     'domainadd': cmd('domainadd', 'da', domain_add, 'fqdn [transport]',
   858     'domainadd': cmd('domainadd', 'da', domain_add, 'fqdn [transport]',
   854                      _(u'create a new domain')),
   859                      _(u'create a new domain')),
   855     'domaindelete': cmd('domaindelete', 'dd', domain_delete, 'fqdn [force]',
   860     'domaindelete': cmd('domaindelete', 'dd', domain_delete, 'fqdn [force]',
   856                       _(u'delete the given domain and all its alias domains')),
   861                       _(u'delete the given domain and all its alias domains')),
   870                      _(u'set, update or delete the note of the given domain')),
   875                      _(u'set, update or delete the note of the given domain')),
   871     # List commands
   876     # List commands
   872     'listdomains': cmd('listdomains', 'ld', list_domains, '[pattern]',
   877     'listdomains': cmd('listdomains', 'ld', list_domains, '[pattern]',
   873                       _(u'list all domains or search for domains by pattern')),
   878                       _(u'list all domains or search for domains by pattern')),
   874     'listaddresses': cmd('listaddresses', 'll', list_addresses, '[pattern]',
   879     'listaddresses': cmd('listaddresses', 'll', list_addresses, '[pattern]',
   875                       _(u'list all addresses or search for addresses by pattern')),
   880                          _(u'list all addresses or search for addresses by '
       
   881                            u'pattern')),
   876     'listusers': cmd('listusers', 'lu', list_users, '[pattern]',
   882     'listusers': cmd('listusers', 'lu', list_users, '[pattern]',
   877                       _(u'list all user accounts or search for accounts by pattern')),
   883                      _(u'list all user accounts or search for accounts by '
       
   884                        u'pattern')),
   878     'listaliases': cmd('listaliases', 'la', list_aliases, '[pattern]',
   885     'listaliases': cmd('listaliases', 'la', list_aliases, '[pattern]',
   879                       _(u'list all aliases or search for aliases by pattern')),
   886                       _(u'list all aliases or search for aliases by pattern')),
   880     'listrelocated': cmd('listrelocated', 'lr', list_relocated, '[pattern]',
   887     'listrelocated': cmd('listrelocated', 'lr', list_relocated, '[pattern]',
   881                          _(u'list all relocated users or search for relocated '
   888                          _(u'list all relocated users or search for relocated '
   882                            u'users by pattern')),
   889                            u'users by pattern')),
   988         w_std(txt_wrpr.fill(para))
   995         w_std(txt_wrpr.fill(para))
   989     txt_wrpr.width += 8
   996     txt_wrpr.width += 8
   990     txt_wrpr.subsequent_indent = old_si
   997     txt_wrpr.subsequent_indent = old_si
   991     txt_wrpr.initial_indent = old_ii
   998     txt_wrpr.initial_indent = old_ii
   992 
   999 
       
  1000 
   993 def _print_list(alist, title):
  1001 def _print_list(alist, title):
   994     """Print a list."""
  1002     """Print a list."""
   995     # TP: used in e.g. 'Existing alias addresses' or 'Existing accounts'
  1003     # TP: used in e.g. 'Existing alias addresses' or 'Existing accounts'
   996     msg = u'%s %s' % (_(u'Existing'), title)
  1004     msg = u'%s %s' % (_(u'Existing'), title)
   997     w_std(msg, u'-' * len(msg))
  1005     w_std(msg, u'-' * len(msg))
  1062     print
  1070     print
  1063 
  1071 
  1064 
  1072 
  1065 def _print_address_list(which, dids, addresses, matching):
  1073 def _print_address_list(which, dids, addresses, matching):
  1066     """Print a list of (matching) addresses."""
  1074     """Print a list of (matching) addresses."""
  1067     _trans = { TYPE_ACCOUNT                  : _('user accounts')
  1075     _trans = {
  1068              , TYPE_ALIAS                    : _('aliases')
  1076         TYPE_ACCOUNT: _('user accounts'),
  1069              , TYPE_RELOCATED                : _('relocated users')
  1077         TYPE_ALIAS: _('aliases'),
  1070              , TYPE_ACCOUNT | TYPE_ALIAS
  1078         TYPE_RELOCATED: _('relocated users'),
  1071                  : _('user accounts and aliases')
  1079         TYPE_ACCOUNT | TYPE_ALIAS: _('user accounts and aliases'),
  1072              , TYPE_ACCOUNT | TYPE_RELOCATED
  1080         TYPE_ACCOUNT | TYPE_RELOCATED: _('user accounts and relocated users'),
  1073                  : _('user accounts and relocated users')
  1081         TYPE_ALIAS | TYPE_RELOCATED: _('aliases and relocated users'),
  1074              , TYPE_ALIAS | TYPE_RELOCATED
  1082         TYPE_ACCOUNT | TYPE_ALIAS | TYPE_RELOCATED: _('addresses'),
  1075                  : _('aliases and relocated users')
  1083     }
  1076              , TYPE_ACCOUNT | TYPE_ALIAS | TYPE_RELOCATED : _('addresses')
       
  1077              }
       
  1078     try:
  1084     try:
  1079         if matching:
  1085         if matching:
  1080             title = _(u'Matching %s') % _trans[which]
  1086             title = _(u'Matching %s') % _trans[which]
  1081         else:
  1087         else:
  1082             title = _(u'Existing %s') % _trans[which]
  1088             title = _(u'Existing %s') % _trans[which]
  1085         raise VMMError(_("Invalid address type for list: '%s'") % which,
  1091         raise VMMError(_("Invalid address type for list: '%s'") % which,
  1086                        INVALID_ARGUMENT)
  1092                        INVALID_ARGUMENT)
  1087     if addresses:
  1093     if addresses:
  1088         if which & (which - 1) == 0:
  1094         if which & (which - 1) == 0:
  1089             # only one type is requested, so no type indicator
  1095             # only one type is requested, so no type indicator
  1090             _trans = { TYPE_ACCOUNT   : ''
  1096             _trans = {TYPE_ACCOUNT: '', TYPE_ALIAS: '', TYPE_RELOCATED: ''}
  1091                      , TYPE_ALIAS     : ''
       
  1092                      , TYPE_RELOCATED : ''
       
  1093                      }
       
  1094         else:
  1097         else:
  1095             # TP: the letters 'u', 'a' and 'r' are abbreviations of user,
  1098             # TP: the letters 'u', 'a' and 'r' are abbreviations of user,
  1096             # alias and relocated user
  1099             # alias and relocated user
  1097             _trans = { TYPE_ACCOUNT   : _('u')
  1100             _trans = {
  1098                      , TYPE_ALIAS     : _('a')
  1101                 TYPE_ACCOUNT: _('u'),
  1099                      , TYPE_RELOCATED : _('r')
  1102                 TYPE_ALIAS: _('a'),
  1100                      }
  1103                 TYPE_RELOCATED: _('r'),
       
  1104             }
  1101         for did in dids:
  1105         for did in dids:
  1102             for addr, atype, aliasdomain in addresses[did]:
  1106             for addr, atype, aliasdomain in addresses[did]:
  1103                 if aliasdomain:
  1107                 if aliasdomain:
  1104                     leader = '[%s-]' % _trans[atype]
  1108                     leader = '[%s-]' % _trans[atype]
  1105                 else:
  1109                 else: