VirtualMailManager/cli/config.py
branchv0.6.x
changeset 344 0d2430dc6ef8
parent 341 6709d0faf2f5
child 349 d60ffbc0124b
equal deleted inserted replaced
343:9232ed7e4d85 344:0d2430dc6ef8
    13 
    13 
    14 from VirtualMailManager import ENCODING
    14 from VirtualMailManager import ENCODING
    15 from VirtualMailManager.config import Config, ConfigValueError, LazyConfig
    15 from VirtualMailManager.config import Config, ConfigValueError, LazyConfig
    16 from VirtualMailManager.errors import ConfigError
    16 from VirtualMailManager.errors import ConfigError
    17 from VirtualMailManager.cli import w_err, w_std
    17 from VirtualMailManager.cli import w_err, w_std
    18 from VirtualMailManager.constants import VMM_TOO_MANY_FAILURES
    18 from VirtualMailManager.constants import CONF_ERROR, VMM_TOO_MANY_FAILURES
    19 
    19 
    20 _ = lambda msg: msg
    20 _ = lambda msg: msg
    21 
    21 
    22 
    22 
    23 class CliConfig(Config):
    23 class CliConfig(Config):
    63         """Set the value of an option.
    63         """Set the value of an option.
    64 
    64 
    65         If the new `value` has been set, the configuration file will be
    65         If the new `value` has been set, the configuration file will be
    66         immediately updated.
    66         immediately updated.
    67 
    67 
    68         Throws a ``ValueError`` if `value` couldn't be converted to
    68         Throws a ``ConfigError`` if `value` couldn't be converted to
    69         ``LazyConfigOption.cls``"""
    69         ``LazyConfigOption.cls`` or ``LazyConfigOption.validate`` fails."""
    70         section, option_ = self._get_section_option(option)
    70         section, option_ = self._get_section_option(option)
    71         val = self._cfg[section][option_].cls(value)
    71         try:
    72         if self._cfg[section][option_].validate:
    72             val = self._cfg[section][option_].cls(value)
    73             val = self._cfg[section][option_].validate(val)
    73             if self._cfg[section][option_].validate:
       
    74                 val = self._cfg[section][option_].validate(val)
       
    75         except (ValueError, ConfigValueError), err:
       
    76             raise ConfigError(str(err), CONF_ERROR)
    74         # Do not write default values also skip identical values
    77         # Do not write default values also skip identical values
    75         if not self._cfg[section][option_].default is None:
    78         if not self._cfg[section][option_].default is None:
    76             old_val = self.dget(option)
    79             old_val = self.dget(option)
    77         else:
    80         else:
    78             old_val = self.pget(option)
    81             old_val = self.pget(option)