[Zconfig] Write support

Nicola Larosa nico at teknico.net
Mon Dec 6 14:16:56 EST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>>> I've got the million dollar question: how should I go implementing write 
>>> support in ZConfig? Tried to look at the code, but it's a bit long to
>>> follow.  

>> No idea :)

> I think it probably has something to do with reading and writing some
> Python. ;-)

I suspected something of the kind. ;-)


> But maybe Fred can give an idea about how he'd think about going about it.

I'd sure like an opinion about this stuff (see below).


>> I'm currently mangling the file using string expressions. I chatted to 
>> Chris M who had some idea about it. I was suggesting just throwing 
>> ZConfig out and replacing it with XML that is read in by Zope for a 
>> billion reasons ;)

> ZConfig isn't a file format, FWIW.
> 
> The file format itself doesn't have much to do with the actual purpose
> of ZConfig.  It would be easy to replace the Apache parser in ZConfig
> with an XML parser, and have an XML config file.  That could probably be
> done in a day and ZConfig could still be used to read the file.

In fact, cfgparser.py is a minor part of ZConfig.


> But it still wouldn't solve the problem of needing to know if a value
> for an element given in the config file is valid.  ZConfig's main job in
> life is to allow you to describe and extend a schema for a configuration
> and to enforce the schema at config file parsing time, stopping with a
> sensible error message if a value in the config makes no sense according
> to the schema.

Exactly, with an emphasis on the "extend" part that pushes the code towards a 
rather elaborate structure. :-)


>> Chris M was trying to get me back on the ZConfig kool aid :)

> FWIW, I think adding write support to ZConfig would be better than
> starting from scratch with a new schema system.

I agree, and here I am. :-)


>>> When all fails, I could just loop on sections in a config object and write 
>>> something ad hoc "from the outside", but maybe there's a better, and not
>>> too long way?

>> I'm not even going to commit to anything, but I need to solve the same 
>> thing as well and would like to move beyond the hacks we have.

> I can't commit either but I express noodling interest in same.

Well, drink the kool aid I did. :-) It took the better part of an afternoon to 
go through the maze of classes in ZConfig, but I managed to understand enough 
of it to put together a first attempt at the problem (attached). It doesn't 
handle neither defines nor components, and certainly doesn't undo 
substitutions, :-) but at least writes back a three-level config with 
multikeys and multisections, and the output file has the same contents of the 
input one, including indentation.

In other words, it Works For Me. I hope you find it useful, and also hope to 
get some comments about how to go improving it.

- -- 
Nicola Larosa - nico at tekNico.net

After a long life, and thirty years in the public school trenches,
I've concluded that genius is as common as dirt. We suppress our genius
only because we haven't yet figured out how to manage a population of
educated men and women. The solution, I think, is simple and glorious.
Let them manage themselves. -- John Taylor Gatto, 2001

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFBtLAtXv0hgDImBm4RAqa0AKCaMx3CkUnODMYCzb/fwPuo+3MyKQCfUQWw
ikG5ZcfFBAFaUhDgsyljuDg=
=wpip
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cfgwriter-0.1.tar.gz
Type: application/x-tgz
Size: 1366 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zconfig/attachments/20041206/004502f6/cfgwriter-0.1.tar.bin


More information about the ZConfig mailing list