update_config_0.4.x-0.5.py
author Pascal Volk <neverseen@users.sourceforge.net>
Mon, 10 Aug 2009 03:29:52 +0000
changeset 104 c0b5afb89088
child 118 cf85d78486ce
permissions -rwxr-xr-x
Restored update_*_0.4.x-0.5.p*, modified upgrade.sh for v. 0.5.1 update_config_0.4.x-0.5.py, update_tables_0.4.x-0.5.pgsql: * restored from tag vmm-0.5 for upgrades from version 0.4.x upgrade.sh: * added stuff for 0.4.x cleanups

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Copyright (c) 2008 - 2009, VEB IT
# See COPYING for distribution information.

import sys
from ConfigParser import ConfigParser
from shutil import copy2

cf = '/usr/local/etc/vmm.cfg'
fh = file(cf, 'r')
cp = ConfigParser()
cp.readfp(fh)
fh.close()

if not cp.has_option('maildir', 'name') or not cp.has_option('maildir',
        'folders') or cp.has_option('maildir', 'folder'):
    copy2(cf, cf+'.bak_upd_0.4.x-0.5')
    fh = file(cf, 'w')
    if not cp.has_option('maildir', 'name'):
        if cp.has_option('maildir', 'folder'):
            cp.set('maildir', 'name', cp.get('maildir', 'folder'))
            cp.remove_option('maildir', 'folder')
        else:
            cp.set('maildir', 'name', 'Maildir')
    if not cp.has_option('maildir', 'folders'):
        cp.set('maildir', 'folders', 'Drafts:Sent:Templates:Trash')
    if cp.has_option('maildir', 'folder'):
        cp.remove_option('maildir', 'folder')
    cp.write(fh)
    fh.close()

if not cp.has_option('bin', 'postconf'):
    fh = file(cf, 'w')
    try:
        postconf = sys.argv[1].strip()
        if len(postconf):
            cp.set('bin', 'postconf', postconf)
        else: # possible?
            cp.set('bin', 'postconf', '/usr/sbin/postconf')
    except IndexError:
        cp.set('bin', 'postconf', '/usr/sbin/postconf')
    cp.write(fh)
    fh.close()
    print
    print "Please have a look at your %s" %cf
    print "and verify the value from option 'postconf' in section 'bin'."
    print