VirtualMailManager/Config.py
changeset 48 0d5f58f8b8f5
parent 47 191d5a5adc4a
child 49 9bd033177377
equal deleted inserted replaced
47:191d5a5adc4a 48:0d5f58f8b8f5
    17 __date__ = '$Date$'.split()[1]
    17 __date__ = '$Date$'.split()[1]
    18 
    18 
    19 import locale
    19 import locale
    20 import sys
    20 import sys
    21 from shutil import copy2
    21 from shutil import copy2
    22 from ConfigParser import ConfigParser
    22 from ConfigParser import ConfigParser, MissingSectionHeaderError, ParsingError
    23 from cStringIO import StringIO
    23 from cStringIO import StringIO
    24 
    24 
    25 from Exceptions import VMMConfigException
    25 from Exceptions import VMMConfigException
    26 import constants.ERROR as ERR
    26 import constants.ERROR as ERR
    27 
    27 
    85 
    85 
    86     def load(self):
    86     def load(self):
    87         """Loads the configuration, r/o"""
    87         """Loads the configuration, r/o"""
    88         try:
    88         try:
    89             self.__cfgFile = file(self.__cfgFileName, 'r')
    89             self.__cfgFile = file(self.__cfgFileName, 'r')
    90         except:
    90             self.readfp(self.__cfgFile)
    91             raise
    91         except (MissingSectionHeaderError, ParsingError), e:
    92         self.readfp(self.__cfgFile)
    92             self.__cfgFile.close()
       
    93             raise VMMConfigException(str(e), ERR.CONF_ERROR)
    93         self.__cfgFile.close()
    94         self.__cfgFile.close()
    94 
    95 
    95     def check(self):
    96     def check(self):
    96         if not self.__chkSections():
    97         if not self.__chkSections():
    97             errmsg = StringIO()
    98             errmsg = StringIO()
   100                     errmsg.write(_(u"missing section: %s\n") % k)
   101                     errmsg.write(_(u"missing section: %s\n") % k)
   101                 else:
   102                 else:
   102                     errmsg.write(_(u"missing options in section %s:\n") % k)
   103                     errmsg.write(_(u"missing options in section %s:\n") % k)
   103                     for o in v:
   104                     for o in v:
   104                         errmsg.write(" * %s\n" % o)
   105                         errmsg.write(" * %s\n" % o)
   105             raise VMMConfigException((errmsg.getvalue(), ERR.CONF_ERROR))
   106             raise VMMConfigException(errmsg.getvalue(), ERR.CONF_ERROR)
   106 
   107 
   107     def getsections(self):
   108     def getsections(self):
   108         """Return a list with all configurable sections."""
   109         """Return a list with all configurable sections."""
   109         return self.__VMMsections[:-1]
   110         return self.__VMMsections[:-1]
   110 
   111 
   123                 self.__changes = True
   124                 self.__changes = True
   124         except ValueError:
   125         except ValueError:
   125             self.set('config', 'done', 'False')
   126             self.set('config', 'done', 'False')
   126             self.__changes = True
   127             self.__changes = True
   127         for s in sections:
   128         for s in sections:
   128             if s == 'config':
   129             if s != 'config':
   129                 pass
       
   130             else:
       
   131                 print _(u'* Config section: »%s«') % s
   130                 print _(u'* Config section: »%s«') % s
   132             for opt, val in self.items(s):
   131             for opt, val in self.items(s):
   133                 newval = raw_input(
   132                 newval = raw_input(
   134                 _('Enter new value for option %s [%s]: ').encode(
   133                 _('Enter new value for option %s [%s]: ').encode(
   135                     ENCODING, 'replace') % (opt, val))
   134                     ENCODING, 'replace') % (opt, val))