# HG changeset patch # User Pascal Volk # Date 1219113643 0 # Node ID 0d5f58f8b8f57f4c6073176e2ef1997ce137ec0a # Parent 191d5a5adc4af29303af2fbfa904af479a334f2c * 'VirtualMailManager/Exceptions.py' - Rewrote class VMMException and all derived VMM*Exception classes. Affected files in VirtualMailManager/: + '../vmm' + 'Account.py' + 'Alias.py' + 'Config.py' + 'Domain.py' + 'MailLocation.py' + 'Transport.py' + 'VirtualMailManager.py' * 'VirtualMailManager/Config.py' - Some code cleanups/fixes in: + VMMConfig.load() + VMMConfig.configure() * 'VirtualMailManager/DomainAlias.py' - Added to repository * 'VirtualMailManager/VirtualMailManager.py' - Some code cleanups in: + VirtualMailManager.__chkCfgFile() + VirtualMailManager.__getFileMode() removed + VirtualMailManager.configure() * 'vmm' - Rewrote: + usage() + configure() + __main__ - Implemented show_version() * 'po/de.po' * 'po/vmm.pot' - updated diff -r 191d5a5adc4a -r 0d5f58f8b8f5 VirtualMailManager/Account.py --- a/VirtualMailManager/Account.py Mon Aug 18 01:56:31 2008 +0000 +++ b/VirtualMailManager/Account.py Tue Aug 19 02:40:43 2008 +0000 @@ -37,8 +37,8 @@ self._exists() if self._isAlias(): raise VMMAccountException( - (_(u"There is already an alias with the address »%s«.") % address, - ERR.ALIAS_EXISTS)) + _(u"There is already an alias with the address »%s«.") % address, + ERR.ALIAS_EXISTS) def _exists(self): dbc = self._dbh.cursor() @@ -69,8 +69,8 @@ dom = Domain(self._dbh, d) self._gid = dom.getID() if self._gid == 0: - raise VMMAccountException((_(u"Domain »%s« doesn't exist.") % d, - ERR.NO_SUCH_DOMAIN)) + raise VMMAccountException(_(u"Domain »%s« doesn't exist.") % d, + ERR.NO_SUCH_DOMAIN) self._base = dom.getDir() self._tid = dom.getTransportID() @@ -88,11 +88,11 @@ if not isinstance(state, bool): return False if not service in ['smtp', 'pop3', 'imap', 'managesieve', 'all', None]: - raise VMMAccountException((_(u"Unknown service »%s«.") % service, - ERR.UNKNOWN_SERVICE)) + raise VMMAccountException(_(u"Unknown service »%s«.") % service, + ERR.UNKNOWN_SERVICE) if self._uid < 1: - raise VMMAccountException((_(u"The account »%s« doesn't exists.") % - self._addr, ERR.NO_SUCH_ACCOUNT)) + raise VMMAccountException(_(u"The account »%s« doesn't exists.") % + self._addr, ERR.NO_SUCH_ACCOUNT) dbc = self._dbh.cursor() if service in ['smtp', 'pop3', 'imap', 'managesieve']: dbc.execute( @@ -143,13 +143,13 @@ self._dbh.commit() dbc.close() else: - raise VMMAccountException((_(u'The account »%s« already exists.') % - self._addr, ERR.ACCOUNT_EXISTS)) + raise VMMAccountException(_(u'The account »%s« already exists.') % + self._addr, ERR.ACCOUNT_EXISTS) def modify(self, what, value): if self._uid == 0: - raise VMMAccountException((_(u"The account »%s« doesn't exists.") % - self._addr, ERR.NO_SUCH_ACCOUNT)) + raise VMMAccountException(_(u"The account »%s« doesn't exists.") % + self._addr, ERR.NO_SUCH_ACCOUNT) if what not in ['name', 'password', 'transport']: return False dbc = self._dbh.cursor() @@ -175,8 +175,8 @@ info = dbc.fetchone() dbc.close() if info is None: - raise VMMAccountException((_(u"The account »%s« doesn't exists.") % - self._addr, ERR.NO_SUCH_ACCOUNT)) + raise VMMAccountException(_(u"The account »%s« doesn't exists.") % + self._addr, ERR.NO_SUCH_ACCOUNT) else: keys = ['name', 'uid', 'gid', 'maildir', 'transport', 'smtp', 'pop3', 'imap', 'managesieve'] @@ -203,19 +203,19 @@ self._dbh.commit() dbc.close() else: - raise VMMAccountException((_(u"The account »%s« doesn't exists.") % - self._addr, ERR.NO_SUCH_ACCOUNT)) + raise VMMAccountException(_(u"The account »%s« doesn't exists.") % + self._addr, ERR.NO_SUCH_ACCOUNT) def getAccountByID(uid, dbh): try: uid = long(uid) except ValueError: - raise VMMAccountException((_(u'uid must be an int/long.'), - ERR.INVALID_AGUMENT)) + raise VMMAccountException(_(u'uid must be an int/long.'), + ERR.INVALID_AGUMENT) if uid < 1: - raise VMMAccountException((_(u'uid must be greater than 0.'), - ERR.INVALID_AGUMENT)) + raise VMMAccountException(_(u'uid must be greater than 0.'), + ERR.INVALID_AGUMENT) dbc = dbh.cursor() dbc.execute("SELECT local_part||'@'|| domain_name.domainname AS address,\ uid, users.gid FROM users LEFT JOIN domain_name ON (domain_name.gid \ @@ -223,9 +223,9 @@ info = dbc.fetchone() dbc.close() if info is None: - raise VMMAccountException(( + raise VMMAccountException( _(u"There is no account with the UID »%d«.") % uid, - ERR.NO_SUCH_ACCOUNT)) + ERR.NO_SUCH_ACCOUNT) keys = ['address', 'uid', 'gid'] info = dict(zip(keys, info)) return info diff -r 191d5a5adc4a -r 0d5f58f8b8f5 VirtualMailManager/Alias.py --- a/VirtualMailManager/Alias.py Mon Aug 18 01:56:31 2008 +0000 +++ b/VirtualMailManager/Alias.py Tue Aug 19 02:40:43 2008 +0000 @@ -21,9 +21,9 @@ """Class to manage e-mail accounts.""" def __init__(self, dbh, address, destination=None): if address == destination: - raise VMMAliasException(( - _('Address and destination are identical.'), - ERR.ALIAS_ADDR_DEST_IDENTICAL)) + raise VMMAliasException( + _(u'Address and destination are identical.'), + ERR.ALIAS_ADDR_DEST_IDENTICAL) self._dbh = dbh self._addr = address self._dest = destination @@ -35,8 +35,8 @@ self._exists() if self._isAccount(): raise VMMAliasException( - (_(u"There is already an account with address '%s'") % self._addr, - ERR.ACCOUNT_EXISTS)) + _(u"There is already an account with address '%s'") % self._addr, + ERR.ACCOUNT_EXISTS) def _exists(self): dbc = self._dbh.cursor() @@ -65,14 +65,14 @@ dom = Domain(self._dbh, d) self._gid = dom.getID() if self._gid == 0: - raise VMMAliasException((_(u"Domain '%s' doesn't exist.") % d, - ERR.NO_SUCH_DOMAIN)) + raise VMMAliasException(_(u"Domain '%s' doesn't exist.") % d, + ERR.NO_SUCH_DOMAIN) def save(self): if self._dest is None: - raise VMMAliasException(( + raise VMMAliasException( _('No destination address for alias denoted.'), - ERR.ALIAS_MISSING_DEST)) + ERR.ALIAS_MISSING_DEST) if self._isNew: dbc = self._dbh.cursor() dbc.execute("INSERT INTO alias (gid, address, destination) VALUES\ @@ -80,8 +80,8 @@ self._dbh.commit() dbc.close() else: - raise VMMAliasException((_("Alias already exists."), - ERR.ALIAS_EXISTS)) + raise VMMAliasException(_("Alias already exists."), + ERR.ALIAS_EXISTS) def getInfo(self): dbc = self._dbh.cursor() @@ -95,8 +95,8 @@ targets.append(destination[0]) return targets else: - raise VMMAliasException((_("Alias doesn't exists"), - ERR.NO_SUCH_ALIAS)) + raise VMMAliasException(_("Alias doesn't exists"), + ERR.NO_SUCH_ALIAS) def delete(self): dbc = self._dbh.cursor() @@ -111,6 +111,6 @@ if rowcount > 0: self._dbh.commit() else: - raise VMMAliasException((_("Alias doesn't exists"), - ERR.NO_SUCH_ALIAS)) + raise VMMAliasException(_("Alias doesn't exists"), + ERR.NO_SUCH_ALIAS) diff -r 191d5a5adc4a -r 0d5f58f8b8f5 VirtualMailManager/Config.py --- a/VirtualMailManager/Config.py Mon Aug 18 01:56:31 2008 +0000 +++ b/VirtualMailManager/Config.py Tue Aug 19 02:40:43 2008 +0000 @@ -19,7 +19,7 @@ import locale import sys from shutil import copy2 -from ConfigParser import ConfigParser +from ConfigParser import ConfigParser, MissingSectionHeaderError, ParsingError from cStringIO import StringIO from Exceptions import VMMConfigException @@ -87,9 +87,10 @@ """Loads the configuration, r/o""" try: self.__cfgFile = file(self.__cfgFileName, 'r') - except: - raise - self.readfp(self.__cfgFile) + self.readfp(self.__cfgFile) + except (MissingSectionHeaderError, ParsingError), e: + self.__cfgFile.close() + raise VMMConfigException(str(e), ERR.CONF_ERROR) self.__cfgFile.close() def check(self): @@ -102,7 +103,7 @@ errmsg.write(_(u"missing options in section %s:\n") % k) for o in v: errmsg.write(" * %s\n" % o) - raise VMMConfigException((errmsg.getvalue(), ERR.CONF_ERROR)) + raise VMMConfigException(errmsg.getvalue(), ERR.CONF_ERROR) def getsections(self): """Return a list with all configurable sections.""" @@ -125,9 +126,7 @@ self.set('config', 'done', 'False') self.__changes = True for s in sections: - if s == 'config': - pass - else: + if s != 'config': print _(u'* Config section: »%s«') % s for opt, val in self.items(s): newval = raw_input( diff -r 191d5a5adc4a -r 0d5f58f8b8f5 VirtualMailManager/Domain.py --- a/VirtualMailManager/Domain.py Mon Aug 18 01:56:31 2008 +0000 +++ b/VirtualMailManager/Domain.py Tue Aug 19 02:40:43 2008 +0000 @@ -70,11 +70,11 @@ if result is None: return False elif result[1]: - raise VMMDomainException((_('Domain already exists.'), - ERR.DOMAIN_EXISTS)) + raise VMMDomainException(_('Domain already exists.'), + ERR.DOMAIN_EXISTS) else: - raise VMMDomainException((_('Domain alias already exists.'), - ERR.DOMAIN_ALIAS_EXISTS)) + raise VMMDomainException(_('Domain alias already exists.'), + ERR.DOMAIN_ALIAS_EXISTS) def _setID(self): """Sets the ID of the domain.""" @@ -127,14 +127,14 @@ else: hasAlias = False if hasUser and hasAlias: - raise VMMDomainException((_('There are accounts and aliases.'), - ERR.ACCOUNT_AND_ALIAS_PRESENT)) + raise VMMDomainException(_('There are accounts and aliases.'), + ERR.ACCOUNT_AND_ALIAS_PRESENT) elif hasUser: - raise VMMDomainException((_('There are accounts.'), - ERR.ACCOUNT_PRESENT)) + raise VMMDomainException(_('There are accounts.'), + ERR.ACCOUNT_PRESENT) elif hasAlias: - raise VMMDomainException((_('There are aliases.'), - ERR.ALIAS_PRESENT)) + raise VMMDomainException(_('There are aliases.'), + ERR.ALIAS_PRESENT) def save(self): """Stores the new domain in the database.""" @@ -148,8 +148,8 @@ self._dbh.commit() dbc.close() else: - raise VMMDomainException((_('Domain already exists.'), - ERR.DOMAIN_EXISTS)) + raise VMMDomainException(_('Domain already exists.'), + ERR.DOMAIN_EXISTS) def delete(self, delUser=False, delAlias=False): """Deletes the domain. @@ -166,8 +166,8 @@ self._dbh.commit() dbc.close() else: - raise VMMDomainException((_("Domain doesn't exist yet."), - ERR.NO_SUCH_DOMAIN)) + raise VMMDomainException(_("Domain doesn't exist yet."), + ERR.NO_SUCH_DOMAIN) def updateTransport(self, transport, force = False): """Sets a new transport for the domain. @@ -190,8 +190,8 @@ self._dbh.commit() dbc.close() else: - raise VMMDomainException((_("Domain doesn't exist yet."), - ERR.NO_SUCH_DOMAIN)) + raise VMMDomainException(_("Domain doesn't exist yet."), + ERR.NO_SUCH_DOMAIN) def saveAlias(self, aliasname): """Stores the alias name for the domain in the database. @@ -207,8 +207,8 @@ self._dbh.commit() dbc.close() else: - raise VMMDomainException((_("Domain doesn't exist yet."), - ERR.NO_SUCH_DOMAIN)) + raise VMMDomainException(_("Domain doesn't exist yet."), + ERR.NO_SUCH_DOMAIN) def getID(self): """Returns the ID of the domain.""" @@ -237,8 +237,8 @@ info = dbc.fetchone() dbc.close() if info is None: - raise VMMDomainException((_("Domain doesn't exist yet."), - ERR.NO_SUCH_DOMAIN)) + raise VMMDomainException(_("Domain doesn't exist yet."), + ERR.NO_SUCH_DOMAIN) else: keys = ['gid', 'domainname', 'transport', 'domaindir', 'aliasdomains', 'accounts', 'aliases'] diff -r 191d5a5adc4a -r 0d5f58f8b8f5 VirtualMailManager/DomainAlias.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VirtualMailManager/DomainAlias.py Tue Aug 19 02:40:43 2008 +0000 @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +# Copyright 2008 VEB IT +# See COPYING for distribution information. +# $Id$ + +"""Virtual Mail Manager's DomainAlias class to manage alias domains.""" + +from constants.VERSION import VERSION + +__author__ = 'Pascal Volk ' +__version__ = VERSION +__revision__ = 'rev '+'$Rev$'.split()[1] +__date__ = '$Date$'.split()[1] + +from Exceptions import VMMDomainAliasException as VDAE +import constants.ERROR as ERR + +class DomainAlias: + """Class to manage e-mail alias domains.""" + def __init__(self, dbh, domainname, targetDomain): + self._dbh = dbh + + def _exists(self): + pass + + def save(self): + pass + + def info(self): + pass + + def delete(self): + pass diff -r 191d5a5adc4a -r 0d5f58f8b8f5 VirtualMailManager/Exceptions.py --- a/VirtualMailManager/Exceptions.py Mon Aug 18 01:56:31 2008 +0000 +++ b/VirtualMailManager/Exceptions.py Tue Aug 19 02:40:43 2008 +0000 @@ -15,50 +15,60 @@ class VMMException(Exception): """Exception class for VirtualMailManager exceptions""" - def __init__(self, msg): + def __init__(self, msg, code): Exception.__init__(self, msg) + self._code = int(code) -class VMMConfigException(Exception): - """Exception class for Configurtion exceptions""" - def __init__(self, msg): - Exception.__init__(self, msg) + def msg(self): + """Returns the exception message.""" + return self.message + + def code(self): + """Returns the numeric exception error code.""" + return self._code -class VMMPermException(Exception): - """Exception class for permissions exceptions""" - pass +class VMMConfigException(VMMException): + """Exception class for Configurtion exceptions""" + def __init__(self, msg, code): + VMMException.__init__(self, msg, code) -class VMMNotRootException(Exception): +class VMMPermException(VMMException): + """Exception class for permissions exceptions""" + def __init__(self, msg, code): + VMMException.__init__(self, msg, code) + +class VMMNotRootException(VMMException): """Exception class for non-root exceptions""" - def __init__(self, msg): - Exception.__init__(self, msg) + def __init__(self, msg, code): + VMMException.__init__(self, msg, code) class VMMDomainException(VMMException): """Exception class for Domain exceptions""" - def __init__(self, msg): - VMMException.__init__(self, msg) + def __init__(self, msg, code): + VMMException.__init__(self, msg, code) class VMMDomainAliasException(VMMException): """Exception class for DomainAlias exceptions""" - def __init__(self, msg): - VMMException.__init__(self, msg) + def __init__(self, msg, code): + VMMException.__init__(self, msg, code) class VMMAccountException(VMMException): """Exception class for Account exceptions""" - def __init__(self, msg): - VMMException.__init__(self, msg) + def __init__(self, msg, code): + VMMException.__init__(self, msg, code) class VMMAliasException(VMMException): """Exception class for Alias exceptions""" - def __init__(self, msg): - VMMException.__init__(self, msg) + def __init__(self, msg, code): + VMMException.__init__(self, msg, code) class VMMMailLocationException(VMMException): """Exception class for MailLocation exceptions""" - def __init__(self, msg): - VMMException.__init__(self, msg) + def __init__(self, msg, code): + VMMException.__init__(self, msg, code) class VMMTransportException(VMMException): """Exception class for Transport exceptions""" - def __init__(self, msg): - VMMException.__init__(self, msg) + def __init__(self, msg, code): + VMMException.__init__(self, msg, code) diff -r 191d5a5adc4a -r 0d5f58f8b8f5 VirtualMailManager/MailLocation.py --- a/VirtualMailManager/MailLocation.py Mon Aug 18 01:56:31 2008 +0000 +++ b/VirtualMailManager/MailLocation.py Tue Aug 19 02:40:43 2008 +0000 @@ -31,13 +31,13 @@ """ self._dbh = dbh if mid is None and maillocation is None: - raise MLE((_('Either mid or maillocation must be specified.'), - ERR.MAILLOCATION_INIT)) + raise MLE(_('Either mid or maillocation must be specified.'), + ERR.MAILLOCATION_INIT) elif mid is not None: try: self.__id = long(mid) except ValueError: - raise MLE((_('mid must be an int/long.'),ERR.MAILLOCATION_INIT)) + raise MLE(_('mid must be an int/long.'), ERR.MAILLOCATION_INIT) self._loadByID() else: self.__maillocation = maillocation @@ -52,7 +52,7 @@ if result is not None: self.__maillocation = result[0] else: - raise MLE((_('Unknown mid specified.'),ERR.UNKNOWN_MAILLOCATION_ID)) + raise MLE(_('Unknown mid specified.'), ERR.UNKNOWN_MAILLOCATION_ID) def _loadByName(self): dbc = self._dbh.cursor() diff -r 191d5a5adc4a -r 0d5f58f8b8f5 VirtualMailManager/Transport.py --- a/VirtualMailManager/Transport.py Mon Aug 18 01:56:31 2008 +0000 +++ b/VirtualMailManager/Transport.py Tue Aug 19 02:40:43 2008 +0000 @@ -31,15 +31,15 @@ """ self._dbh = dbh if tid is None and transport is None: - raise VMMTransportException(( + raise VMMTransportException( _('Either tid or transport must be specified.'), - ERR.TRANSPORT_INIT)) + ERR.TRANSPORT_INIT) elif tid is not None: try: self.__id = long(tid) except ValueError: - raise VMMTransportException((_('tid must be an int/long.'), - ERR.TRANSPORT_INIT)) + raise VMMTransportException(_('tid must be an int/long.'), + ERR.TRANSPORT_INIT) self._loadByID() else: self.__transport = transport @@ -53,8 +53,8 @@ if result is not None: self.__transport = result[0] else: - raise VMMTransportException((_('Unknown tid specified.'), - ERR.UNKNOWN_TRANSPORT_ID)) + raise VMMTransportException(_('Unknown tid specified.'), + ERR.UNKNOWN_TRANSPORT_ID) def _loadByName(self): dbc = self._dbh.cursor() diff -r 191d5a5adc4a -r 0d5f58f8b8f5 VirtualMailManager/VirtualMailManager.py --- a/VirtualMailManager/VirtualMailManager.py Mon Aug 18 01:56:31 2008 +0000 +++ b/VirtualMailManager/VirtualMailManager.py Tue Aug 19 02:40:43 2008 +0000 @@ -51,8 +51,8 @@ self.__dbh = None if os.geteuid(): - raise VMMNotRootException((_(u"You are not root.\n\tGood bye!\n"), - ERR.CONF_NOPERM)) + raise VMMNotRootException(_(u"You are not root.\n\tGood bye!\n"), + ERR.CONF_NOPERM) if self.__chkCfgFile(): self.__Cfg = Cfg(self.__cfgFileName) self.__Cfg.load() @@ -65,16 +65,13 @@ def __chkCfgFile(self): """Checks the configuration file, returns bool""" if not os.path.isfile(self.__cfgFileName): - raise VMMException((_(u"The file »%s« does not exists.") % - self.__cfgFileName, ERR.CONF_NOFILE)) + raise VMMException(_(u"The file »%s« does not exists.") % + self.__cfgFileName, ERR.CONF_NOFILE) fstat = os.stat(self.__cfgFileName) - try: - fmode = self.__getFileMode() - except: - raise + 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(self.__permWarnMsg, ERR.CONF_ERROR) else: return True @@ -87,25 +84,18 @@ self.__Cfg.getint('misc', 'gid_mail')) os.umask(old_umask) elif not os.path.isdir(self.__Cfg.get('domdir', 'base')): - raise VMMException((_(u'»%s« is not a directory.\n\ + raise VMMException(_(u'»%s« is not a directory.\n\ (vmm.cfg: section "domdir", option "base")') % - self.__Cfg.get('domdir', 'base'), ERR.NO_SUCH_DIRECTORY)) + self.__Cfg.get('domdir', 'base'), ERR.NO_SUCH_DIRECTORY) for opt, val in self.__Cfg.items('bin'): if not os.path.exists(val): - raise VMMException((_(u'»%s« doesn\'t exists.\n\ -(vmm.cfg: section "bin", option "%s")') % (val, opt), ERR.NO_SUCH_BINARY)) + raise VMMException(_(u'»%s« doesn\'t exists.\n\ +(vmm.cfg: section "bin", option "%s")') % + (val, opt), ERR.NO_SUCH_BINARY) elif not os.access(val, os.X_OK): - raise VMMException((_(u'»%s« is not executable.\n\ -(vmm.cfg: section "bin", option "%s")') % (val, opt), ERR.NOT_EXECUTABLE)) - - def __getFileMode(self): - """Determines the file access mode from file __cfgFileName, - returns int. - """ - try: - return int(oct(os.stat(self.__cfgFileName).st_mode & 0777)) - except: - raise + raise VMMException(_(u'»%s« is not executable.\n\ +(vmm.cfg: section "bin", option "%s")') % + (val, opt), ERR.NOT_EXECUTABLE) def __dbConnect(self): """Creates a pyPgSQL.PgSQL.connection instance.""" @@ -120,7 +110,7 @@ dbc.execute("SET NAMES 'UTF8'") dbc.close() except PgSQL.libpq.DatabaseError, e: - raise VMMException((str(e), ERR.DATABASE_ERROR)) + raise VMMException(str(e), ERR.DATABASE_ERROR) def chkLocalpart(localpart): """Validates the local part of an e-mail address. @@ -129,19 +119,19 @@ localpart -- the e-mail address that should be validated (str) """ if len(localpart) < 1: - raise VMMException((_(u'No localpart specified.'), - ERR.LOCALPART_INVALID)) + raise VMMException(_(u'No localpart specified.'), + ERR.LOCALPART_INVALID) if len(localpart) > 64: - raise VMMException((_(u'The local part »%s« is too long') % - localpart, ERR.LOCALPART_TOO_LONG)) + raise VMMException(_(u'The local part »%s« is too long') % + localpart, ERR.LOCALPART_TOO_LONG) ic = re.compile(RE_LOCALPART).findall(localpart) if len(ic): ichrs = '' for c in set(ic): ichrs += u"»%s« " % c - raise VMMException(( + raise VMMException( _(u"The local part »%s« contains invalid characters: %s") % - (localpart, ichrs), ERR.LOCALPART_INVALID)) + (localpart, ichrs), ERR.LOCALPART_INVALID) return localpart chkLocalpart = staticmethod(chkLocalpart) @@ -184,12 +174,12 @@ if not re.match(RE_ASCII_CHARS, domainname): domainname = VirtualMailManager.idn2ascii(domainname) if len(domainname) > 255: - raise VMMException((_(u'The domain name is too long.'), - ERR.DOMAIN_TOO_LONG)) + raise VMMException(_(u'The domain name is too long.'), + ERR.DOMAIN_TOO_LONG) re.compile(RE_DOMAIN) if not re.match(RE_DOMAIN, domainname): - raise VMMException((_(u'The domain name is invalid.'), - ERR.DOMAIN_INVALID)) + raise VMMException(_(u'The domain name is invalid.'), + ERR.DOMAIN_INVALID) return domainname chkDomainname = staticmethod(chkDomainname) @@ -197,11 +187,11 @@ try: localpart, domain = address.split('@') except ValueError: - raise VMMException((_(u"Missing '@' sign in e-mail address »%s«.") % - address, ERR.INVALID_ADDRESS)) + raise VMMException(_(u"Missing '@' sign in e-mail address »%s«.") % + address, ERR.INVALID_ADDRESS) except AttributeError: - raise VMMException((_(u"»%s« looks not like an e-mail address.") % - address, ERR.INVALID_ADDRESS)) + raise VMMException(_(u"»%s« looks not like an e-mail address.") % + address, ERR.INVALID_ADDRESS) domain = VirtualMailManager.chkDomainname(domain) localpart = VirtualMailManager.chkLocalpart(localpart) return '%s@%s' % (localpart, domain) @@ -319,20 +309,20 @@ if uid > 0 and gid > 0: maildir = '%s' % uid if maildir.count('..') or domdir.count('..'): - raise VMMException((_(u'Found ".." in maildir path.'), - ERR.FOUND_DOTS_IN_PATH)) + raise VMMException(_(u'Found ".." in maildir path.'), + ERR.FOUND_DOTS_IN_PATH) if os.path.isdir(domdir): os.chdir(domdir) if os.path.isdir(maildir): mdstat = os.stat(maildir) if (mdstat.st_uid, mdstat.st_gid) != (uid, gid): - raise VMMException(( + raise VMMException( _(u'Owner/group mismatch in maildir detected.'), - ERR.MAILDIR_PERM_MISMATCH)) + ERR.MAILDIR_PERM_MISMATCH) rmtree(maildir, ignore_errors=True) else: - raise VMMException((_(u"No such directory: %s/%s") % - (domdir, uid), ERR.NO_SUCH_DIRECTORY)) + raise VMMException(_(u"No such directory: %s/%s") % + (domdir, uid), ERR.NO_SUCH_DIRECTORY) def __domdirdelete(self, domdir, gid): if gid > 0: @@ -342,14 +332,14 @@ domdirdirs = domdir.replace(basedir+'/', '').split('/') if basedir.count('..') or domdir.count('..'): raise VMMException( - (_(u'FATAL: ".." in domain directory path detected.'), - ERR.FOUND_DOTS_IN_PATH)) + _(u'FATAL: ".." in domain directory path detected.'), + ERR.FOUND_DOTS_IN_PATH) if os.path.isdir('%s/%s' % (basedir, domdirdirs[0])): os.chdir('%s/%s' % (basedir, domdirdirs[0])) if os.lstat(domdirdirs[1]).st_gid != gid: raise VMMException( - (_(u'FATAL: group mismatch in domain directory detected'), - ERR.DOMAINDIR_GROUP_MISMATCH)) + _(u'FATAL: group mismatch in domain directory detected'), + ERR.DOMAINDIR_GROUP_MISMATCH) rmtree(domdirdirs[1], ignore_errors=True) def __getSalt(self): @@ -436,8 +426,8 @@ return self.__Cfg.getboolean('config', 'done') except ValueError, e: raise VMMConfigException(_(u"""Configurtion error: "%s" -(in section "connfig", option "done") see also: vmm.cfg(5)\n""") % - str(e)) +(in section "connfig", option "done") see also: vmm.cfg(5)\n""") % str(e), + ERR.CONF_ERROR) def configure(self, section=None): """Starts interactive configuration. @@ -450,16 +440,13 @@ section -- the section to configure (default None): 'database', 'maildir', 'bin' or 'misc' """ - try: - if not section: - self.__Cfg.configure(self.__cfgSections) - elif section not in self.__cfgSections: - raise VMMException((_(u"Invalid section: '%s'") % section, - ERR.INVALID_SECTION)) - else: - self.__Cfg.configure([section]) - except: - raise + if section is None: + self.__Cfg.configure(self.__cfgSections) + elif section in self.__cfgSections: + self.__Cfg.configure([section]) + else: + raise VMMException(_(u"Invalid section: '%s'") % section, + ERR.INVALID_SECTION) def domain_add(self, domainname, transport=None): dom = self.__getDomain(domainname, transport) @@ -468,8 +455,8 @@ def domain_transport(self, domainname, transport, force=None): if force is not None and force != 'force': - raise VMMDomainException((_(u"Invalid argument: '%s'") % force, - ERR.INVALID_OPTION)) + raise VMMDomainException(_(u"Invalid argument: '%s'") % force, + ERR.INVALID_OPTION) dom = self.__getDomain(domainname, None) if force is None: dom.updateTransport(transport) @@ -478,8 +465,8 @@ def domain_delete(self, domainname, force=None): if not force is None and force not in ['deluser','delalias','delall']: - raise VMMDomainException((_(u"Invalid argument: »%s«") % force, - ERR.INVALID_OPTION)) + raise VMMDomainException(_(u"Invalid argument: »%s«") % force, + ERR.INVALID_OPTION) dom = self.__getDomain(domainname) gid = dom.getID() domdir = dom.getDir() @@ -508,8 +495,8 @@ return (dominfo, dom.getAliaseNames(), dom.getAccounts(), dom.getAliases()) else: - raise VMMDomainException((_(u'Invalid argument: »%s«') % detailed, - ERR.INVALID_OPTION)) + raise VMMDomainException(_(u'Invalid argument: »%s«') % detailed, + ERR.INVALID_OPTION) def domain_alias_add(self, aliasname, domainname): """Adds an alias name to the domain. @@ -549,9 +536,9 @@ domain = pattern[:-1] re.compile(RE_DOMAIN_SRCH) if not re.match(RE_DOMAIN_SRCH, domain): - raise VMMException(( + raise VMMException( _(u"The pattern '%s' contains invalid characters.") % - pattern, ERR.DOMAIN_INVALID)) + pattern, ERR.DOMAIN_INVALID) else: pattern = VirtualMailManager.chkDomainname(pattern) # XXX chk by domain if not like @@ -582,14 +569,14 @@ if self.__Cfg.getboolean('maildir', 'delete'): try: self.__maildirdelete(acc.getDir('domain'), uid, gid) - except (VMMException), e: - if e[0][1] in [ERR.FOUND_DOTS_IN_PATH, + except VMMException, e: + if e.code() in [ERR.FOUND_DOTS_IN_PATH, ERR.MAILDIR_PERM_MISMATCH, ERR.NO_SUCH_DIRECTORY]: warning = _(u"""\ The account has been successfully deleted from the database. But an error occurred while deleting the following directory: »%s« - Reason: %s""") % (acc.getDir('home'), e[0][0]) + Reason: %s""") % (acc.getDir('home'), e.msg()) self.__warnings.append(warning) else: raise e @@ -617,8 +604,8 @@ def user_password(self, emailaddress, password): acc = self.__getAccount(emailaddress) if acc.getUID() == 0: - raise VMMException((_(u"Account doesn't exists"), - ERR.NO_SUCH_ACCOUNT)) + raise VMMException(_(u"Account doesn't exists"), + ERR.NO_SUCH_ACCOUNT) if password is None: password = self._readpass() acc.modify('password', self.__pwhash(password)) diff -r 191d5a5adc4a -r 0d5f58f8b8f5 po/de.po --- a/po/de.po Mon Aug 18 01:56:31 2008 +0000 +++ b/po/de.po Tue Aug 19 02:40:43 2008 +0000 @@ -5,8 +5,8 @@ msgid "" msgstr "" "Project-Id-Version: vmm 0.5\n" -"POT-Creation-Date: 2008-08-18 02:56+CEST\n" -"PO-Revision-Date: 2008-08-18 03:48+0200\n" +"POT-Creation-Date: 2008-08-19 03:57+CEST\n" +"PO-Revision-Date: 2008-08-19 04:03+0200\n" "Last-Translator: Pascal Volk \n" "Language-Team: German\n" "MIME-Version: 1.0\n" @@ -80,23 +80,23 @@ msgid "Alias doesn't exists" msgstr "Der Alias existiert nicht." -#: VirtualMailManager/Config.py:100 +#: VirtualMailManager/Config.py:101 msgid "missing section: %s\n" msgstr "Fehlender Abschnitt: %s\n" -#: VirtualMailManager/Config.py:102 +#: VirtualMailManager/Config.py:103 msgid "missing options in section %s:\n" msgstr "Fehlende Optionen im Abschnitt %s:\n" -#: VirtualMailManager/Config.py:118 +#: VirtualMailManager/Config.py:119 msgid "Argument 'sections' is not a list." msgstr "Argument 'section' ist nicht vom Typ List." -#: VirtualMailManager/Config.py:131 +#: VirtualMailManager/Config.py:130 msgid "* Config section: »%s«" msgstr "* Konfigurations Abschnitt: »%s«" -#: VirtualMailManager/Config.py:134 +#: VirtualMailManager/Config.py:133 msgid "Enter new value for option %s [%s]: " msgstr "Neuer Wert für Option %s [%s]: " @@ -149,7 +149,7 @@ msgid "Unknown tid specified." msgstr "Unbekannte tid angegeben." -#: VirtualMailManager/VirtualMailManager.py:51 +#: VirtualMailManager/VirtualMailManager.py:47 msgid "" "fix permissions for »%s«\n" "`chmod 0600 %s` would be great." @@ -157,7 +157,7 @@ "Bitte Zugriffsrechte für »%s« anpassen\n" "`chmod 0600 %s` wäre großartig." -#: VirtualMailManager/VirtualMailManager.py:58 +#: VirtualMailManager/VirtualMailManager.py:54 msgid "" "You are not root.\n" "\tGood bye!\n" @@ -165,11 +165,11 @@ "Sie sind nicht root.\n" "\tAuf Wiedersehen.\n" -#: VirtualMailManager/VirtualMailManager.py:72 +#: VirtualMailManager/VirtualMailManager.py:68 msgid "The file »%s« does not exists." msgstr "Die Datei »%s« existiert nicht." -#: VirtualMailManager/VirtualMailManager.py:94 +#: VirtualMailManager/VirtualMailManager.py:87 msgid "" "»%s« is not a directory.\n" "(vmm.cfg: section \"domdir\", option \"base\")" @@ -177,7 +177,7 @@ "»%s« ist kein Verzeichnis.\n" "(vmm.cfg: Abschnitt \"domdir\", Option \"base\")" -#: VirtualMailManager/VirtualMailManager.py:99 +#: VirtualMailManager/VirtualMailManager.py:92 msgid "" "»%s« doesn't exists.\n" "(vmm.cfg: section \"bin\", option \"%s\")" @@ -185,7 +185,7 @@ "»%s« existiert nicht.\n" "(vmm.cfg: Abschnitt \"bin\", Option \"%s\")" -#: VirtualMailManager/VirtualMailManager.py:102 +#: VirtualMailManager/VirtualMailManager.py:96 msgid "" "»%s« is not executable.\n" "(vmm.cfg: section \"bin\", option \"%s\")" @@ -193,75 +193,75 @@ "»%s« ist nicht ausführbar.\n" "(vmm.cfg: Abschnitt \"bin\", Option \"%s\")" -#: VirtualMailManager/VirtualMailManager.py:136 +#: VirtualMailManager/VirtualMailManager.py:122 msgid "No localpart specified." msgstr "Kein local-part angegeben." -#: VirtualMailManager/VirtualMailManager.py:139 +#: VirtualMailManager/VirtualMailManager.py:125 msgid "The local part »%s« is too long" msgstr "Der local-part »%s« ist zu lang" -#: VirtualMailManager/VirtualMailManager.py:147 +#: VirtualMailManager/VirtualMailManager.py:133 msgid "The local part »%s« contains invalid characters: %s" msgstr "Der local-part »%s« enthält ungültige Zeichen: %s" -#: VirtualMailManager/VirtualMailManager.py:191 +#: VirtualMailManager/VirtualMailManager.py:177 msgid "The domain name is too long." msgstr "Der Domain-Name ist zu lang." -#: VirtualMailManager/VirtualMailManager.py:195 +#: VirtualMailManager/VirtualMailManager.py:181 msgid "The domain name is invalid." msgstr "Der Domain-Name ist ungültig." -#: VirtualMailManager/VirtualMailManager.py:204 +#: VirtualMailManager/VirtualMailManager.py:190 msgid "Missing '@' sign in e-mail address »%s«." msgstr "In der E-Mail-Adresse »%s« fehlt das '@'-Zeichen." -#: VirtualMailManager/VirtualMailManager.py:207 +#: VirtualMailManager/VirtualMailManager.py:193 msgid "»%s« looks not like an e-mail address." msgstr "»%s« sieht nicht wie eine E-Mail-Adresse aus." -#: VirtualMailManager/VirtualMailManager.py:225 +#: VirtualMailManager/VirtualMailManager.py:211 msgid "Enter new password: " msgstr "Neues Passwort eingeben: " -#: VirtualMailManager/VirtualMailManager.py:228 +#: VirtualMailManager/VirtualMailManager.py:214 msgid "Sorry, empty passwords are not permitted" msgstr "Entschuldigung, leere Passwörter sind nicht zulässig" -#: VirtualMailManager/VirtualMailManager.py:229 +#: VirtualMailManager/VirtualMailManager.py:215 msgid "Retype new password: " msgstr "Neues Passwort wiederholen: " -#: VirtualMailManager/VirtualMailManager.py:232 +#: VirtualMailManager/VirtualMailManager.py:218 msgid "Sorry, passwords do not match" msgstr "Entschuldigung, die Passwörter stimmen nicht überein" -#: VirtualMailManager/VirtualMailManager.py:268 +#: VirtualMailManager/VirtualMailManager.py:254 msgid "No such directory: %s" msgstr "Verzeichnis nicht gefunden: %s" -#: VirtualMailManager/VirtualMailManager.py:326 +#: VirtualMailManager/VirtualMailManager.py:312 msgid "Found \"..\" in maildir path." msgstr "\"..\" im Pfad zum Maildir entdeckt." -#: VirtualMailManager/VirtualMailManager.py:334 +#: VirtualMailManager/VirtualMailManager.py:320 msgid "Owner/group mismatch in maildir detected." msgstr "Maildir gehört dem/der falschen Benutzer/Gruppe." -#: VirtualMailManager/VirtualMailManager.py:338 +#: VirtualMailManager/VirtualMailManager.py:324 msgid "No such directory: %s/%s" msgstr "Verzeichnis nicht gefunden: %s/%s" -#: VirtualMailManager/VirtualMailManager.py:349 +#: VirtualMailManager/VirtualMailManager.py:335 msgid "FATAL: \"..\" in domain directory path detected." msgstr "FATAL: \"..\" im Pfad zum Domain-Verzeichnis entdeckt." -#: VirtualMailManager/VirtualMailManager.py:355 +#: VirtualMailManager/VirtualMailManager.py:341 msgid "FATAL: group mismatch in domain directory detected" msgstr "FATAL: Domain-Verzeichnis gehört der falschen Gruppe" -#: VirtualMailManager/VirtualMailManager.py:442 +#: VirtualMailManager/VirtualMailManager.py:428 msgid "" "Configurtion error: \"%s\"\n" "(in section \"connfig\", option \"done\") see also: vmm.cfg(5)\n" @@ -269,24 +269,24 @@ "Konfigurations Fehler: \"%s\"\n" "(im Abschnitt \"connfig\", Option \"done\") Siehe auch: vmm.cfg(5)\n" -#: VirtualMailManager/VirtualMailManager.py:461 +#: VirtualMailManager/VirtualMailManager.py:448 msgid "Invalid section: '%s'" msgstr "Ungültiger Abschnitt: '%s'" -#: VirtualMailManager/VirtualMailManager.py:475 +#: VirtualMailManager/VirtualMailManager.py:458 msgid "Invalid argument: '%s'" msgstr "Ungültiges Argument: '%s'" -#: VirtualMailManager/VirtualMailManager.py:485 -#: VirtualMailManager/VirtualMailManager.py:515 +#: VirtualMailManager/VirtualMailManager.py:468 +#: VirtualMailManager/VirtualMailManager.py:498 msgid "Invalid argument: »%s«" msgstr "Ungültiges Argument: »%s«" -#: VirtualMailManager/VirtualMailManager.py:557 +#: VirtualMailManager/VirtualMailManager.py:540 msgid "The pattern '%s' contains invalid characters." msgstr "Das Muster '%s' enthält ungültige Zeichen." -#: VirtualMailManager/VirtualMailManager.py:592 +#: VirtualMailManager/VirtualMailManager.py:575 msgid "" "The account has been successfully deleted from the database.\n" " But an error occurred while deleting the following directory:\n" @@ -298,134 +298,140 @@ " »%s«\n" " Grund: %s" -#: VirtualMailManager/VirtualMailManager.py:624 +#: VirtualMailManager/VirtualMailManager.py:607 msgid "Account doesn't exists" msgstr "Der Account existiert nicht" -#: vmm:45 +#: vmm:41 msgid "" "Usage: %s SUBCOMMAND OBJECT ARGS*\n" " short long\n" " subcommand object args (* = optional)\n" -"\n" msgstr "" "Verwendung: %s UNTERBEFEHL OBJEKT ARGS*\n" " kurz lang\n" " Unterbefehl Objekt args (* = optional)\n" -"\n" -#: vmm:76 vmm:85 vmm:362 vmm:414 +#: vmm:76 vmm:87 vmm:413 msgid "Error" msgstr "Fehler" -#: vmm:96 vmm:412 -msgid "Ouch" -msgstr "Autsch" - -#: vmm:123 +#: vmm:109 msgid "information" msgstr "Informationen" -#: vmm:137 +#: vmm:119 msgid "Available" msgstr "Verfügbare" -#: vmm:140 vmm:213 +#: vmm:122 vmm:201 msgid "alias domains" msgstr "Alias-Domains" -#: vmm:150 vmm:161 vmm:179 +#: vmm:132 vmm:143 vmm:161 msgid "\tNone" msgstr "\tKeine" -#: vmm:154 +#: vmm:136 msgid "Alias information" msgstr "Alias Informationen" -#: vmm:156 +#: vmm:138 msgid "\tMail for %s goes to:" msgstr "\tE-Mails für %s gehen an:" -#: vmm:174 +#: vmm:156 msgid "Available domains" msgstr "Verfügbare Domains" -#: vmm:176 +#: vmm:158 msgid "Matching domains" msgstr "Übereinstimmende Domains" -#: vmm:191 vmm:199 vmm:207 +#: vmm:179 vmm:187 vmm:195 msgid "Missing domain name." msgstr "Kein Domain-Name angegeben." -#: vmm:209 vmm:212 +#: vmm:197 vmm:200 msgid "Domain" msgstr "Domain" -#: vmm:214 +#: vmm:202 msgid "accounts" msgstr "Accounts" -#: vmm:215 +#: vmm:203 msgid "aliases" msgstr "Aliase" -#: vmm:219 +#: vmm:207 msgid "Missing domain name and new transport." msgstr "Domain-Name und neuer Transport fehlen." -#: vmm:221 +#: vmm:209 msgid "Missing new transport." msgstr "Neuer Transport fehlt." -#: vmm:230 +#: vmm:218 msgid "Missing alias domain name and target domain name." msgstr "Domain-Namen für Alias- und Ziel-Domain fehlen." -#: vmm:232 +#: vmm:220 msgid "Missing target domain name." msgstr "Keine Ziel-Domain angegeben." -#: vmm:238 +#: vmm:227 vmm:233 msgid "Missing alias domain name." msgstr "Keine Alias-Domain angegeben." -#: vmm:244 vmm:253 vmm:259 vmm:283 vmm:291 vmm:299 +#: vmm:239 vmm:248 vmm:254 vmm:278 vmm:286 vmm:294 msgid "Missing e-mail address." msgstr "E-Mail-Adresse fehlt." -#: vmm:267 +#: vmm:262 msgid "Missing e-mail address and users name." msgstr "E-Mail-Adresse und der Name des Benutzers fehlen." -#: vmm:269 +#: vmm:264 msgid "Missing users name." msgstr "Name des Benutzers fehlt." -#: vmm:275 +#: vmm:270 msgid "Missing e-mail address and transport." msgstr "E-Mail-Adresse und Transport fehlen." -#: vmm:277 +#: vmm:272 msgid "Missing transport." msgstr "Transport fehlt." -#: vmm:308 +#: vmm:303 msgid "Missing alias address and destination." msgstr "Alias- und Ziel-Adresse fehlen." -#: vmm:314 vmm:320 +#: vmm:309 vmm:315 msgid "Missing alias address" msgstr "Alias-Adresse fehlt." -#: vmm:328 +#: vmm:323 msgid "Missing userid" msgstr "Keine UID angegeben." -#: vmm:341 +#: vmm:336 msgid "Warnings:" msgstr "Warnungen:" -#: vmm:409 +#: vmm:341 +msgid "version" +msgstr "Version" + +#: vmm:342 +msgid "from" +msgstr "vom" + +#: vmm:408 msgid "Unknown subcommand" msgstr "Unbekannter Unterbefehl" + +#: vmm:411 +msgid "Ouch" +msgstr "Autsch" diff -r 191d5a5adc4a -r 0d5f58f8b8f5 po/vmm.pot --- a/po/vmm.pot Mon Aug 18 01:56:31 2008 +0000 +++ b/po/vmm.pot Tue Aug 19 02:40:43 2008 +0000 @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: vmm 0.5\n" -"POT-Creation-Date: 2008-08-18 03:08+CEST\n" +"POT-Creation-Date: 2008-08-19 04:00+CEST\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -80,25 +80,25 @@ msgid "Alias doesn't exists" msgstr "" -#: VirtualMailManager/Config.py:100 +#: VirtualMailManager/Config.py:101 msgid "" "missing section: %s\n" msgstr "" -#: VirtualMailManager/Config.py:102 +#: VirtualMailManager/Config.py:103 msgid "" "missing options in section %s:\n" msgstr "" -#: VirtualMailManager/Config.py:118 +#: VirtualMailManager/Config.py:119 msgid "Argument 'sections' is not a list." msgstr "" -#: VirtualMailManager/Config.py:131 +#: VirtualMailManager/Config.py:130 msgid "* Config section: \302\273%s\302\253" msgstr "" -#: VirtualMailManager/Config.py:134 +#: VirtualMailManager/Config.py:133 msgid "Enter new value for option %s [%s]: " msgstr "" @@ -151,132 +151,132 @@ msgid "Unknown tid specified." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:51 +#: VirtualMailManager/VirtualMailManager.py:47 msgid "" "fix permissions for \302\273%s\302\253\n" "`chmod 0600 %s` would be great." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:58 +#: VirtualMailManager/VirtualMailManager.py:54 msgid "" "You are not root.\n" "\tGood bye!\n" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:72 +#: VirtualMailManager/VirtualMailManager.py:68 msgid "The file \302\273%s\302\253 does not exists." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:94 +#: VirtualMailManager/VirtualMailManager.py:87 msgid "" "\302\273%s\302\253 is not a directory.\n" "(vmm.cfg: section \"domdir\", option \"base\")" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:99 +#: VirtualMailManager/VirtualMailManager.py:92 msgid "" "\302\273%s\302\253 doesn't exists.\n" "(vmm.cfg: section \"bin\", option \"%s\")" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:102 +#: VirtualMailManager/VirtualMailManager.py:96 msgid "" "\302\273%s\302\253 is not executable.\n" "(vmm.cfg: section \"bin\", option \"%s\")" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:136 +#: VirtualMailManager/VirtualMailManager.py:122 msgid "No localpart specified." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:139 +#: VirtualMailManager/VirtualMailManager.py:125 msgid "The local part \302\273%s\302\253 is too long" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:147 +#: VirtualMailManager/VirtualMailManager.py:133 msgid "The local part \302\273%s\302\253 contains invalid characters: %s" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:191 +#: VirtualMailManager/VirtualMailManager.py:177 msgid "The domain name is too long." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:195 +#: VirtualMailManager/VirtualMailManager.py:181 msgid "The domain name is invalid." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:204 +#: VirtualMailManager/VirtualMailManager.py:190 msgid "Missing '@' sign in e-mail address \302\273%s\302\253." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:207 +#: VirtualMailManager/VirtualMailManager.py:193 msgid "\302\273%s\302\253 looks not like an e-mail address." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:225 +#: VirtualMailManager/VirtualMailManager.py:211 msgid "Enter new password: " msgstr "" -#: VirtualMailManager/VirtualMailManager.py:228 +#: VirtualMailManager/VirtualMailManager.py:214 msgid "Sorry, empty passwords are not permitted" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:229 +#: VirtualMailManager/VirtualMailManager.py:215 msgid "Retype new password: " msgstr "" -#: VirtualMailManager/VirtualMailManager.py:232 +#: VirtualMailManager/VirtualMailManager.py:218 msgid "Sorry, passwords do not match" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:268 +#: VirtualMailManager/VirtualMailManager.py:254 msgid "No such directory: %s" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:326 +#: VirtualMailManager/VirtualMailManager.py:312 msgid "Found \"..\" in maildir path." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:334 +#: VirtualMailManager/VirtualMailManager.py:320 msgid "Owner/group mismatch in maildir detected." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:338 +#: VirtualMailManager/VirtualMailManager.py:324 msgid "No such directory: %s/%s" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:349 +#: VirtualMailManager/VirtualMailManager.py:335 msgid "FATAL: \"..\" in domain directory path detected." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:355 +#: VirtualMailManager/VirtualMailManager.py:341 msgid "FATAL: group mismatch in domain directory detected" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:442 +#: VirtualMailManager/VirtualMailManager.py:428 msgid "" "Configurtion error: \"%s\"\n" "(in section \"connfig\", option \"done\") see also: vmm.cfg(5)\n" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:461 +#: VirtualMailManager/VirtualMailManager.py:448 msgid "Invalid section: '%s'" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:475 +#: VirtualMailManager/VirtualMailManager.py:458 msgid "Invalid argument: '%s'" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:485 -#: VirtualMailManager/VirtualMailManager.py:515 +#: VirtualMailManager/VirtualMailManager.py:468 +#: VirtualMailManager/VirtualMailManager.py:498 msgid "Invalid argument: \302\273%s\302\253" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:557 +#: VirtualMailManager/VirtualMailManager.py:540 msgid "The pattern '%s' contains invalid characters." msgstr "" -#: VirtualMailManager/VirtualMailManager.py:592 +#: VirtualMailManager/VirtualMailManager.py:575 msgid "" "The account has been successfully deleted from the database.\n" " But an error occurred while deleting the following directory:\n" @@ -284,131 +284,138 @@ " Reason: %s" msgstr "" -#: VirtualMailManager/VirtualMailManager.py:624 +#: VirtualMailManager/VirtualMailManager.py:607 msgid "Account doesn't exists" msgstr "" -#: vmm:45 +#: vmm:41 msgid "" "Usage: %s SUBCOMMAND OBJECT ARGS*\n" " short long\n" " subcommand object args (* = optional)\n" -"\n" msgstr "" -#: vmm:76 vmm:85 vmm:362 vmm:414 +#: vmm:76 vmm:87 vmm:413 msgid "Error" msgstr "" -#: vmm:96 vmm:412 -msgid "Ouch" -msgstr "" - -#: vmm:123 +#: vmm:109 msgid "information" msgstr "" -#: vmm:137 +#: vmm:119 msgid "Available" msgstr "" -#: vmm:140 vmm:213 +#: vmm:122 vmm:201 msgid "alias domains" msgstr "" -#: vmm:150 vmm:161 vmm:179 +#: vmm:132 vmm:143 vmm:161 msgid "\tNone" msgstr "" -#: vmm:154 +#: vmm:136 msgid "Alias information" msgstr "" +#: vmm:138 +msgid "\tMail for %s goes to:" +msgstr "" + #: vmm:156 -msgid "\tMail for %s goes to:" -msgstr "" - -#: vmm:174 msgid "Available domains" msgstr "" -#: vmm:176 +#: vmm:158 msgid "Matching domains" msgstr "" -#: vmm:191 vmm:199 vmm:207 +#: vmm:179 vmm:187 vmm:195 msgid "Missing domain name." msgstr "" -#: vmm:209 vmm:212 +#: vmm:197 vmm:200 msgid "Domain" msgstr "" -#: vmm:214 +#: vmm:202 msgid "accounts" msgstr "" -#: vmm:215 +#: vmm:203 msgid "aliases" msgstr "" -#: vmm:219 +#: vmm:207 msgid "Missing domain name and new transport." msgstr "" -#: vmm:221 +#: vmm:209 msgid "Missing new transport." msgstr "" -#: vmm:230 +#: vmm:218 msgid "Missing alias domain name and target domain name." msgstr "" -#: vmm:232 +#: vmm:220 msgid "Missing target domain name." msgstr "" -#: vmm:238 +#: vmm:227 vmm:233 msgid "Missing alias domain name." msgstr "" -#: vmm:244 vmm:253 vmm:259 vmm:283 vmm:291 vmm:299 +#: vmm:239 vmm:248 vmm:254 vmm:278 vmm:286 vmm:294 msgid "Missing e-mail address." msgstr "" -#: vmm:267 +#: vmm:262 msgid "Missing e-mail address and users name." msgstr "" -#: vmm:269 +#: vmm:264 msgid "Missing users name." msgstr "" -#: vmm:275 +#: vmm:270 msgid "Missing e-mail address and transport." msgstr "" -#: vmm:277 +#: vmm:272 msgid "Missing transport." msgstr "" -#: vmm:308 +#: vmm:303 msgid "Missing alias address and destination." msgstr "" -#: vmm:314 vmm:320 +#: vmm:309 vmm:315 msgid "Missing alias address" msgstr "" -#: vmm:328 +#: vmm:323 msgid "Missing userid" msgstr "" -#: vmm:341 +#: vmm:336 msgid "Warnings:" msgstr "" -#: vmm:409 +#: vmm:341 +msgid "version" +msgstr "" + +#: vmm:342 +msgid "from" +msgstr "" + +#: vmm:408 msgid "Unknown subcommand" msgstr "" +#: vmm:411 +msgid "Ouch" +msgstr "" + diff -r 191d5a5adc4a -r 0d5f58f8b8f5 vmm --- a/vmm Mon Aug 18 01:56:31 2008 +0000 +++ b/vmm Tue Aug 19 02:40:43 2008 +0000 @@ -17,6 +17,7 @@ import os import sys import gettext +from time import strftime, strptime from VirtualMailManager.VirtualMailManager import VirtualMailManager from VirtualMailManager.Config import VMMConfig @@ -24,16 +25,11 @@ import VirtualMailManager.constants.EXIT as EXIT import VirtualMailManager.constants.ERROR as ERR -locale.setlocale(locale.LC_ALL, '') -ENCODING = locale.nl_langinfo(locale.CODESET) -__prog__ = os.path.basename(sys.argv[0]) - -gettext.install(__prog__, '/usr/local/share/locale', unicode=1) def w_err(code, *args): for arg in args: sys.stderr.write(arg.encode(ENCODING, 'replace')) - sys.stderr.write('\n') + sys.stderr.write('\n') sys.exit(code) def w_std(*args): @@ -42,17 +38,19 @@ sys.stdout.write('\n') def usage(excode=0, errMsg=None): - sys.stderr.write(_("""\ + u_head = _("""\ Usage: %s SUBCOMMAND OBJECT ARGS* short long - subcommand object args (* = optional)\n\n""")% - __prog__) - sys.stderr.write("""\ + subcommand object args (* = optional)\n""")\ + % __prog__ + + u_body = """\ da domainadd domain.tld transport* di domaininfo domain.tld detailed* dt domaintransport domain.tld transport force* dd domaindelete domain.tld delalias*|deluser*|delall* daa domainaliasadd aliasdomain.tld domain.tld + dai domainaliasinfo aliasdomain.tld dad domainaliasdelete aliasdomain.tld ua useradd user@domain.tld password* ui userinfo user@domain.tld du* @@ -70,35 +68,23 @@ cf configure section* h help v version +""" + if excode > 0: + if errMsg is None: + w_err(excode, u_head, u_body) + else: + w_err(excode, u_head, u_body, '%s: %s\n' % (_('Error'), errMsg)) + else: + w_std(u_head, u_body) + sys.exit(excode) -""") - if not errMsg is None: - sys.stderr.write('%s: %s\n' % (_('Error'), errMsg)) - sys.exit(excode) - -def getVMM(): +def get_vmm(): try: vmm = VirtualMailManager() return vmm except (VMME.VMMException, VMME.VMMNotRootException, VMME.VMMPermException, VMME.VMMConfigException), e: - w_err(e[0][1], "%s: %s\n" % (_('Error'),e[0][0])) - -def configure(): - try: - if len(argv) < 3: - vmm.configure() - else: - vmm.configure(argv[2]) - except (EOFError, KeyboardInterrupt): - #sys.stderr.write('\n%s!\n' % _('Ouch')) - #sys.exit(EXIT.USER_INTERRUPT) - w_err(EXIT.USER_INTERRUPT, '\n%s!\n' % _('Ouch')) - except VMME.VMMConfigException, e: - #sys.stderr.write(str(e)) - #sys.exit(ERR.CONF_ERROR) - w_err(ERR.CONF_ERROR, str(e)) - sys.exit(0) + w_err(e.code(), "%s: %s\n" % (_('Error'), e.msg())) def _getOrder(): order = () @@ -121,14 +107,11 @@ def _printInfo(info, title): msg = '%s %s' % (title, _('information')) - #print '%s\n%s' % (msg, '-'*len(msg)) w_std ('%s\n%s' % (msg, '-'*len(msg))) for k,u in _getOrder(): if u: - #print '\t%s: %s' % (k.upper().ljust(15, '.'), info[k]) w_std('\t%s: %s' % (k.upper().ljust(15, '.'), info[k])) else: - #print '\t%s: %s' % (k.title().ljust(15, '.'), info[k]) w_std('\t%s: %s' % (k.title().ljust(15, '.'), info[k])) print @@ -185,9 +168,15 @@ print _formatDom(alias, main=False) print +def configure(): + if need_setup or len(argv) < 3: + vmm.configure() + else: + vmm.configure(argv[2]) + def domain_add(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing domain name.')) + usage(EXIT.MISSING_ARGS, _(u'Missing domain name.')) elif argc < 4: vmm.domain_add(argv[2].lower()) else: @@ -195,7 +184,7 @@ def domain_delete(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing domain name.')) + usage(EXIT.MISSING_ARGS, _(u'Missing domain name.')) elif argc < 4: vmm.domain_delete(argv[2].lower()) else: @@ -203,7 +192,7 @@ def domain_info(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing domain name.')) + usage(EXIT.MISSING_ARGS, _(u'Missing domain name.')) elif argc < 4: _printInfo(vmm.domain_info(argv[2].lower()), _('Domain')) else: @@ -215,9 +204,9 @@ def domain_transport(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing domain name and new transport.')) + usage(EXIT.MISSING_ARGS, _(u'Missing domain name and new transport.')) if argc < 4: - usage(EXIT.MISSING_ARGS, _('Missing new transport.')) + usage(EXIT.MISSING_ARGS, _(u'Missing new transport.')) elif argc < 5: vmm.domain_transport(argv[2].lower(), argv[3]) else: @@ -226,21 +215,28 @@ def domain_alias_add(): if argc < 3: usage(EXIT.MISSING_ARGS, - _('Missing alias domain name and target domain name.')) + _(u'Missing alias domain name and target domain name.')) elif argc < 4: - usage(EXIT.MISSING_ARGS, _('Missing target domain name.')) + usage(EXIT.MISSING_ARGS, _(u'Missing target domain name.')) else: vmm.domain_alias_add(argv[2].lower(), argv[3].lower()) +def domain_alias_info(): + raise NotImplementedError('Sorry not implemented yet. ;-)') + if argc < 3: + usage(EXIT.MISSING_ARGS, _(u'Missing alias domain name.')) + else: + vmm.domain_alias_delete(argv[2].lower()) + def domain_alias_delete(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing alias domain name.')) + usage(EXIT.MISSING_ARGS, _(u'Missing alias domain name.')) else: vmm.domain_alias_delete(argv[2].lower()) def user_add(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing e-mail address.')) + usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address.')) elif argc < 4: password = None else: @@ -249,13 +245,13 @@ def user_delete(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing e-mail address.')) + usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address.')) else: vmm.user_delete(argv[2].lower()) def user_info(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing e-mail address.')) + usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address.')) elif argc < 4: _printInfo(vmm.user_info(argv[2].lower()), 'Account') else: @@ -263,7 +259,7 @@ def user_name(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing e-mail address and users name.')) + usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address and users name.')) if argc < 4: usage(EXIT.MISSING_ARGS, _('Missing users name.')) else: @@ -271,15 +267,15 @@ def user_transport(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing e-mail address and transport.')) + usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address and transport.')) if argc <4: - usage(EXIT.MISSING_ARGS, _('Missing transport.')) + usage(EXIT.MISSING_ARGS, _(u'Missing transport.')) else: vmm.user_transport(argv[2].lower(), argv[3]) def user_enable(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing e-mail address.')) + usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address.')) elif argc < 4: vmm.user_enable(argv[2].lower()) else: @@ -287,7 +283,7 @@ def user_disable(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing e-mail address.')) + usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address.')) elif argc < 4: vmm.user_disable(argv[2].lower()) else: @@ -295,7 +291,7 @@ def user_password(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing e-mail address.')) + usage(EXIT.MISSING_ARGS, _(u'Missing e-mail address.')) elif argc < 4: password = None else: @@ -304,19 +300,19 @@ def alias_add(): if argc < 4: - usage(EXIT.MISSING_ARGS, _('Missing alias address and destination.')) + usage(EXIT.MISSING_ARGS, _(u'Missing alias address and destination.')) else: vmm.alias_add(argv[2].lower(), argv[3]) def alias_info(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing alias address')) + usage(EXIT.MISSING_ARGS, _(u'Missing alias address')) else: _printAliases(argv[2], vmm.alias_info(argv[2].lower())) def alias_delete(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing alias address')) + usage(EXIT.MISSING_ARGS, _(u'Missing alias address')) elif argc < 4: vmm.alias_delete(argv[2].lower()) else: @@ -324,9 +320,9 @@ def user_byID(): if argc < 3: - usage(EXIT.MISSING_ARGS, _('Missing userid')) + usage(EXIT.MISSING_ARGS, _(u'Missing userid')) else: - _printInfo(vmm.user_byID(argv[2]), 'Account') + _printInfo(vmm.user_byID(argv[2]), u'Account') def domain_list(): if argc < 3: @@ -335,32 +331,35 @@ order, doms = vmm.domain_list(argv[2].lower()) _printDomList(order, doms) -def showWarnings(): +def show_warnings(): if vmm.hasWarnings(): print _(u'Warnings:') for w in vmm.getWarnings(): print " * ",w +def show_version(): + w_std("%s, %s %s (%s %s %s)\n" % (__prog__, _('version'), __version__, + __revision__, _('from'), strftime(locale.nl_langinfo(locale.D_FMT), + strptime(__date__, '%Y-%m-%d')))) + #def main(): if __name__ == '__main__': + __prog__ = os.path.basename(sys.argv[0]) + locale.setlocale(locale.LC_ALL, '') + ENCODING = locale.nl_langinfo(locale.CODESET) + gettext.install(__prog__, '/usr/local/share/locale', unicode=1) + argv = [unicode(arg, ENCODING) for arg in sys.argv] argc = len(sys.argv) - argv = [unicode(arg, ENCODING) for arg in sys.argv] + if argc < 2: usage(EXIT.MISSING_ARGS) - vmm = getVMM() + + vmm = get_vmm() try: - if argv[1] in ['cf', 'configure'] or not vmm.setupIsDone(): + need_setup = not vmm.setupIsDone() + if argv[1] in ['cf', 'configure'] or need_setup: configure() - except VMME.VMMConfigException, e: - #sys.stderr.write(str(e)) - #sys.exit(ERR.CONF_ERROR) - w_err(ERR.CONF_ERROR, str(e)) - except VMME.VMMException, e: - #sys.stderr.write("%s: %s\n" % (_('Error'), e[0][0])) - #sys.exit(e[0][1]) - w_err(e[0][1], "%s: %s\n" % (_('Error'), e[0][0])) - try: - if argv[1] in ['da', 'domainadd']: + elif argv[1] in ['da', 'domainadd']: domain_add() elif argv[1] in ['di', 'domaininfo']: domain_info() @@ -370,6 +369,8 @@ domain_delete() elif argv[1] in ['daa', 'domainaliasadd']: domain_alias_add() + elif argv[1] in ['dai', 'domainaliasinfo']: + domain_alias_info() elif argv[1] in ['dad', 'domainaliasdelete']: domain_alias_delete() elif argv[1] in ['ua', 'useradd']: @@ -401,13 +402,12 @@ elif argv[1] in ['h', 'help']: usage() elif argv[1] in ['v', 'version']: - print "%s, version %s (%s from %s)\n" % (__prog__, __version__, - __revision__, __date__) + show_version() else: usage(EXIT.UNKNOWN_COMMAND, - "%s: '%s'" % (_(u'Unknown subcommand'), argv[1])) - showWarnings() + u"%s: »%s«" % (_('Unknown subcommand'), argv[1])) + show_warnings() except (EOFError, KeyboardInterrupt): - w_err(EXIT.USER_INTERRUPT, '\n%s!\n' % _('Ouch')) - except VMME.VMMException, e: - w_err(e[0][1], "%s: %s" % (_('Error'), e[0][0])) + w_err(EXIT.USER_INTERRUPT, '\n%s!\n' % _(u'Ouch')) + except (VMME.VMMConfigException, VMME.VMMException), e: + w_err(e.code(), "%s: %s" % (_(u'Error'), e.msg()))