# HG changeset patch # User Pascal Volk # Date 1281066334 0 # Node ID 9232ed7e4d85ce40e5fc65cdc9c5b2409ac82e35 # Parent b0c971f943dca7afc1326e7578fd4360098e3329 VMM/cli/main: Except more errors and handle them correct. diff -r b0c971f943dc -r 9232ed7e4d85 VirtualMailManager/cli/main.py --- a/VirtualMailManager/cli/main.py Fri Aug 06 02:15:16 2010 +0000 +++ b/VirtualMailManager/cli/main.py Fri Aug 06 03:45:34 2010 +0000 @@ -8,25 +8,31 @@ VirtualMailManager's command line interface. """ +from ConfigParser import NoOptionError, NoSectionError + from VirtualMailManager import ENCODING, errors -from VirtualMailManager.config import ConfigValueError +from VirtualMailManager.config import BadOptionError, ConfigValueError from VirtualMailManager.cli import w_err from VirtualMailManager.cli.handler import CliHandler -from VirtualMailManager.constants import DATABASE_ERROR, EX_MISSING_ARGS, \ - EX_SUCCESS, EX_UNKNOWN_COMMAND, EX_USER_INTERRUPT +from VirtualMailManager.constants import CONF_ERROR, DATABASE_ERROR, \ + EX_MISSING_ARGS, EX_SUCCESS, EX_UNKNOWN_COMMAND, EX_USER_INTERRUPT, \ + INVALID_ARGUMENT from VirtualMailManager.cli.subcommands import RunContext, cmd_map, usage _ = lambda msg: msg + def _get_handler(): """Try to get a CliHandler. Exit the program when an error occurs.""" try: handler = CliHandler() handler.cfg_install() except (errors.NotRootError, errors.PermissionError, errors.VMMError, - errors.ConfigError, ConfigValueError), err: + errors.ConfigError), err: w_err(err.code, _(u'Error: %s') % err.msg) + except ConfigValueError, err: + w_err(CONF_ERROR, _(u'Error: %s') % err) else: return handler @@ -59,6 +65,14 @@ if err.code != DATABASE_ERROR: w_err(err.code, _(u'Error: %s') % err.msg) w_err(err.code, unicode(err.msg, ENCODING, 'replace')) + except (BadOptionError, ConfigValueError), err: + w_err(INVALID_ARGUMENT, _(u'Error: %s') % err) + except NoSectionError, err: + w_err(INVALID_ARGUMENT, _(u"Error: No section '%s'") % err.section) + except NoOptionError, err: + w_err(INVALID_ARGUMENT, + _(u"Error: No option '%(option)s' in section: '%(section)s'") % + {'option': err.option, 'section': err.section}) if handler.has_warnings(): w_err(0, _(u'Warnings:'), *handler.get_warnings()) return EX_SUCCESS