VMM/Alias: moved the postconf stuff from the Handlers to Alias class. v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Fri, 30 Apr 2010 03:03:47 +0000
branchv0.6.x
changeset 281 59ff7c719697
parent 280 db35d2eec518
child 282 28871c1be260
VMM/Alias: moved the postconf stuff from the Handlers to Alias class.
VirtualMailManager/Alias.py
VirtualMailManager/Handler.py
VirtualMailManager/cli/Handler.py
--- a/VirtualMailManager/Alias.py	Fri Apr 30 00:01:15 2010 +0000
+++ b/VirtualMailManager/Alias.py	Fri Apr 30 03:03:47 2010 +0000
@@ -11,12 +11,14 @@
 from VirtualMailManager.Domain import get_gid
 from VirtualMailManager.EmailAddress import EmailAddress
 from VirtualMailManager.errors import AliasError as AErr
+from VirtualMailManager.ext.Postconf import Postconf
 from VirtualMailManager.pycompat import all
 from VirtualMailManager.constants.ERROR import \
      ALIAS_EXCEEDS_EXPANSION_LIMIT, NO_SUCH_ALIAS, NO_SUCH_DOMAIN
 
 
 _ = lambda msg: msg
+cfg_dget = lambda option: None
 
 
 class Alias(object):
@@ -46,8 +48,10 @@
             self._dests.extend(EmailAddress(dest[0]) for dest in dests)
         dbc.close()
 
-    def __check_expansion(self, count_new, limit):
+    def __check_expansion(self, count_new):
         """Checks the current expansion limit of the alias."""
+        postconf = Postconf(cfg_dget('bin.postconf'))
+        limit = long(postconf.read('virtual_alias_expansion_limit'))
         dcount = len(self._dests)
         failed = False
         if dcount == limit or dcount + count_new > limit:
@@ -96,7 +100,7 @@
         """The Alias' EmailAddress instance."""
         return self._addr
 
-    def add_destinations(self, destinations, expansion_limit, warnings=None):
+    def add_destinations(self, destinations, warnings=None):
         """Adds the `EmailAddress`es from *destinations* list to the
         destinations of the alias.
 
@@ -120,7 +124,7 @@
                 warnings.extend(duplicates)
         if not destinations:
             return destinations
-        self.__check_expansion(len(destinations), expansion_limit)
+        self.__check_expansion(len(destinations))
         dbc = self._dbh.cursor()
         dbc.executemany("INSERT INTO alias VALUES (%d, '%s', %%s)" %
                         (self._gid, self._addr.localpart),
@@ -160,4 +164,4 @@
         del self._dests[:]
 
 
-del _
+del _, cfg_dget
--- a/VirtualMailManager/Handler.py	Fri Apr 30 00:01:15 2010 +0000
+++ b/VirtualMailManager/Handler.py	Fri Apr 30 03:03:47 2010 +0000
@@ -32,7 +32,6 @@
      RelocatedError
 from VirtualMailManager.Relocated import Relocated
 from VirtualMailManager.Transport import Transport
-from VirtualMailManager.ext.Postconf import Postconf
 
 
 RE_DOMAIN_SEARCH = """^[a-z0-9-\.]+$"""
@@ -46,7 +45,7 @@
 class Handler(object):
     """Wrapper class to simplify the access on all the stuff from
     VirtualMailManager"""
-    __slots__ = ('_Cfg', '_cfgFileName', '_dbh', '_postconf', '__warnings')
+    __slots__ = ('_Cfg', '_cfgFileName', '_dbh', '__warnings')
 
     def __init__(self, skip_some_checks=False):
         """Creates a new Handler instance.
@@ -72,8 +71,6 @@
         if not skip_some_checks:
             self._Cfg.check()
             self._chkenv()
-            # will be moved to the Alias module
-            #self._postconf = Postconf(self._Cfg.dget('bin.postconf'))
 
     def __findCfgFile(self):
         for path in ['/root', '/usr/local/etc', '/etc']:
@@ -490,9 +487,7 @@
         alias = self.__getAlias(aliasaddress)
         destinations = [EmailAddress(address) for address in targetaddresses]
         warnings = []
-        destinations = alias.add_destinations(destinations,
-                    long(self._postconf.read('virtual_alias_expansion_limit')),
-                                              warnings)
+        destinations = alias.add_destinations(destinations, warnings)
         if warnings:
             self.__warnings.append(_('Ignored destination addresses:'))
             self.__warnings.extend(('  * %s' % w for w in warnings))
--- a/VirtualMailManager/cli/Handler.py	Fri Apr 30 00:01:15 2010 +0000
+++ b/VirtualMailManager/cli/Handler.py	Fri Apr 30 03:03:47 2010 +0000
@@ -15,7 +15,6 @@
 from VirtualMailManager.cli import read_pass
 from VirtualMailManager.cli.Config import CliConfig as Cfg
 from VirtualMailManager.constants.ERROR import INVALID_SECTION
-from VirtualMailManager.ext.Postconf import Postconf
 
 _ = lambda msg: msg
 
@@ -48,7 +47,6 @@
         if not skip_some_checks:
             self._Cfg.check()
             self._chkenv()
-            self._postconf = Postconf(self._Cfg.dget('bin.postconf'))
 
     def cfgSet(self, option, value):
         return self._Cfg.set(option, value)