VirtualMailManager/Config.py
changeset 47 191d5a5adc4a
parent 34 6d74e20c5b3b
child 48 0d5f58f8b8f5
equal deleted inserted replaced
46:7ece710c559d 47:191d5a5adc4a
    14 __author__ = 'Pascal Volk <p.volk@veb-it.de>'
    14 __author__ = 'Pascal Volk <p.volk@veb-it.de>'
    15 __version__ = VERSION
    15 __version__ = VERSION
    16 __revision__ = 'rev '+'$Rev$'.split()[1]
    16 __revision__ = 'rev '+'$Rev$'.split()[1]
    17 __date__ = '$Date$'.split()[1]
    17 __date__ = '$Date$'.split()[1]
    18 
    18 
       
    19 import locale
    19 import sys
    20 import sys
    20 import gettext
       
    21 from shutil import copy2
    21 from shutil import copy2
    22 from ConfigParser import ConfigParser
    22 from ConfigParser import ConfigParser
    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 
    28 gettext.bindtextdomain('vmm', '/usr/local/share/locale')
    28 locale.setlocale(locale.LC_ALL, '')
    29 gettext.textdomain('vmm')
    29 ENCODING = locale.nl_langinfo(locale.CODESET)
    30 _ = gettext.gettext
       
    31 
    30 
    32 class VMMConfig(ConfigParser):
    31 class VMMConfig(ConfigParser):
    33     """This class is for configure the Virtual Mail Manager.
    32     """This class is for configure the Virtual Mail Manager.
    34 
    33 
    35     You can specify settings for the database connection
    34     You can specify settings for the database connection
    96     def check(self):
    95     def check(self):
    97         if not self.__chkSections():
    96         if not self.__chkSections():
    98             errmsg = StringIO()
    97             errmsg = StringIO()
    99             for k,v in self.__missing.items():
    98             for k,v in self.__missing.items():
   100                 if v[0] is True:
    99                 if v[0] is True:
   101                     errmsg.write(_("missing section: %s\n") % k)
   100                     errmsg.write(_(u"missing section: %s\n") % k)
   102                 else:
   101                 else:
   103                     errmsg.write(_("missing options in section %s:\n") % k)
   102                     errmsg.write(_(u"missing options in section %s:\n") % k)
   104                     for o in v:
   103                     for o in v:
   105                         errmsg.write(" * %s\n" % o)
   104                         errmsg.write(" * %s\n" % o)
   106             raise VMMConfigException((errmsg.getvalue(), ERR.CONF_ERROR))
   105             raise VMMConfigException((errmsg.getvalue(), ERR.CONF_ERROR))
   107 
   106 
   108     def getsections(self):
   107     def getsections(self):
   114 
   113 
   115         Keyword arguments:
   114         Keyword arguments:
   116         sections -- list of strings
   115         sections -- list of strings
   117         """
   116         """
   118         if not isinstance(sections, list):
   117         if not isinstance(sections, list):
   119             raise TypeError(_("Argument 'sections' is not a list."))
   118             raise TypeError(_(u"Argument 'sections' is not a list."))
   120         # if [config] done = false (default at 1st run),
   119         # if [config] done = false (default at 1st run),
   121         # then set changes true
   120         # then set changes true
   122         try:
   121         try:
   123             if not self.getboolean('config', 'done'):
   122             if not self.getboolean('config', 'done'):
   124                 self.__changes = True
   123                 self.__changes = True
   127             self.__changes = True
   126             self.__changes = True
   128         for s in sections:
   127         for s in sections:
   129             if s == 'config':
   128             if s == 'config':
   130                 pass
   129                 pass
   131             else:
   130             else:
   132                 print _('* Config section: %s') % s
   131                 print _(u'* Config section: »%s«') % s
   133             for opt, val in self.items(s):
   132             for opt, val in self.items(s):
   134                 newval = raw_input(_('Enter new value for %s [%s]: ')
   133                 newval = raw_input(
   135                         %(opt, val))
   134                 _('Enter new value for option %s [%s]: ').encode(
       
   135                     ENCODING, 'replace') % (opt, val))
   136                 if newval and newval != val:
   136                 if newval and newval != val:
   137                     self.set(s, opt, newval)
   137                     self.set(s, opt, newval)
   138                     self.__changes = True
   138                     self.__changes = True
   139             print
   139             print
   140         if self.__changes:
   140         if self.__changes: