Provide list{addresses,aliases,users,relocated} subcommands
The patch provides the list{addresses,aliases,users,relocated} subcommands to
the UI. All commands actually take the same path in the code and only one
query is run with different parameters for each case.
There are still two shortcomings:
1. With alias domains, the output order is not as one might want it, e.g.
foo@example.org
bar@example.org
foo@example.com
bar@example.com
when it should really be foo@ twice and then bar@ twice. I have not found
a way to modify the SQL accordingly.
2. The SELECT queries for Accounts, Alias and Relocated are hard-coded in
common.py.
# -*- coding: UTF-8 -*-# Copyright 2007 - 2011, Pascal Volk# See COPYING for distribution information.""" VirtualMailManager.cli.main ~~~~~~~~~~~~~~~~~~~~~~~~~~~ VirtualMailManager's command line interface."""fromConfigParserimportNoOptionError,NoSectionErrorfromVirtualMailManagerimportENCODING,errorsfromVirtualMailManager.configimportBadOptionError,ConfigValueErrorfromVirtualMailManager.cliimportw_errfromVirtualMailManager.cli.handlerimportCliHandlerfromVirtualMailManager.constantsimportDATABASE_ERROR,EX_MISSING_ARGS, \EX_SUCCESS,EX_UNKNOWN_COMMAND,EX_USER_INTERRUPT,INVALID_ARGUMENTfromVirtualMailManager.cli.subcommandsimportRunContext,cmd_map, \update_cmd_map,usage_=lambdamsg:msgdef_get_handler():"""Try to get a CliHandler. Exit the program when an error occurs."""try:handler=CliHandler()except(errors.NotRootError,errors.PermissionError,errors.VMMError,errors.ConfigError),err:w_err(err.code,_(u'Error: %s')%err.msg)else:handler.cfg_install()returnhandlerdefrun(argv):update_cmd_map()iflen(argv)<2:usage(EX_MISSING_ARGS,_(u"You must specify a subcommand at least."))sub_cmd=argv[1].lower()ifsub_cmdincmd_map:cmd_func=cmd_map[sub_cmd].funcelse:forcmdincmd_map.itervalues():ifcmd.alias==sub_cmd:cmd_func=cmd.funcsub_cmd=cmd.namebreakelse:usage(EX_UNKNOWN_COMMAND,_(u"Unknown subcommand: '%s'")%sub_cmd)handler=_get_handler()run_ctx=RunContext(argv,handler,sub_cmd)try:cmd_func(run_ctx)except(EOFError,KeyboardInterrupt):# TP: We have to cry, because root has killed/interrupted vmm# with Ctrl+C or Ctrl+D.w_err(EX_USER_INTERRUPT,'',_(u'Ouch!'),'')excepterrors.VMMError,err:iferr.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)exceptNoSectionError,err:w_err(INVALID_ARGUMENT,_(u"Error: Unknown section: '%s'")%err.section)exceptNoOptionError,err:w_err(INVALID_ARGUMENT,_(u"Error: No option '%(option)s' in section: '%(section)s'")%{'option':err.option,'section':err.section})ifhandler.has_warnings():w_err(0,_(u'Warnings:'),*handler.get_warnings())returnEX_SUCCESSdel_