VirtualMailManager/config.py
branchv0.6.x
changeset 348 ca7575401549
parent 342 b0c971f943dc
child 353 2ae40cd0d213
equal deleted inserted replaced
347:586367ee042b 348:ca7575401549
     6     ~~~~~~~~~~~~~~~~~~~~~~~~~
     6     ~~~~~~~~~~~~~~~~~~~~~~~~~
     7 
     7 
     8     VMM's configuration module for simplified configuration access.
     8     VMM's configuration module for simplified configuration access.
     9 """
     9 """
    10 
    10 
    11 import re
       
    12 
       
    13 from ConfigParser import \
    11 from ConfigParser import \
    14      Error, MissingSectionHeaderError, NoOptionError, NoSectionError, \
    12      Error, MissingSectionHeaderError, NoOptionError, NoSectionError, \
    15      ParsingError, RawConfigParser
    13      ParsingError, RawConfigParser
    16 from cStringIO import StringIO# TODO: move interactive stff to cli
    14 from cStringIO import StringIO# TODO: move interactive stff to cli
    17 
    15 
    18 from VirtualMailManager.common import \
    16 from VirtualMailManager.common import VERSION_RE, \
    19      exec_ok, expand_path, get_unicode, lisdir, version_hex
    17      exec_ok, expand_path, get_unicode, lisdir, version_hex
    20 from VirtualMailManager.constants import CONF_ERROR
    18 from VirtualMailManager.constants import CONF_ERROR
    21 from VirtualMailManager.errors import ConfigError, VMMError
    19 from VirtualMailManager.errors import ConfigError, VMMError
    22 from VirtualMailManager.maillocation import known_format
    20 from VirtualMailManager.maillocation import known_format
    23 from VirtualMailManager.password import verify_scheme as _verify_scheme
    21 from VirtualMailManager.password import verify_scheme as _verify_scheme
   439 def check_version_format(version_string):
   437 def check_version_format(version_string):
   440     """Check if the *version_string* has the proper format, e.g.: '1.2.3'.
   438     """Check if the *version_string* has the proper format, e.g.: '1.2.3'.
   441     Returns the validated version string if it has the expected format.
   439     Returns the validated version string if it has the expected format.
   442     Otherwise a `ConfigValueError` will be raised.
   440     Otherwise a `ConfigValueError` will be raised.
   443     """
   441     """
   444     version_re = r'^\d+\.\d+\.(?:\d+|(?:alpha|beta|rc)\d+)$'
   442     if not VERSION_RE.match(version_string):
   445     if not re.match(version_re, version_string):
       
   446         raise ConfigValueError(_(u"Not a valid Dovecot version: '%s'") %
   443         raise ConfigValueError(_(u"Not a valid Dovecot version: '%s'") %
   447                                get_unicode(version_string))
   444                                get_unicode(version_string))
   448     return version_string
   445     return version_string
   449 
   446 
   450 
   447