VirtualMailManager/cli/subcommands.py
branchv0.6.x
changeset 345 f8d5c8bb8bce
parent 341 6709d0faf2f5
child 361 971577b89d26
equal deleted inserted replaced
344:0d2430dc6ef8 345:f8d5c8bb8bce
    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.account import SERVICES
    18 from VirtualMailManager.account import SERVICES
    19 from VirtualMailManager.cli import get_winsize, prog, w_err, w_std
    19 from VirtualMailManager.cli import get_winsize, prog, w_err, w_std
       
    20 from VirtualMailManager.common import version_str
    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 
    25 
    25 __all__ = (
    26 __all__ = (
    26     'Command', 'RunContext', 'cmd_map', 'usage', 'alias_add', 'alias_delete',
    27     'Command', 'RunContext', 'cmd_map', 'usage', 'alias_add', 'alias_delete',
    27     'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info',
    28     'alias_info', 'aliasdomain_add', 'aliasdomain_delete', 'aliasdomain_info',
    28     'aliasdomain_switch', 'configure', 'domain_add', 'domain_delete',
    29     'aliasdomain_switch', 'config_get', 'config_set', 'configure',
    29     'domain_info', 'domain_transport', 'get_user', 'help_', 'list_domains',
    30     'domain_add', 'domain_delete',  'domain_info', 'domain_transport',
    30     'relocated_add', 'relocated_delete', 'relocated_info', 'user_add',
    31     'get_user', 'help_', 'list_domains', 'relocated_add', 'relocated_delete',
    31     'user_delete', 'user_disable', 'user_enable', 'user_info', 'user_name',
    32     'relocated_info', 'user_add', 'user_delete', 'user_disable', 'user_enable',
    32     'user_password', 'user_transport', 'version',
    33     'user_info', 'user_name', 'user_password', 'user_transport', 'version',
    33 )
    34 )
    34 
    35 
    35 _ = lambda msg: msg
    36 _ = lambda msg: msg
    36 txt_wrpr = TextWrapper(width=get_winsize()[1] - 1)
    37 txt_wrpr = TextWrapper(width=get_winsize()[1] - 1)
    37 
    38 
   165                                  u'domain name.'), ctx.scmd)
   166                                  u'domain name.'), ctx.scmd)
   166     elif ctx.argc < 4:
   167     elif ctx.argc < 4:
   167         usage(EX_MISSING_ARGS, _(u'Missing destination domain name.'),
   168         usage(EX_MISSING_ARGS, _(u'Missing destination domain name.'),
   168               ctx.scmd)
   169               ctx.scmd)
   169     ctx.hdlr.aliasdomain_switch(ctx.args[2].lower(), ctx.args[3].lower())
   170     ctx.hdlr.aliasdomain_switch(ctx.args[2].lower(), ctx.args[3].lower())
       
   171 
       
   172 
       
   173 def config_get(ctx):
       
   174     """show the actual value of the configuration option"""
       
   175     if ctx.argc < 3:
       
   176         usage(EX_MISSING_ARGS, _(u"Missing option name."), ctx.scmd)
       
   177     option = ctx.args[2].lower()
       
   178     if option != 'misc.dovecot_version':
       
   179         w_std('%s = %s' % (option, ctx.cget(option)))
       
   180     else:
       
   181         w_std('%s = %s' % (option, version_str(ctx.cget(option))))
       
   182 
       
   183 
       
   184 def config_set(ctx):
       
   185     """set a new value for the configuration option"""
       
   186     if ctx.argc < 3:
       
   187         usage(EX_MISSING_ARGS, _(u'Missing option and new value.'), ctx.scmd)
       
   188     if ctx.argc < 4:
       
   189         usage(EX_MISSING_ARGS, _(u'Missing new configuration value.'),
       
   190               ctx.scmd)
       
   191     ctx.hdlr.cfg_set(ctx.args[2].lower(), ctx.args[3])
   170 
   192 
   171 
   193 
   172 def configure(ctx):
   194 def configure(ctx):
   173     """start interactive configuration modus"""
   195     """start interactive configuration modus"""
   174     if ctx.argc < 3:
   196     if ctx.argc < 3:
   575                            'address',
   597                            'address',
   576                            _(u'delete the record of the relocated user')),
   598                            _(u'delete the record of the relocated user')),
   577     'relocatedinfo': cmd('relocatedinfo', 'ri', relocated_info, 'address',
   599     'relocatedinfo': cmd('relocatedinfo', 'ri', relocated_info, 'address',
   578                          _(u'print information about a relocated user')),
   600                          _(u'print information about a relocated user')),
   579     # cli commands
   601     # cli commands
       
   602     'configget': cmd('configget', 'cg', config_get, 'option',
       
   603                      _('show the actual value of the configuration option')),
       
   604     'configset': cmd('configset', 'cs', config_set, 'option value',
       
   605                       _('set a new value for the configuration option')),
   580     'configure': cmd('configure', 'cf', configure, '[section]',
   606     'configure': cmd('configure', 'cf', configure, '[section]',
   581                      _(u'start interactive configuration modus')),
   607                      _(u'start interactive configuration modus')),
   582     'help': cmd('help', 'h', help_, '[subcommand]',
   608     'help': cmd('help', 'h', help_, '[subcommand]',
   583                 _(u'show a help overview or help for the given subcommand')),
   609                 _(u'show a help overview or help for the given subcommand')),
   584     'version': cmd('version', 'v', version, '',
   610     'version': cmd('version', 'v', version, '',