views:

102

answers:

1

I'm trying to set an option (xdebug.profiler_enable) in my php.ini file using python's ConfigParser object. here is the code: section in php.ini file im trying to modify

[xdebug]
;XDEBUG SETTINGS
;turn on the profiler?
xdebug.profiler_enable=0
xdebug.profiler_append=1    
xdebug.profiler_enable_trigger=0
xdebug.trace_output_name="%R"
xdebug.profiler_output_dir="/home/made_up_user/www/cachegrind/"

Python

import sys
import ConfigParser

if __name__ == '__main__':            
    phpIniLocation = "/home/made_up_user/Desktop/phpinicopy.ini";
    phpIni = ConfigParser.RawConfigParser();
    phpIni.read(phpIniLocation);

    xdebugSetting = phpIni.getboolean("xdebug", "xdebug.profiler_enable");

    if xdebugSetting:
        phpIni.set("xdebug", "xdebug.profiler_enable", "0");                   

    else:
        phpIni.set("xdebug", "xdebug.profiler_enable", "1");

Environment: Ubuntu 9.04,python 2.6 Everything SEEMS to be working fine. The xdebugSetting variable returns the option's boolean value correctly, I can parse through the section and retrieve each of the options correct values, and the set method doesn't throw any exceptions, but when i check the file, the options have not been changed. I have used RawConfigParser, ConfigParser, and SafeConfigParser all with the same result. The script runs with roots permissions. Is there something I'm missing? How do I get the set method to work?

+1  A: 
phpIni.write(open(phpIniLocation, 'w'))

docs.

nosklo
thank you, i should have read the documentation more thoroughly.
@unknown (google): If this is the right answer, do not say "thanks" (although, that's a nice thing to do). Click the green "accept this answer" check-mark (that's even nicer.)
S.Lott