update_config.py
branchv0.6.x
changeset 181 866a6d679fce
parent 168 fd496561acc6
child 229 0fb2f12648a7
equal deleted inserted replaced
180:f8279c90e99c 181:866a6d679fce
    34         os.sys.stderr.write(
    34         os.sys.stderr.write(
    35             'error: the version %s is not supported by this script\n' % VERSION)
    35             'error: the version %s is not supported by this script\n' % VERSION)
    36         raise SystemExit(3)
    36         raise SystemExit(3)
    37 
    37 
    38 def get_cfg_parser(cf):
    38 def get_cfg_parser(cf):
    39     fh = file(cf, 'r')
    39     fh = open(cf, 'r')
    40     cp = ConfigParser()
    40     cp = ConfigParser()
    41     cp.readfp(fh)
    41     cp.readfp(fh)
    42     fh.close()
    42     fh.close()
    43     return cp
    43     return cp
    44 
    44 
    45 def update_cfg_file(cp, cf):
    45 def update_cfg_file(cp, cf):
    46     copy2(cf, cf+'.bak.'+str(time()))
    46     copy2(cf, cf+'.bak.'+str(time()))
    47     fh = file(cf, 'w')
    47     fh = open(cf, 'w')
    48     cp.write(fh)
    48     cp.write(fh)
    49     fh.close()
    49     fh.close()
    50 
    50 
    51 def add_sections(cp, sections):
    51 def add_sections(cp, sections):
    52     for section in sections:
    52     for section in sections:
    70 def get_option(cp, src):
    70 def get_option(cp, src):
    71     ss, so = src.split('.')
    71     ss, so = src.split('.')
    72     return cp.get(ss, so)
    72     return cp.get(ss, so)
    73 
    73 
    74 def upd_052(cp):
    74 def upd_052(cp):
       
    75     global had_config
       
    76 
       
    77     had_config = cp.remove_section('config')
    75     add_sections(cp, ('domain', 'account'))
    78     add_sections(cp, ('domain', 'account'))
    76     if cp.has_section('domdir'):
    79     if cp.has_section('domdir'):
    77         for src, dst in (('domdir.mode',   'domain.directory_mode'),
    80         for src, dst in (('domdir.mode',   'domain.directory_mode'),
    78                          ('domdir.delete', 'domain.delete_directory'),
    81                          ('domdir.delete', 'domain.delete_directory'),
    79                          ('domdir.base',   'misc.base_directory')):
    82                          ('domdir.base',   'misc.base_directory')):
    88                      ('maildir.delete',    'account.delete_directory'),
    91                      ('maildir.delete',    'account.delete_directory'),
    89                      ('misc.forcedel',     'domain.force_deletion'),
    92                      ('misc.forcedel',     'domain.force_deletion'),
    90                      ('misc.passwdscheme', 'misc.password_scheme'),
    93                      ('misc.passwdscheme', 'misc.password_scheme'),
    91                      ('misc.dovecotvers',  'misc.dovecot_version')):
    94                      ('misc.dovecotvers',  'misc.dovecot_version')):
    92         move_option(cp, src, dst)
    95         move_option(cp, src, dst)
    93     for dst, val in (('account.random_password', 'false'),
       
    94                      ('account.password_length', '8'),
       
    95                      ('domain.auto_postmaster',  'true')):
       
    96         add_option(cp, dst, val)
       
    97 
    96 
    98 # def main():
    97 # def main():
    99 if __name__ == '__main__':
    98 if __name__ == '__main__':
   100     sect_opt = []
    99     sect_opt = []
       
   100     had_config = False
   101     cf = get_config_file()
   101     cf = get_config_file()
   102     cp = get_cfg_parser(cf)
   102     cp = get_cfg_parser(cf)
   103     update(cp)
   103     update(cp)
   104     if len(sect_opt):
   104     if len(sect_opt):
       
   105         had_config = False
   105         update_cfg_file(cp, cf)
   106         update_cfg_file(cp, cf)
   106         sect_opt.sort()
   107         sect_opt.sort()
   107         print 'Please have a look at your configuration: %s' %cf
   108         print 'Please have a look at your configuration: %s' %cf
   108         print 'This are your Renamed/New settings:'
   109         print 'This are your Renamed/New settings:'
   109         for s_o, st in sect_opt:
   110         for s_o, st in sect_opt:
   110             print '%s   %s = %s' % (st, s_o, get_option(cp, s_o))
   111             print '%s   %s = %s' % (st, s_o, get_option(cp, s_o))
       
   112     if had_config:
       
   113         update_cfg_file(cp, cf)
       
   114         print 'Removed section "config" with option "done" (obsolte)'
   111         print
   115         print
   112