|
From: <nev...@us...> - 2010-02-05 20:13:56
|
details: http://hg.localdomain.org/vmm/rev/6e1ef32fbd82 changeset: 185:6e1ef32fbd82 user: Pascal Volk date: Fri Feb 05 20:13:32 2010 +0000 description: VMM/*: Moved some methods from classes to modules __init__. - Adjusted many import statements. - Small adjustments and whitespace cosmetics in Config.py diffstat: VirtualMailManager/Account.py | 12 +- VirtualMailManager/Alias.py | 8 +- VirtualMailManager/AliasDomain.py | 8 +- VirtualMailManager/Config.py | 80 ++++++------------- VirtualMailManager/Domain.py | 36 ++++---- VirtualMailManager/EmailAddress.py | 18 ++-- VirtualMailManager/MailLocation.py | 6 +- VirtualMailManager/Relocated.py | 8 +- VirtualMailManager/Transport.py | 4 +- VirtualMailManager/__init__.py | 109 ++++++++++++++++++++------- VirtualMailManager/cli/handler.py | 146 ++++++++++++------------------------ VirtualMailManager/ext/Postconf.py | 3 +- vmm | 10 +- 13 files changed, 218 insertions(+), 230 deletions(-) diffs (truncated from 898 to 300 lines): diff -r d0425225ce52 -r 6e1ef32fbd82 VirtualMailManager/Account.py --- a/VirtualMailManager/Account.py Thu Feb 04 19:08:01 2010 +0000 +++ b/VirtualMailManager/Account.py Fri Feb 05 20:13:32 2010 +0000 @@ -4,12 +4,12 @@ """Virtual Mail Manager's Account class to manage e-mail accounts.""" -from __main__ import ERR -from Exceptions import VMMAccountException as AccE -from Domain import Domain -from Transport import Transport -from MailLocation import MailLocation -from EmailAddress import EmailAddress +import VirtualMailManager.constants.ERROR as ERR +from VirtualMailManager.Domain import Domain +from VirtualMailManager.EmailAddress import EmailAddress +from VirtualMailManager.Exceptions import VMMAccountException as AccE +from VirtualMailManager.MailLocation import MailLocation +from VirtualMailManager.Transport import Transport import VirtualMailManager as VMM class Account(object): diff -r d0425225ce52 -r 6e1ef32fbd82 VirtualMailManager/Alias.py --- a/VirtualMailManager/Alias.py Thu Feb 04 19:08:01 2010 +0000 +++ b/VirtualMailManager/Alias.py Fri Feb 05 20:13:32 2010 +0000 @@ -4,10 +4,10 @@ """Virtual Mail Manager's Alias class to manage e-mail aliases.""" -from __main__ import ERR -from Exceptions import VMMAliasException as VMMAE -from Domain import Domain -from EmailAddress import EmailAddress +import VirtualMailManager.constants.ERROR as ERR +from VirtualMailManager.Domain import Domain +from VirtualMailManager.EmailAddress import EmailAddress +from VirtualMailManager.Exceptions import VMMAliasException as VMMAE import VirtualMailManager as VMM class Alias(object): diff -r d0425225ce52 -r 6e1ef32fbd82 VirtualMailManager/AliasDomain.py --- a/VirtualMailManager/AliasDomain.py Thu Feb 04 19:08:01 2010 +0000 +++ b/VirtualMailManager/AliasDomain.py Fri Feb 05 20:13:32 2010 +0000 @@ -4,16 +4,16 @@ """Virtual Mail Manager's AliasDomain class to manage alias domains.""" -from __main__ import ERR -from Exceptions import VMMAliasDomainException as VADE -import VirtualMailManager as VMM +import VirtualMailManager.constants.ERROR as ERR +from VirtualMailManager import chk_domainname +from VirtualMailManager.Exceptions import VMMAliasDomainException as VADE class AliasDomain(object): """Class to manage e-mail alias domains.""" __slots__ = ('__gid', '__name', '_domain', '_dbh') def __init__(self, dbh, domainname, targetDomain=None): self._dbh = dbh - self.__name = VMM.VirtualMailManager.chkDomainname(domainname) + self.__name = chk_domainname(domainname) self.__gid = 0 self._domain = targetDomain self._exists() diff -r d0425225ce52 -r 6e1ef32fbd82 VirtualMailManager/Config.py --- a/VirtualMailManager/Config.py Thu Feb 04 19:08:01 2010 +0000 +++ b/VirtualMailManager/Config.py Fri Feb 05 20:13:32 2010 +0000 @@ -36,10 +36,13 @@ from shutil import copy2 from ConfigParser import (Error, MissingSectionHeaderError, NoOptionError, NoSectionError, ParsingError, RawConfigParser) -from cStringIO import StringIO +from cStringIO import StringIO# TODO: move interactive stff to cli -from __main__ import os, ENCODING, ERR, get_unicode, w_std -from Exceptions import VMMConfigException +import VirtualMailManager.constants.ERROR as ERR + +from VirtualMailManager import ENCODING, exec_ok, get_unicode, is_dir +from VirtualMailManager.cli import w_std# move to cli +from VirtualMailManager.Exceptions import VMMConfigException class BadOptionError(Error): @@ -62,9 +65,9 @@ class LazyConfig(RawConfigParser): """The **lazy** derivate of the `RawConfigParser`. - + There are two additional getters: - + `LazyConfig.pget()` The polymorphic getter, which returns a option's value with the appropriate type. @@ -127,7 +130,7 @@ * `BadOptionError` * `NoSectionError` * `NoOptionError` - """ + """ sect_opt = section_option.lower().split('.') if len(sect_opt) != 2:# do we need a regexp to check the format? raise BadOptionError( @@ -158,13 +161,13 @@ def dget(self, option): """Returns the value of the `option`. - + If the option could not be found in the configuration file, the configured default value, from ``LazyConfig._cfg`` will be returned. - + Arguments: - + `option` : string the configuration option in the form "``section``\ **.**\ ``option``" @@ -188,7 +191,7 @@ def set(self, option, value): """Set the value of an option. - + Throws a ``ValueError`` if `value` couldn't be converted to ``LazyConfigOption.cls``""" section, option = self.__get_section_option(option) @@ -202,7 +205,7 @@ def has_section(self, section): """Checks if ``section`` is a known configuration section.""" - return section.lower() in self._cfg + return section.lower() in self._cfg def has_option(self, option): """Checks if the option (section\ **.**\ option) is a known @@ -214,7 +217,6 @@ return False - class LazyConfigOption(object): """A simple container class for configuration settings. @@ -266,7 +268,7 @@ """Creates a new Config instance Arguments: - + ``filename`` path to the configuration file """ @@ -290,11 +292,9 @@ 'smtp' : LCO(bool_t, True, self.get_boolean), }, 'bin': { - 'dovecotpw': LCO(str, '/usr/sbin/dovecotpw', self.get, - self.exec_ok), - 'du': LCO(str, '/usr/bin/du', self.get, self.exec_ok), - 'postconf': LCO(str, '/usr/sbin/postconf', self.get, - self.exec_ok), + 'dovecotpw': LCO(str, '/usr/sbin/dovecotpw', self.get, exec_ok), + 'du': LCO(str, '/usr/bin/du', self.get, exec_ok), + 'postconf': LCO(str, '/usr/sbin/postconf', self.get, exec_ok), }, 'database': { 'host': LCO(str, 'localhost', self.get), @@ -313,7 +313,7 @@ 'name': LCO(str, 'Maildir', self.get), }, 'misc': { - 'base_directory': LCO(str, '/srv/mail', self.get, self.is_dir), + 'base_directory': LCO(str, '/srv/mail', self.get, is_dir), 'dovecot_version': LCO(int, 12, self.getint), 'gid_mail': LCO(int, 8, self.getint), 'password_scheme': LCO(str, 'CRAM-MD5', self.get, @@ -341,6 +341,8 @@ Raises a VMMConfigException if the check fails. """ + # TODO: There are only two settings w/o defaults. + # So there is no need for cStringIO if not self.__chkCfg(): errmsg = StringIO() errmsg.write(_(u'Missing options, which have no default value.\n')) @@ -356,36 +358,10 @@ """Returns an iterator object for all configuration sections.""" return self._cfg.iterkeys() - def is_dir(self, path): - """Checks if ``path`` is a directory. - - Throws a `ConfigValueError` if ``path`` is not a directory. - """ - path = self.__expand_path(path) - if not os.path.isdir(path): - raise ConfigValueError(_(u'“%s” is not a directory') % \ - get_unicode(path)) - return path - - def exec_ok(self, binary): - """Checks if the ``binary`` exists and if it is executable. - - Throws a `ConfigValueError` if the ``binary`` isn't a file or is - not executable. - """ - binary = self.__expand_path(binary) - if not os.path.isfile(binary): - raise ConfigValueError(_(u'“%s” is not a file') % \ - get_unicode(binary)) - if not os.access(binary, os.X_OK): - raise ConfigValueError(_(u'File is not executable: “%s”') % \ - get_unicode(binary)) - return binary - def known_scheme(self, scheme): """Converts ``scheme`` to upper case and checks if is known by Dovecot (listed in VirtualMailManager.SCHEMES). - + Throws a `ConfigValueError` if the scheme is not listed in VirtualMailManager.SCHEMES. """ @@ -404,6 +380,8 @@ Arguments: sections -- list of strings with section names """ + # TODO: Derivate CliConfig from Config an move the interactive + # stuff to CliConfig input_fmt = _(u'Enter new value for option %(option)s \ [%(current_value)s]: ') failures = 0 @@ -435,6 +413,7 @@ def __saveChanges(self): """Writes changes to the configuration file.""" + # TODO: Move interactive stuff to CliConfig copy2(self.__cfgFileName, self.__cfgFileName+'.bak') self.__cfgFile = open(self.__cfgFileName, 'w') self.write(self.__cfgFile) @@ -442,7 +421,7 @@ def __chkCfg(self): """Checks all section's options for settings w/o default values. - + Returns ``True`` if everything is fine, else ``False``.""" errors = False for section in self._cfg.iterkeys(): @@ -456,10 +435,3 @@ self.__missing[section] = missing return not errors - def __expand_path(self, path): - """Expands paths, starting with ``.`` or ``~``, to an absolute path.""" - if path.startswith('.'): - return os.path.abspath(path) - if path.startswith('~'): - return os.path.expanduser(path) - return path diff -r d0425225ce52 -r 6e1ef32fbd82 VirtualMailManager/Domain.py --- a/VirtualMailManager/Domain.py Thu Feb 04 19:08:01 2010 +0000 +++ b/VirtualMailManager/Domain.py Fri Feb 05 20:13:32 2010 +0000 @@ -6,13 +6,17 @@ from random import choice -from __main__ import ERR -from Exceptions import VMMDomainException as VMMDE -import VirtualMailManager as VMM -from Transport import Transport +from VirtualMailManager import chk_domainname +from VirtualMailManager.constants.ERROR import \ + ACCOUNT_AND_ALIAS_PRESENT, ACCOUNT_PRESENT, ALIAS_PRESENT, \ + DOMAIN_ALIAS_EXISTS, DOMAIN_EXISTS, NO_SUCH_DOMAIN +from VirtualMailManager.Exceptions import VMMDomainException as VMMDE +from VirtualMailManager.Transport import Transport + MAILDIR_CHARS = '0123456789abcdefghijklmnopqrstuvwxyz' + class Domain(object): """Class to manage e-mail domains.""" __slots__ = ('_basedir','_domaindir','_id','_name','_transport','_dbh') @@ -25,7 +29,7 @@ transport -- default vmm.cfg/misc/transport (str) """ self._dbh = dbh - self._name = VMM.VirtualMailManager.chkDomainname(domainname) + self._name = chk_domainname(domainname) self._basedir = basedir if transport is not None: self._transport = Transport(self._dbh, transport=transport) @@ -34,8 +38,8 @@ |