VMM/{Account,common,maillocation}: Dovecot version (check) fixes. v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Mon, 26 Apr 2010 02:15:36 +0000
branchv0.6.x
changeset 265 3c0173418d5d
parent 264 04fea4d8b900
child 266 e14c345b44a1
VMM/{Account,common,maillocation}: Dovecot version (check) fixes. - Account: fixed versions dependencies. - maillocation: use the version string, may be uses in a error message. - common: version_hex() raises a ValueError, instead of returning 0, if the version string is invalid.
VirtualMailManager/Account.py
VirtualMailManager/common.py
VirtualMailManager/maillocation.py
--- a/VirtualMailManager/Account.py	Sun Apr 25 04:51:14 2010 +0000
+++ b/VirtualMailManager/Account.py	Mon Apr 26 02:15:36 2010 +0000
@@ -94,7 +94,7 @@
         self._chk_state()
         if service not in (None, 'all', 'imap', 'pop3', 'sieve', 'smtp'):
             raise AErr(_(u"Unknown service: '%s'.") % service, UNKNOWN_SERVICE)
-        if dcvers > 0x10100f0:
+        if dcvers >= 0x10200b2:
             sieve_col = 'sieve'
         else:
             sieve_col = 'managesieve'
@@ -230,7 +230,7 @@
                        ACCOUNT_MISSING_PASSWORD)
         assert all(isinstance(service, bool) for service in (smtp, pop3, imap,
                                                              sieve))
-        if dcvers > 0x10100f0:
+        if dcvers >= 0x10200b2:
             sieve_col = 'sieve'
         else:
             sieve_col = 'managesieve'
@@ -291,7 +291,7 @@
           `dovecot --version`.
         """
         self._chk_state()
-        if dcvers > 0x10100f0:
+        if dcvers >= 0x10200b2:
             sieve_col = 'sieve'
         else:
             sieve_col = 'managesieve'
--- a/VirtualMailManager/common.py	Sun Apr 25 04:51:14 2010 +0000
+++ b/VirtualMailManager/common.py	Mon Apr 26 02:15:36 2010 +0000
@@ -16,6 +16,8 @@
      NOT_EXECUTABLE, NO_SUCH_BINARY, NO_SUCH_DIRECTORY
 from VirtualMailManager.errors import VMMError
 
+
+_version_re = re.compile(r'^(\d+)\.(\d+)\.(?:(\d+)|(alpha|beta|rc)(\d+))$')
 _ = lambda msg: msg
 
 
@@ -65,24 +67,24 @@
 
 def version_hex(version_string):
     """Convert a Dovecot version, e.g.: '1.2.3' or '2.0.beta4', to an int.
-    Returns 0 if the *version_string* has the wrong™ format.
+    Raises a `ValueError` if the *version_string* has the wrong™ format.
 
     version_hex('1.2.3') -> 16909296
     hex(version_hex('1.2.3')) -> '0x10203f0'
     """
     version = 0
-    version_re = r'^(\d+)\.(\d+)\.(?:(\d+)|(alpha|beta|rc)(\d+))$'
     version_level = dict(alpha=0xA, beta=0xB, rc=0xC)
-    version_mo = re.match(version_re, version_string)
-    if version_mo:
-        major, minor, patch, level, serial = version_mo.groups()
-        version += int(major) << 24
-        version += int(minor) << 16
-        if patch:
-            version += int(patch) << 8
-        version += version_level.get(level, 0xF) << 4
-        if serial:
-            version += int(serial)
+    version_mo = _version_re.match(version_string)
+    if not version_mo:
+        raise ValueError('Invalid version string: %r' % version_string)
+    major, minor, patch, level, serial = version_mo.groups()
+    version += int(major) << 24
+    version += int(minor) << 16
+    if patch:
+        version += int(patch) << 8
+    version += version_level.get(level, 0xF) << 4
+    if serial:
+        version += int(serial)
     return version
 
 del _
--- a/VirtualMailManager/maillocation.py	Sun Apr 25 04:51:14 2010 +0000
+++ b/VirtualMailManager/maillocation.py	Mon Apr 26 02:15:36 2010 +0000
@@ -26,14 +26,13 @@
 SDBOX_NAME = 'dbox'
 
 _storage = {
-    MAILDIR_ID: dict(dovecot_version=0x10000f0, postfix=True,
-                     prefix='maildir:', directory=MAILDIR_NAME,
-                     mid=MAILDIR_ID),
-    MBOX_ID: dict(dovecot_version=0x10000f0, postfix=True, prefix='mbox:',
+    MAILDIR_ID: dict(dovecot_version='1.0.0', postfix=True, prefix='maildir:',
+                     directory=MAILDIR_NAME, mid=MAILDIR_ID),
+    MBOX_ID: dict(dovecot_version='1.0.0', postfix=True, prefix='mbox:',
                   directory=MBOX_NAME, mid=MBOX_ID),
-    MDBOX_ID: dict(dovecot_version=0x20000a1, postfix=False, prefix='mdbox:',
-                   directory=MDBOX_NAME, mid=MDBOX_ID),
-    SDBOX_ID: dict(dovecot_version=0x10000f0, postfix=False, prefix='dbox:',
+    MDBOX_ID: dict(dovecot_version='2.0.alpha1', postfix=False,
+                   prefix='mdbox:', directory=MDBOX_NAME, mid=MDBOX_ID),
+    SDBOX_ID: dict(dovecot_version='1.0.0', postfix=False, prefix='dbox:',
                    directory=SDBOX_NAME, mid=SDBOX_ID),
 }