VMM: Code cleanup. v0.7.x
authorPascal Volk <user@localhost.localdomain.org>
Wed, 09 Jan 2013 20:55:27 +0000
branchv0.7.x
changeset 681 4cab983479db
parent 680 5365af94a8ec
child 682 697350dd9369
VMM: Code cleanup.
VirtualMailManager/cli/subcommands.py
VirtualMailManager/handler.py
--- a/VirtualMailManager/cli/subcommands.py	Sun Jan 06 19:10:37 2013 +0000
+++ b/VirtualMailManager/cli/subcommands.py	Wed Jan 09 20:55:27 2013 +0000
@@ -228,23 +228,20 @@
 
 def domain_quota(ctx):
     """update the quota limit of the specified domain"""
-    force = 'force' if ctx.args.force else None
     ctx.hdlr.domain_quotalimit(ctx.args.fqdn.lower(), ctx.args.storage,
-                               ctx.args.messages, force)
+                               ctx.args.messages, ctx.args.force)
 
 
 def domain_services(ctx):
     """allow all named service and block the uncredited."""
-    force = 'force' if ctx.args.force else None
     services = ctx.args.services if ctx.args.services else []
-    ctx.hdlr.domain_services(ctx.args.fqdn.lower(), force, *services)
+    ctx.hdlr.domain_services(ctx.args.fqdn.lower(), ctx.args.force, *services)
 
 
 def domain_transport(ctx):
     """update the transport of the specified domain"""
-    force = 'force' if ctx.args.force else None
     ctx.hdlr.domain_transport(ctx.args.fqdn.lower(),
-                              ctx.args.transport.lower(), force)
+                              ctx.args.transport.lower(), ctx.args.force)
 
 
 def domain_note(ctx):
--- a/VirtualMailManager/handler.py	Sun Jan 06 19:10:37 2013 +0000
+++ b/VirtualMailManager/handler.py	Wed Jan 09 20:55:27 2013 +0000
@@ -451,27 +451,20 @@
         dom.save()
         self._make_domain_dir(dom)
 
-    def domain_quotalimit(self, domainname, bytes_, messages=0, force=None):
+    def domain_quotalimit(self, domainname, bytes_, messages=0, force=False):
         """Wrapper around Domain.update_quotalimit()."""
         if not all(isinstance(i, int) for i in (bytes_, messages)):
             raise TypeError("'bytes_' and 'messages' have to be "
                             "integers or longs.")
-        if force is not None and force != 'force':
-            raise DomainError(_("Invalid argument: '%s'") % force,
-                              INVALID_ARGUMENT)
+        assert isinstance(force, bool)
         dom = self._get_domain(domainname)
         quotalimit = QuotaLimit(self._dbh, bytes=bytes_, messages=messages)
-        if force is None:
-            dom.update_quotalimit(quotalimit)
-        else:
-            dom.update_quotalimit(quotalimit, force=True)
+        dom.update_quotalimit(quotalimit, force)
 
-    def domain_services(self, domainname, force=None, *services):
+    def domain_services(self, domainname, force=False, *services):
         """Wrapper around Domain.update_serviceset()."""
+        assert isinstance(force, bool)
         kwargs = dict.fromkeys(SERVICES, False)
-        if force is not None and force != 'force':
-            raise DomainError(_("Invalid argument: '%s'") % force,
-                              INVALID_ARGUMENT)
         for service in set(services):
             if service not in SERVICES:
                 raise DomainError(_("Unknown service: '%s'") % service,
@@ -480,19 +473,14 @@
 
         dom = self._get_domain(domainname)
         serviceset = ServiceSet(self._dbh, **kwargs)
-        dom.update_serviceset(serviceset, (True, False)[not force])
+        dom.update_serviceset(serviceset, force)
 
-    def domain_transport(self, domainname, transport, force=None):
+    def domain_transport(self, domainname, transport, force=False):
         """Wrapper around Domain.update_transport()"""
-        if force is not None and force != 'force':
-            raise DomainError(_("Invalid argument: '%s'") % force,
-                              INVALID_ARGUMENT)
+        assert isinstance(force, bool)
         dom = self._get_domain(domainname)
         trsp = Transport(self._dbh, transport=transport)
-        if force is None:
-            dom.update_transport(trsp)
-        else:
-            dom.update_transport(trsp, force=True)
+        dom.update_transport(trsp, force)
 
     def domain_note(self, domainname, note):
         """Wrapper around Domain.update_note()"""