* 'create_tables.pgsql'
* 'update_tables_0.4.x-0.5.pgsql'
- Changed length of address column in table from varchar(256) to varchar(64)
because only the local part will be stored.
* 'UPGRADE'
- Updated, privileges on view postfix_alias have to be set once again.
#!/usr/bin/env python# -*- coding: UTF-8 -*-# Copyright 2007-2008 VEB IT# See COPYING for distribution information.# $Id$"""Configurtion class for read, modify and write theconfiguration from Virtual Mail Manager."""fromconstants.VERSIONimportVERSION__author__='Pascal Volk <p.volk@veb-it.de>'__version__=VERSION__revision__='rev '+'$Rev$'.split()[1]__date__='$Date$'.split()[1]importlocaleimportsysfromshutilimportcopy2fromConfigParserimportConfigParser,MissingSectionHeaderError,ParsingErrorfromcStringIOimportStringIOfromExceptionsimportVMMConfigExceptionimportconstants.ERRORasERRlocale.setlocale(locale.LC_ALL,'')ENCODING=locale.nl_langinfo(locale.CODESET)classConfig(ConfigParser):"""This class is for configure the Virtual Mail Manager. You can specify settings for the database connection and maildirectories. """def__init__(self,filename):"""Creates a new Config instance Keyword arguments: filename -- name of the configuration file """ConfigParser.__init__(self)self.__cfgFileName=filenameself.__cfgFile=Noneself.__VMMsections=['database','maildir','services','domdir','bin','misc','config']self.__changes=Falseself.__missing={}self.__dbopts=[['host','localhot'],['user','vmm'],['pass','your secret password'],['name','mailsys']]self.__mdopts=[['folder','Maildir'],['mode',448],['diskusage','false'],['delete','false']]self.__serviceopts=[['smtp','true'],['pop3','true'],['imap','true'],['managesieve','true']]self.__domdopts=[['base','/srv/mail'],['mode',504],['delete','false']]self.__binopts=[['dovecotpw','/usr/sbin/dovecotpw'],['du','/usr/bin/du']]self.__miscopts=[['passwdscheme','PLAIN'],['gid_mail',8],['forcedel','false'],['transport','dovecot:']]defload(self):"""Loads the configuration, r/o"""try:self.__cfgFile=file(self.__cfgFileName,'r')self.readfp(self.__cfgFile)except(MissingSectionHeaderError,ParsingError),e:self.__cfgFile.close()raiseVMMConfigException(str(e),ERR.CONF_ERROR)self.__cfgFile.close()defcheck(self):ifnotself.__chkSections():errmsg=StringIO()fork,vinself.__missing.items():ifv[0]isTrue:errmsg.write(_(u"missing section: %s\n")%k)else:errmsg.write(_(u"missing options in section %s:\n")%k)foroinv:errmsg.write(" * %s\n"%o)raiseVMMConfigException(errmsg.getvalue(),ERR.CONF_ERROR)defgetsections(self):"""Return a list with all configurable sections."""returnself.__VMMsections[:-1]defconfigure(self,sections):"""Interactive method for configuring all options in the given section Keyword arguments: sections -- list of strings """ifnotisinstance(sections,list):raiseTypeError("Argument 'sections' is not a list.")# if [config] done = false (default at 1st run),# then set changes truetry:ifnotself.getboolean('config','done'):self.__changes=TrueexceptValueError:self.set('config','done','False')self.__changes=Trueforsinsections:ifs!='config':print_(u'* Config section: »%s«')%sforopt,valinself.items(s):newval=raw_input(_('Enter new value for option %(opt)s [%(val)s]: ').encode(ENCODING,'replace')%{'opt':opt,'val':val})ifnewvalandnewval!=val:self.set(s,opt,newval)self.__changes=Trueprintifself.__changes:self.__saveChanges()def__saveChanges(self):"""Writes changes to the configuration file."""self.set('config','done','true')copy2(self.__cfgFileName,self.__cfgFileName+'.bak')self.__cfgFile=file(self.__cfgFileName,'w')self.write(self.__cfgFile)self.__cfgFile.close()def__chkSections(self):"""Checks if all configuration sections are existing."""errors=Falseforsinself.__VMMsections:ifnotself.has_section(s):self.__missing[s]=[True]elifnotself.__chkOptions(s):errors=Truereturnnoterrorsdef__chkOptions(self,section):"""Checks if all configuration options in section are existing. Keyword arguments: section -- the section to be checked """retval=Truemissing=[]ifsection=='database':opts=self.__dboptselifsection=='maildir':opts=self.__mdoptselifsection=='services':opts=self.__serviceoptselifsection=='domdir':opts=self.__domdoptselifsection=='bin':opts=self.__binoptselifsection=='misc':opts=self.__miscoptselifsection=='config':opts=[['done','false']]foro,vinopts:ifnotself.has_option(section,o):missing.append(o)retval=Falseiflen(missing):self.__missing[section]=missingreturnretval