VMM/Alias: renamed Alias.add_destination() to add_destinations().
Now it's possible to add one ore more destinations to the alias with a
single method call.
VMM/Handler: adjusted Handler.aliasAdd() to the API changes of the Alias
class. Also use get_gid from the Domain module to get the gid of a
domain. We don't need complete Domain object, only the gid.
Handler.getWarnings(): no longer return the __warnings list. Return a
copy instead and empty the Handler.__warnings list.
# -*- coding: UTF-8 -*-# Copyright (c) 2010, Pascal Volk# See COPYING for distribution information.""" VirtualMailManager.cli.CliConfig Adds some interactive stuff to the Config class."""fromConfigParserimportRawConfigParserfromshutilimportcopy2fromVirtualMailManagerimportENCODINGfromVirtualMailManager.ConfigimportConfig,ConfigValueError,LazyConfigfromVirtualMailManager.errorsimportConfigErrorfromVirtualMailManager.cliimportw_stdfromVirtualMailManager.constants.ERRORimportVMM_TOO_MANY_FAILURESclassCliConfig(Config):"""Adds the interactive ``configure`` method to the `Config` class and overwrites `LazyConfig.set(), in order to update a single option in the configuration file with a single command line command. """defconfigure(self,sections):"""Interactive method for configuring all options of the given iterable ``sections`` object."""input_fmt=_(u'Enter new value for option %(option)s\[%(current_value)s]: ')failures=0w_std(_(u'Using configuration file: %s\n')%self._cfg_filename)forsinsections:w_std(_(u'* Configuration section: %r')%s)foropt,valinself.items(s):failures=0whileTrue:newval=raw_input(input_fmt.encode(ENCODING,'replace')%{'option':opt,'current_value':val})ifnewvalandnewval!=val:try:LazyConfig.set(self,'%s.%s'%(s,opt),newval)breakexcept(ValueError,ConfigValueError),e:w_std(_(u'Warning: %s')%e)failures+=1iffailures>2:raiseConfigError(_(u'Too many failures - try again later.'),VMM_TOO_MANY_FAILURES)else:breakprintifself._modified:self.__saveChanges()defset(self,option,value):"""Set the value of an option. If the new `value` has been set, the configuration file will be immediately updated. Throws a ``ValueError`` if `value` couldn't be converted to ``LazyConfigOption.cls``"""section,option_=self._get_section_option(option)val=self._cfg[section][option_].cls(value)ifself._cfg[section][option_].validate:val=self._cfg[section][option_].validate(val)# Do not write default values also skip identical valuesifnotself._cfg[section][option_].defaultisNone:old_val=self.dget(option)else:old_val=self.pget(option)ifval==old_val:returnifnotRawConfigParser.has_section(self,section):self.add_section(section)RawConfigParser.set(self,section,option_,val)self.__saveChanges()def__saveChanges(self):"""Writes changes to the configuration file."""copy2(self._cfg_filename,self._cfg_filename+'.bak')self._cfg_file=open(self._cfg_filename,'w')self.write(self._cfg_file)self._cfg_file.close()