VirtualMailManager/cli/main.py
branchv0.6.x
changeset 354 a653c43048b1
parent 343 9232ed7e4d85
child 366 d6573da35b5f
equal deleted inserted replaced
353:2ae40cd0d213 354:a653c43048b1
    12 
    12 
    13 from VirtualMailManager import ENCODING, errors
    13 from VirtualMailManager import ENCODING, errors
    14 from VirtualMailManager.config import BadOptionError, ConfigValueError
    14 from VirtualMailManager.config import BadOptionError, ConfigValueError
    15 from VirtualMailManager.cli import w_err
    15 from VirtualMailManager.cli import w_err
    16 from VirtualMailManager.cli.handler import CliHandler
    16 from VirtualMailManager.cli.handler import CliHandler
    17 from VirtualMailManager.constants import CONF_ERROR, DATABASE_ERROR, \
    17 from VirtualMailManager.constants import DATABASE_ERROR, EX_MISSING_ARGS, \
    18      EX_MISSING_ARGS, EX_SUCCESS, EX_UNKNOWN_COMMAND, EX_USER_INTERRUPT, \
    18      EX_SUCCESS, EX_UNKNOWN_COMMAND, EX_USER_INTERRUPT, INVALID_ARGUMENT
    19      INVALID_ARGUMENT
       
    20 from VirtualMailManager.cli.subcommands import RunContext, cmd_map, usage
    19 from VirtualMailManager.cli.subcommands import RunContext, cmd_map, usage
    21 
    20 
    22 
    21 
    23 _ = lambda msg: msg
    22 _ = lambda msg: msg
    24 
    23 
    25 
    24 
    26 def _get_handler():
    25 def _get_handler():
    27     """Try to get a CliHandler. Exit the program when an error occurs."""
    26     """Try to get a CliHandler. Exit the program when an error occurs."""
    28     try:
    27     try:
    29         handler = CliHandler()
    28         handler = CliHandler()
    30         handler.cfg_install()
       
    31     except (errors.NotRootError, errors.PermissionError, errors.VMMError,
    29     except (errors.NotRootError, errors.PermissionError, errors.VMMError,
    32             errors.ConfigError), err:
    30             errors.ConfigError), err:
    33         w_err(err.code, _(u'Error: %s') % err.msg)
    31         w_err(err.code, _(u'Error: %s') % err.msg)
    34     except ConfigValueError, err:
       
    35         w_err(CONF_ERROR, _(u'Error: %s') % err)
       
    36     else:
    32     else:
       
    33         handler.cfg_install()
    37         return handler
    34         return handler
    38 
    35 
    39 
    36 
    40 def run(argv):
    37 def run(argv):
    41     if len(argv) < 2:
    38     if len(argv) < 2: