VirtualMailManager/cli/subcommands.py
branchv0.6.x
changeset 462 a64c1b5e08b4
parent 458 4ff0fa3ba0fa
child 469 1ebb6b88f589
equal deleted inserted replaced
461:cabdf94ec580 462:a64c1b5e08b4
    19 from VirtualMailManager.common import human_size, size_in_bytes, version_str
    19 from VirtualMailManager.common import human_size, size_in_bytes, version_str
    20 from VirtualMailManager.constants import __copyright__, __date__, \
    20 from VirtualMailManager.constants import __copyright__, __date__, \
    21      __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \
    21      __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \
    22      DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, RELOCATED_EXISTS
    22      DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, RELOCATED_EXISTS
    23 from VirtualMailManager.errors import VMMError
    23 from VirtualMailManager.errors import VMMError
       
    24 from VirtualMailManager.password import list_schemes
    24 from VirtualMailManager.serviceset import SERVICES
    25 from VirtualMailManager.serviceset import SERVICES
    25 
    26 
    26 __all__ = (
    27 __all__ = (
    27     'Command', 'RunContext', 'cmd_map', 'usage', 'alias_add', 'alias_delete',
    28     'Command', 'RunContext', 'cmd_map', 'usage', 'alias_add', 'alias_delete',
    28     'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info',
    29     'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info',
    29     'aliasdomain_switch', 'config_get', 'config_set', 'configure',
    30     'aliasdomain_switch', 'config_get', 'config_set', 'configure',
    30     'domain_add', 'domain_delete',  'domain_info', 'domain_quota',
    31     'domain_add', 'domain_delete',  'domain_info', 'domain_quota',
    31     'domain_services', 'domain_transport', 'get_user', 'help_', 'list_domains',
    32     'domain_services', 'domain_transport', 'get_user', 'help_', 'list_domains',
    32     'relocated_add', 'relocated_delete', 'relocated_info', 'user_add',
    33     'list_pwschemes', 'relocated_add', 'relocated_delete', 'relocated_info',
    33     'user_delete', 'user_info', 'user_name', 'user_password', 'user_quota',
    34     'user_add', 'user_delete', 'user_info', 'user_name', 'user_password',
    34     'user_services', 'user_transport', 'version',
    35     'user_quota', 'user_services', 'user_transport', 'version',
    35 )
    36 )
    36 
    37 
    37 _ = lambda msg: msg
    38 _ = lambda msg: msg
    38 txt_wrpr = TextWrapper(width=get_winsize()[1] - 1)
    39 txt_wrpr = TextWrapper(width=get_winsize()[1] - 1)
    39 cmd_map = {}
    40 cmd_map = {}
   422     else:
   423     else:
   423         gids, domains = ctx.hdlr.domain_list()
   424         gids, domains = ctx.hdlr.domain_list()
   424     _print_domain_list(gids, domains, matching)
   425     _print_domain_list(gids, domains, matching)
   425 
   426 
   426 
   427 
       
   428 def list_pwschemes(ctx_unused):
       
   429     """Prints all usable password schemes and password encoding suffixes."""
       
   430     keys = (_(u'Usable password schemes:'), _(u'Usable encoding suffixes:'))
       
   431     old_ii, old_si = txt_wrpr.initial_indent, txt_wrpr.subsequent_indent
       
   432     txt_wrpr.initial_indent = ''
       
   433     indent = 0
       
   434 
       
   435     for key in keys:
       
   436         k_len = len(key)
       
   437         if k_len > indent:
       
   438             indent = k_len
       
   439     txt_wrpr.subsequent_indent = (indent + 1) * ' '
       
   440     fmt = '%%-%us %%s' % indent
       
   441     for key, value in zip(keys, list_schemes()):
       
   442         w_std('\n'.join(txt_wrpr.wrap(fmt % (key, ' '.join(value)))))
       
   443 
       
   444     txt_wrpr.initial_indent, txt_wrpr.subsequent_indent = old_ii, old_si
       
   445 
       
   446 
   427 def relocated_add(ctx):
   447 def relocated_add(ctx):
   428     """create a new record for a relocated user"""
   448     """create a new record for a relocated user"""
   429     if ctx.argc < 3:
   449     if ctx.argc < 3:
   430         usage(EX_MISSING_ARGS,
   450         usage(EX_MISSING_ARGS,
   431               _(u'Missing relocated address and destination.'), ctx.scmd)
   451               _(u'Missing relocated address and destination.'), ctx.scmd)
   627         scmd = cmd_map[key]
   647         scmd = cmd_map[key]
   628         w_err(0, '  %-5s %-19s %s' % (scmd.alias, scmd.name, scmd.args))
   648         w_err(0, '  %-5s %-19s %s' % (scmd.alias, scmd.name, scmd.args))
   629     w_err(errno, '', _(u"Error: %s") % errmsg)
   649     w_err(errno, '', _(u"Error: %s") % errmsg)
   630 
   650 
   631 
   651 
   632 def version(ctx):
   652 def version(ctx_unused):
   633     """Write version and copyright information to stdout."""
   653     """Write version and copyright information to stdout."""
   634     w_std('%s, %s %s (%s %s)\nPython %s %s %s\n\n%s\n%s %s' % (prog,
   654     w_std('%s, %s %s (%s %s)\nPython %s %s %s\n\n%s\n%s %s' % (prog,
   635     # TP: The words 'from', 'version' and 'on' are used in
   655     # TP: The words 'from', 'version' and 'on' are used in
   636     # the version information, e.g.:
   656     # the version information, e.g.:
   637     # vmm, version 0.5.2 (from 09/09/09)
   657     # vmm, version 0.5.2 (from 09/09/09)
   730                      _('show the actual value of the configuration option')),
   750                      _('show the actual value of the configuration option')),
   731     'configset': cmd('configset', 'cs', config_set, _('option value'),
   751     'configset': cmd('configset', 'cs', config_set, _('option value'),
   732                       _('set a new value for the configuration option')),
   752                       _('set a new value for the configuration option')),
   733     'configure': cmd('configure', 'cf', configure, _(u'[section]'),
   753     'configure': cmd('configure', 'cf', configure, _(u'[section]'),
   734                      _(u'start interactive configuration modus')),
   754                      _(u'start interactive configuration modus')),
       
   755     'listpwschemes': cmd('listpwschemes', 'lp', list_pwschemes, '',
       
   756                          _(u'lists all usable password schemes and password '
       
   757                            u'encoding suffixes')),
   735     'help': cmd('help', 'h', help_, _(u'[subcommand]'),
   758     'help': cmd('help', 'h', help_, _(u'[subcommand]'),
   736                 _(u'show a help overview or help for the given subcommand')),
   759                 _(u'show a help overview or help for the given subcommand')),
   737     'version': cmd('version', 'v', version, '',
   760     'version': cmd('version', 'v', version, '',
   738                    _(u'show version and copyright information')),
   761                    _(u'show version and copyright information')),
   739     })
   762     })