VirtualMailManager/cli/Config.py
branchv0.6.x
changeset 204 83938336c518
parent 189 e63853509ad0
child 206 da07dd944ad1
--- a/VirtualMailManager/cli/Config.py	Fri Feb 12 09:10:54 2010 +0000
+++ b/VirtualMailManager/cli/Config.py	Sat Feb 13 03:20:42 2010 +0000
@@ -8,16 +8,21 @@
     Adds some interactive stuff to the Config class.
 """
 
+from shutil import copy2
+
 from VirtualMailManager import ENCODING
-from VirtualMailManager.Config import Config 
+from VirtualMailManager.Config import Config, ConfigValueError, LazyConfig
+from VirtualMailManager.Exceptions import VMMConfigException
 from VirtualMailManager.cli import w_std
 from VirtualMailManager.constants.ERROR import VMM_TOO_MANY_FAILURES
 
+
 class CliConfig(Config):
     """Adds the interactive ``configure`` method to the `Config` class
     and overwrites `LazyConfig.set(), in order to update a single option
     in the configuration file with a single command line command.
     """
+
     def configure(self, sections):
         """Interactive method for configuring all options of the given
         iterable ``sections`` object."""
@@ -27,15 +32,15 @@
 
         w_std(_(u'Using configuration file: %s\n') % self._cfgFileName)
         for s in sections:
-            w_std(_(u'* Configuration section: ā€œ%sā€') % s )
+            w_std(_(u'* Configuration section: %r') % s)
             for opt, val in self.items(s):
                 failures = 0
                 while True:
-                    newval = raw_input(input_fmt.encode(ENCODING,'replace') %{
-                                       'option': opt, 'current_value': val})
+                    newval = raw_input(input_fmt.encode(ENCODING, 'replace') %
+                                       {'option': opt, 'current_value': val})
                     if newval and newval != val:
                         try:
-                            LazyConfig.set('%s.%s' % (s, opt), newval)
+                            LazyConfig.set(self, '%s.%s' % (s, opt), newval)
                             break
                         except (ValueError, ConfigValueError), e:
                             w_std(_(u'Warning: %s') % e)
@@ -43,7 +48,7 @@
                             if failures > 2:
                                 raise VMMConfigException(
                                     _(u'Too many failures - try again later.'),
-                                    VMM_TOO_MANY_FAILURES)
+                                                         VMM_TOO_MANY_FAILURES)
                     else:
                         break
             print
@@ -60,7 +65,7 @@
         ``LazyConfigOption.cls``"""
         section, option_ = self._get_section_option(option)
         val = self._cfg[section][option_].cls(value)
-        if not self._cfg[section][option_].validate is None:
+        if self._cfg[section][option_].validate:
             val = self._cfg[section][option_].validate(val)
         # Do not write default values also skip identical values
         if not self._cfg[section][option_].default is None:
@@ -76,7 +81,7 @@
 
     def __saveChanges(self):
         """Writes changes to the configuration file."""
-        copy2(self._cfgFileName, self._cfgFileName+'.bak')
+        copy2(self._cfgFileName, self._cfgFileName + '.bak')
         self._cfgFile = open(self._cfgFileName, 'w')
         self.write(self._cfgFile)
         self._cfgFile.close()