VirtualMailManager/config.py
branchv0.6.x
changeset 384 d3a97f7fb98a
parent 366 d6573da35b5f
child 458 4ff0fa3ba0fa
equal deleted inserted replaced
383:ac5ac03b58da 384:d3a97f7fb98a
    12      Error, MissingSectionHeaderError, NoOptionError, NoSectionError, \
    12      Error, MissingSectionHeaderError, NoOptionError, NoSectionError, \
    13      ParsingError, RawConfigParser
    13      ParsingError, RawConfigParser
    14 from cStringIO import StringIO
    14 from cStringIO import StringIO
    15 
    15 
    16 from VirtualMailManager.common import VERSION_RE, \
    16 from VirtualMailManager.common import VERSION_RE, \
    17      exec_ok, expand_path, get_unicode, lisdir, version_hex
    17      exec_ok, expand_path, get_unicode, lisdir, size_in_bytes, version_hex
    18 from VirtualMailManager.constants import CONF_ERROR
    18 from VirtualMailManager.constants import CONF_ERROR
    19 from VirtualMailManager.errors import ConfigError, VMMError
    19 from VirtualMailManager.errors import ConfigError, VMMError
    20 from VirtualMailManager.maillocation import known_format
    20 from VirtualMailManager.maillocation import known_format
    21 from VirtualMailManager.password import verify_scheme as _verify_scheme
    21 from VirtualMailManager.password import verify_scheme as _verify_scheme
    22 
    22 
   345                 'crypt_sha512_rounds': LCO(int, 5000, self.getint),
   345                 'crypt_sha512_rounds': LCO(int, 5000, self.getint),
   346                 'dovecot_version': LCO(str, None, self.hexversion,
   346                 'dovecot_version': LCO(str, None, self.hexversion,
   347                                        check_version_format),
   347                                        check_version_format),
   348                 'password_scheme': LCO(str, 'CRAM-MD5', self.get,
   348                 'password_scheme': LCO(str, 'CRAM-MD5', self.get,
   349                                        verify_scheme),
   349                                        verify_scheme),
       
   350                 'quota_bytes': LCO(str, '0', self.get_in_bytes,
       
   351                                    check_size_value),
       
   352                 'quota_messages': LCO(int, 0, self.getint),
   350                 'transport': LCO(str, 'dovecot:', self.get),
   353                 'transport': LCO(str, 'dovecot:', self.get),
   351             },
   354             },
   352         }
   355         }
   353 
   356 
   354     def load(self):
   357     def load(self):
   403 
   406 
   404     def hexversion(self, section, option):
   407     def hexversion(self, section, option):
   405         """Converts the version number (e.g.: 1.2.3) from the *option*'s
   408         """Converts the version number (e.g.: 1.2.3) from the *option*'s
   406         value to an int."""
   409         value to an int."""
   407         return version_hex(self.get(section, option))
   410         return version_hex(self.get(section, option))
       
   411 
       
   412     def get_in_bytes(self, section, option):
       
   413         """Converts the size value (e.g.: 1024k) from the *option*'s
       
   414         value to a long"""
       
   415         return size_in_bytes(self.get(section, option))
   408 
   416 
   409     def unicode(self, section, option):
   417     def unicode(self, section, option):
   410         """Returns the value of the `option` from `section`, converted
   418         """Returns the value of the `option` from `section`, converted
   411         to Unicode."""
   419         to Unicode."""
   412         return get_unicode(self.get(section, option))
   420         return get_unicode(self.get(section, option))
   447         # section mailbox
   455         # section mailbox
   448         value = self.dget('mailbox.format')
   456         value = self.dget('mailbox.format')
   449         if not known_format(value):
   457         if not known_format(value):
   450             self._missing['mailbox'] = ['format: ' +\
   458             self._missing['mailbox'] = ['format: ' +\
   451                               _(u"Unsupported mailbox format: '%s'") % value]
   459                               _(u"Unsupported mailbox format: '%s'") % value]
       
   460         # section misc
       
   461         try:
       
   462             value = self.dget('misc.quota_bytes')
       
   463         except (ValueError, TypeError), err:
       
   464             self._missing['misc'] = [u'quota_bytes: ' + str(err)]
   452 
   465 
   453 
   466 
   454 def is_dir(path):
   467 def is_dir(path):
   455     """Check if the expanded path is a directory.  When the expanded path
   468     """Check if the expanded path is a directory.  When the expanded path
   456     is a directory the expanded path will be returned.  Otherwise a
   469     is a directory the expanded path will be returned.  Otherwise a
   487     format = format.lower()
   500     format = format.lower()
   488     if known_format(format):
   501     if known_format(format):
   489         return format
   502         return format
   490     raise ConfigValueError(_(u"Unsupported mailbox format: '%s'") %
   503     raise ConfigValueError(_(u"Unsupported mailbox format: '%s'") %
   491                            get_unicode(format))
   504                            get_unicode(format))
       
   505 
       
   506 
       
   507 def check_size_value(value):
       
   508     """Check if the size value *value* has the proper format, e.g.: 1024k.
       
   509     Returns the validated value string if it has the expected format.
       
   510     Otherwise a `ConfigValueError` will be raised."""
       
   511     try:
       
   512         tmp = size_in_bytes(value)
       
   513     except (TypeError, ValueError), err:
       
   514         raise ConfigValueError(_(u"Not a valid size value: '%s'") %
       
   515                                get_unicode(value))
       
   516     return value
   492 
   517 
   493 
   518 
   494 def check_version_format(version_string):
   519 def check_version_format(version_string):
   495     """Check if the *version_string* has the proper format, e.g.: '1.2.3'.
   520     """Check if the *version_string* has the proper format, e.g.: '1.2.3'.
   496     Returns the validated version string if it has the expected format.
   521     Returns the validated version string if it has the expected format.