[Python-Dev] ConfigParser to save with order (original) (raw)
Tony Meyer t-meyer at ihug.co.nz
Fri Jan 20 12:19:54 CET 2006
- Previous message: [Python-Dev] ConfigParser to save with order
- Next message: [Python-Dev] ConfigParser to save with order
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Tony Meyer]
Allowing 'surgical' editing of configuration files, as has been proposed many times both here and c.l.p would not require ConfigParser to be entirely rewritten (just more extensive modification of the write() method).
After writing the summary of this thread, I figured I might as well
prove this by submitting a patch, so did so:
[ 1410680 ] Add 'surgical editing' to ConfigParser <http://python.org/sf/1410680>
So there are now at least three open ConfigParser patches, all
addressing similar things, although not in the same way, and all
three could actually be applied.
My patch (which includes new unittests and a marked-up doc patch)
runs through a file and updates it to match the in-memory
configuration object. Comments, blank lines, and order are
preserved. By default (this can be turned off with a keyword arg)
new sections/options are added to the file as well (new options in
existing sections are added at the end of the last instance of that
section, new sections are added at the end of the file). These new
options are added in alphabetical (well, list.sort()) order, so
ordering is consistent, and if an empty file is 'updated' one ends up
with the output of write() but sorted.
This is essentially a tidied-up version of the SpamBayes code I wrote
a few years back.
If anyone is still interested in adding this, feel free to take a
look at the tracker :)
=Tony.Meyer
- Previous message: [Python-Dev] ConfigParser to save with order
- Next message: [Python-Dev] ConfigParser to save with order
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]