Converted VirtualMailManager and Postconf to new-style classes.
A few small cleanups.
--- a/INSTALL Fri Aug 21 11:25:14 2009 +0000
+++ b/INSTALL Fri Aug 21 17:42:22 2009 +0000
@@ -26,7 +26,7 @@
* Create Database and db users for Postfix and Dovecot
connecting to PostgreSQL:
psql template1
-
+
# create database
CREATE DATABASE mailsys ENCODING 'UTF8';
# connect to the new database
--- a/UPGRADE Fri Aug 21 11:25:14 2009 +0000
+++ b/UPGRADE Fri Aug 21 17:42:22 2009 +0000
@@ -8,7 +8,7 @@
* stop Postfix and Dovecot
* backup/dump your database.
* backup/dump your database!
-
+
* start psql and connect to the appropriate database
(ex. psql mailsys mailsys vmm -W -h localhost)
* update the database: \i update_tables_0.4.x-0.5.pgsql
@@ -29,7 +29,7 @@
* You have also to adjust the permissions of the set-uid deliver copy:
chgrp nogroup /usr/local/lib/dovecot/deliver
- chmod u+s,o-rwx /usr/local/lib/dovecot/deliver
+ chmod u+s,o-rwx /usr/local/lib/dovecot/deliver
* execute upgrade.sh
--- a/VirtualMailManager/Account.py Fri Aug 21 11:25:14 2009 +0000
+++ b/VirtualMailManager/Account.py Fri Aug 21 17:42:22 2009 +0000
@@ -144,7 +144,7 @@
else:
raise AccE(_(u'The account »%s« already exists.') % self._addr,
ERR.ACCOUNT_EXISTS)
-
+
def modify(self, what, value):
if self._uid == 0:
raise AccE(_(u"The account »%s« doesn't exists.") % self._addr,
@@ -248,7 +248,7 @@
info = dbc.fetchone()
dbc.close()
if info is None:
- raise AccE(_(u"There is no account with the UID »%d«.") % uid,
+ raise AccE(_(u"There is no account with the UID »%d«.") % uid,
ERR.NO_SUCH_ACCOUNT)
keys = ['address', 'uid', 'gid']
info = dict(zip(keys, info))
--- a/VirtualMailManager/Config.py Fri Aug 21 11:25:14 2009 +0000
+++ b/VirtualMailManager/Config.py Fri Aug 21 17:42:22 2009 +0000
@@ -94,7 +94,7 @@
def check(self):
"""Performs a configuration check.
-
+
Raises a VMMConfigException if the check fails.
"""
if not self.__chkSections():
--- a/VirtualMailManager/Transport.py Fri Aug 21 11:25:14 2009 +0000
+++ b/VirtualMailManager/Transport.py Fri Aug 21 17:42:22 2009 +0000
@@ -17,7 +17,7 @@
"""Creates a new Transport instance.
Either tid or transport must be specified.
-
+
Keyword arguments:
dbh -- a pyPgSQL.PgSQL.connection
tid -- the id of a transport (long)
--- a/VirtualMailManager/VirtualMailManager.py Fri Aug 21 11:25:14 2009 +0000
+++ b/VirtualMailManager/VirtualMailManager.py Fri Aug 21 17:42:22 2009 +0000
@@ -37,16 +37,15 @@
locale.setlocale(locale.LC_ALL, '')
ENCODING = locale.nl_langinfo(locale.CODESET)
-class VirtualMailManager:
+class VirtualMailManager(object):
"""The main class for vmm"""
+ __slots__ = ('__Cfg', '__cfgFileName', '__cfgSections', '__dbh', '__scheme',
+ '__warnings', '_postconf')
def __init__(self):
"""Creates a new VirtualMailManager instance.
Throws a VMMNotRootException if your uid is greater 0.
"""
self.__cfgFileName = ''
- self.__permWarnMsg = _(u"fix permissions for »%(cfgFileName)s«\n\
-`chmod 0600 %(cfgFileName)s` would be great.") % {'cfgFileName':
- self.__cfgFileName}
self.__warnings = []
self.__Cfg = None
self.__dbh = None
@@ -82,7 +81,10 @@
fmode = int(oct(fstat.st_mode & 0777))
if fmode % 100 and fstat.st_uid != fstat.st_gid \
or fmode % 10 and fstat.st_uid == fstat.st_gid:
- raise VMMPermException(self.__permWarnMsg, ERR.CONF_ERROR)
+ raise VMMPermException(_(
+ u'fix permissions (%(perms)s) for »%(file)s«\n\
+`chmod 0600 %(file)s` would be great.') % {'file':
+ self.__cfgFileName, 'perms': fmode}, ERR.CONF_WRONGPERM)
else:
return True
@@ -126,7 +128,7 @@
def idn2ascii(domainname):
"""Converts an idn domainname in punycode.
-
+
Keyword arguments:
domainname -- the domainname to convert (str)
"""
@@ -140,7 +142,7 @@
def ace2idna(domainname):
"""Convertis a domainname from ACE according to IDNA
-
+
Keyword arguments:
domainname -- the domainname to convert (str)
"""
@@ -154,7 +156,7 @@
def chkDomainname(domainname):
"""Validates the domain name of an e-mail address.
-
+
Keyword arguments:
domainname -- the domain name that should be validated
"""
@@ -247,7 +249,7 @@
def __getDiskUsage(self, directory):
"""Estimate file space usage for the given directory.
-
+
Keyword arguments:
directory -- the directory to summarize recursively disk usage for
"""
@@ -612,7 +614,7 @@
alias.save(long(self._postconf.read('virtual_alias_expansion_limit')))
gid = self.__getDomain(alias._dest._domainname).getID()
if gid > 0 and not VirtualMailManager.accountExists(self.__dbh,
- alias._dest) and not VirtualMailManager.aliasExists(self.__dbh,
+ alias._dest) and not VirtualMailManager.aliasExists(self.__dbh,
alias._dest):
self.__warnings.append(
_(u"The destination account/alias »%s« doesn't exists yet.")%\
--- a/VirtualMailManager/constants/ERROR.py Fri Aug 21 11:25:14 2009 +0000
+++ b/VirtualMailManager/constants/ERROR.py Fri Aug 21 17:42:22 2009 +0000
@@ -48,3 +48,4 @@
UNKNOWN_MAILLOCATION_ID = 63
UNKNOWN_SERVICE = 64
UNKNOWN_TRANSPORT_ID = 65
+VMM_ERROR = 66
--- a/VirtualMailManager/ext/Postconf.py Fri Aug 21 11:25:14 2009 +0000
+++ b/VirtualMailManager/ext/Postconf.py Fri Aug 21 17:42:22 2009 +0000
@@ -15,12 +15,13 @@
RE_PC_PARAMS = """^\w+$"""
RE_PC_VARIABLES = r"""\$\b\w+\b"""
-class Postconf:
+class Postconf(object):
+ __slots__ = ('__bin', '__val', '__varFinder')
def __init__(self, postconf_bin):
"""Creates a new Postconf instance.
-
+
Keyword arguments:
- postconf_bin -- absolute path to Postfix' postconf binary (str)
+ postconf_bin -- absolute path to the Postfix postconf binary (str)
"""
self.__bin = postconf_bin
self.__val = ''
@@ -29,7 +30,7 @@
def read(self, parameter, expand_vars=True):
"""Returns the parameters value.
- If expand_vars is True (default), all variables in the value will be
+ If expand_vars is True (default), all variables in the value will be
expanded:
e.g. mydestination -> mail.example.com, localhost.example.com, localhost
Otherwise the value may contain one or more variables.
@@ -41,7 +42,7 @@
"""
if not re.match(RE_PC_PARAMS, parameter):
raise VMMException(_(u'The value »%s« looks not like a valid\
- postfix configuration parameter name.') % parameter, ERR.INVALID_AGUMENT)
+ postfix configuration parameter name.') % parameter, ERR.VMM_ERROR)
self.__val = self.__read(parameter)
if expand_vars:
self.__expandVars()
@@ -67,7 +68,7 @@
out, err = Popen([self.__bin, '-h', parameter], stdout=PIPE,
stderr=PIPE).communicate()
if len(err):
- raise Exception, err.strip()
+ raise VMMException(err.strip(), ERR.VMM_ERROR)
return out.strip()
def __readMulti(self, parameters):
@@ -76,7 +77,7 @@
cmd.append(parameter[1:])
out, err = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
if len(err):
- raise Exception, err.strip()
+ raise VMMException(err.strip(), ERR.VMM_ERROR)
par_val = {}
for line in out.splitlines():
par, val = line.split(' = ')