On 07.09.06, Dag Wieers wrote:
On Wed, 6 Sep 2006, Joerg Lehmann wrote:
On 06.09.06, Alexander Wirt wrote:
Maybe it would be good to allow a include, like /etc/pytone/pytonerc and /etc/pytone/pytonerc.local, so that users can add their changes to the local file and distributions can just overwrite the global config. This works good for packages like bind in Debian.
This is the obvious thing to do, but the problem is that the Python ConfigParser module upon which the whole PyTone config code is based doesn't allow you to do that. So PyTone would need to provide its own parser.
Even though I don't think it is a solution because one needs to be able to install from subversion without overwriting the main configuration-file. I see the use to having multiple config-files about different things (like one for the layout, one for the sound device, etc...)
Fair enough.
ConfigParser is in fact able to parse multiple files and I'm doing that with Yam. You can find the implementation here:
http://svn.rpmforge.net/svn/trunk/tools/yam/yam
I do something like:
cf = Config() if cf.confdir and os.path.isdir(cf.confdir): files = glob.glob(os.path.join(cf.confdir, '*.conf')) files.sort() for configfile in files: cf.read(configfile) cf.update(configfile
That's about the same I do in PyTone, namely for the pytonerc in /etc and the one in ~./pytone or alternatively for the latter, the one provided as option to the -c command line switch.
To read out and update my configuration using multiple config-files. Of course the default config-file must be taken from somewhere and I allow to do -c config-file and that one is used by the Config class.
It is not the best way and there are some corner cases like you cannot have includes inside included files and the order (sorted) of the configuration-files is important. But Yam prints out the final configuration if you enable a certain verbosity and that should help debugging complex cases. The default configuration files are fairly simple though.
I think Alex was exactly speaking about includes, which, as you said, are not supported by the ConfigParser module.
Jörg