[Python-checkins] python/nondist/sandbox/setuptools/setuptools/command setopt.py, 1.2, 1.3

pje@users.sourceforge.net pje at users.sourceforge.net
Fri Jul 8 17:50:34 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23000/setuptools/command

Modified Files:
	setopt.py 
Log Message:
Delete empty sections when their last option is deleted.


Index: setopt.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/setopt.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- setopt.py	8 Jul 2005 05:09:23 -0000	1.2
+++ setopt.py	8 Jul 2005 15:50:32 -0000	1.3
@@ -51,10 +51,9 @@
     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 @@
                         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 @@
 
     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"""



More information about the Python-checkins mailing list