def edit_config(filename, settings, dry_run=False):
from setuptools.compat import ConfigParser<EOL>log.debug("<STR_LIT>", filename)<EOL>opts = ConfigParser.RawConfigParser()<EOL>opts.read([filename])<EOL>for section, options in settings.items():<EOL><INDENT>if options is None:<EOL><INDENT>log.info("<STR_LIT>", section, filename)<EOL>opts.remove_section(section)<EOL><DEDENT>else:<EOL><INDENT>if not opts.has_section(section):<EOL><INDENT>log.debug("<STR_LIT>", section, filename)<EOL>opts.add_section(section)<EOL><DEDENT>for option, value in options.items():<EOL><INDENT>if value is None:<EOL><INDENT>log.debug(<EOL>"<STR_LIT>",<EOL>section, option, filename<EOL>)<EOL>opts.remove_option(section, option)<EOL>if not opts.options(section):<EOL><INDENT>log.info("<STR_LIT>",<EOL>section, filename)<EOL>opts.remove_section(section)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>log.debug(<EOL>"<STR_LIT>",<EOL>section, option, value, filename<EOL>)<EOL>opts.set(section, option, value)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>log.info("<STR_LIT>", filename)<EOL>if not dry_run:<EOL><INDENT>with open(filename, '<STR_LIT:w>') as f:<EOL><INDENT>opts.write(f)<EOL><DEDENT><DEDENT>
Edit a configuration file to include `settings`

    `settings` is a dictionary of dictionaries or ``None`` values, keyed by
    command/section name.  A ``None`` value means to delete the entire section,
    while a dictionary lists settings to be changed or deleted in that section.
    A setting of ``None`` means to delete that setting.