From d798d6943f81d938581c37b431b141b013678021 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 8 Jul 2005 15:50:32 +0000 Subject: Delete empty sections when their last option is deleted. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041099 --- setuptools/command/setopt.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'setuptools/command/setopt.py') diff --git a/setuptools/command/setopt.py b/setuptools/command/setopt.py index 3af0753f..dbf3a94e 100755 --- a/setuptools/command/setopt.py +++ b/setuptools/command/setopt.py @@ -51,10 +51,9 @@ def edit_config(filename, settings, dry_run=False): log.debug("Reading configuration from %s", filename) opts = RawConfigParser() opts.read([filename]) - for section, options in settings.items(): if options is None: - log.debug("Deleting section [%s] from %s", section, filename) + log.info("Deleting section [%s] from %s", section, filename) opts.remove_section(section) else: if not opts.has_section(section): @@ -66,6 +65,10 @@ def edit_config(filename, settings, dry_run=False): section, option, filename ) opts.remove_option(section,option) + if not opts.options(section): + log.info("Deleting empty [%s] section from %s", + section, filename) + opts.remove_section(section) else: log.debug( "Setting %s.%s to %r in %s", @@ -75,10 +78,7 @@ def edit_config(filename, settings, dry_run=False): log.info("Writing %s", filename) if not dry_run: - f = open(filename,'w') - opts.write(f) - f.close() - + f = open(filename,'w'); opts.write(f); f.close() class option_base(Command): """Abstract base class for commands that mess with config files""" -- cgit v1.2.3