#!/usr/bin/python

configfilepath = 'etc/zope.conf'

config=open(configfilepath).read()

import re

config_regex = re.compile('(^debug-mode (off|on))$', re.MULTILINE)

#print config_regex.findall(config)
whole, current_state = config_regex.findall(config)[0]
if current_state == 'off':
    new_state = 'on'
    print "debug-mode switched ON"
else:
    new_state = 'off'
    print "debug-mode switched OFF"
    
better = 'debug-mode %s'%new_state
config = config.replace(whole, better)

open(configfilepath,'w').write(config)
    