* 'VirtualMailManager/VirtualMailManager.py'
authorPascal Volk <neverseen@users.sourceforge.net>
Tue, 15 Apr 2008 02:49:21 +0000
changeset 18 c98e08791ee8
parent 17 fe9be0081e5f
child 19 bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py' * 'VirtualMailManager/Domain.py' * 'vmm' - added code to optional force new transport for all existing accounts.
ChangeLog
VirtualMailManager/Domain.py
VirtualMailManager/VirtualMailManager.py
vmm
--- a/ChangeLog	Tue Apr 15 01:28:34 2008 +0000
+++ b/ChangeLog	Tue Apr 15 02:49:21 2008 +0000
@@ -5,6 +5,11 @@
 	* vmm (main): Added code for modify user's transport
 	* VirtualMailManager/VirtualMailManager.py: Implemented
 	VirtualMailManager.user_transport()
+	* VirtualMailManager/VirtualMailManager.py
+	(VirtualMailManager.domain_transport()):
+	* vmm:
+	* VirtualMailManager/Domain.py (Domain.updateTransport()): Added code to
+	optional force new transport for all existing accounts.
 
 2008-04-14  Pascal Volk  <neverseen@users.sourceforge.net>
 
--- a/VirtualMailManager/Domain.py	Tue Apr 15 01:28:34 2008 +0000
+++ b/VirtualMailManager/Domain.py	Tue Apr 15 02:49:21 2008 +0000
@@ -153,11 +153,12 @@
             raise VMMDomainException(("Domain doesn't exist yet.",
                 ERR.NO_SUCH_DOMAIN))
 
-    def updateTransport(self, transport):
+    def updateTransport(self, transport, force = False):
         """Sets a new transport for the domain.
 
         Keyword arguments:
         transport -- the new transport (str)
+        force -- True/False force new transport for all accounts (bool)
         """
         if self._id > 0:
             trsp = Transport(self._dbh, transport=transport)
@@ -166,6 +167,11 @@
                     self._id)
             if dbc.rowcount > 0:
                 self._dbh.commit()
+            if force:
+                dbc.execute("UPDATE users SET tid=%s WHERE gid=%s",
+                        trsp.getID(), self._id)
+                if dbc.rowcount > 0:
+                    self._dbh.commit()
             dbc.close()
         else:
             raise VMMDomainException(("Domain doesn't exist yet.",
--- a/VirtualMailManager/VirtualMailManager.py	Tue Apr 15 01:28:34 2008 +0000
+++ b/VirtualMailManager/VirtualMailManager.py	Tue Apr 15 02:49:21 2008 +0000
@@ -414,13 +414,19 @@
         dom.save()
         self.__domdirmake(dom.getDir(), dom.getID())
 
-    def domain_transport(self, domainname, transport):
+    def domain_transport(self, domainname, transport, force=None):
+        if force is not None and force != 'force':
+            raise VMMDomainException(('Invalid argument: »%s«' % force,
+                ERR.INVALID_OPTION))
         dom = self.__getDomain(domainname, None)
-        dom.updateTransport(transport)
+        if force is None:
+            dom.updateTransport(transport)
+        else:
+            dom.updateTransport(transport, force=True)
 
     def domain_delete(self, domainname, force=None):
         if not force is None and force not in ['deluser','delalias','delall']:
-            raise VMMDomainException(('Invalid argument: «%s»' % force,
+            raise VMMDomainException(('Invalid argument: »%s«' % force,
                 ERR.INVALID_OPTION))
         dom = self.__getDomain(domainname)
         gid = dom.getID()
--- a/vmm	Tue Apr 15 01:28:34 2008 +0000
+++ b/vmm	Tue Apr 15 02:49:21 2008 +0000
@@ -32,12 +32,13 @@
 
   da    domainadd       domain.tld       transport*
   di    domaininfo      domain.tld       detailed*
-  dt    domaintransport domain.tld       transport
+  dt    domaintransport domain.tld       transport force*
   dd    domaindelete    domain.tld       delalias*|deluser*|delall*
   ua    useradd         user@domain.tld  password*
   ui    userinfo        user@domain.tld  du*
   un    username        user@domain.tld  'Users Name'
   up    userpassword    user@domain.tld  password*
+  ut    usertransport   user@domain.tld  transport
   u0    userdisable     user@domain.tld
   u1    userenable      user@domain.tld
   ud    userdelete      user@domain.tld
@@ -154,8 +155,10 @@
         usage(EXIT.MISSING_ARGS, 'Missing domain name and new transport.')
     if argc < 4:
         usage(EXIT.MISSING_ARGS, 'Missing new transport.')
+    elif argc < 5:
+        vmm.domain_transport(sys.argv[2].lower(), sys.argv[3])
     else:
-        vmm.domain_transport(sys.argv[2].lower(), sys.argv[3])
+        vmm.domain_transport(sys.argv[2].lower(), sys.argv[3], sys.argv[4])
 
 def user_add():
     global argc