|
From: Michael F. <fuz...@vo...> - 2008-02-22 11:53:23
|
Brian Jones wrote: > Ok, so I took a quick break from reading the March stuff to look this > over. I haven't read the *entire* thing, but I have a question about > ConfigObj, and I hope I've read enough of the article that it's not > too dumb a question :) > It's definitely not a dumb question. What you are saying is that the presence of: x Implies 'x = True' This is fine - except it means changing the parser (which can be fiddly), making it an option, making it an option to specify how 'x = True' should be written back out (maybe both those could be a single option) and so on. For config files *created* by ConfigObj I wouldn't want it to be the default but I am happy for ConfigObj to be compatible with a wider range of files created by other applications. I'm afraid I have another rather pressing writing task at the moment - so I'm afraid the default response is 'patches welcomed'. I'm forwarding this to the ConfigObj mailing list in case anyone else has an interest in implementing this... Michael http://www.manning.com/foord > Given the very simple interface, and some of the complex things that > ConfigObj does, I'm wondering how hard it would be to add support for > "toggles" in a config file. In other words, single values on a line by > themselves in a config file that, by their presence, signal the > application to do (or not do) something specific. > > As an example, I actually needed this feature to write a mysql backup > script that would parse the system's my.cnf file instead of having to > edit a bunch of vars at the top of the script before use. However, the > config file contains "toggle" config variables: if they exist in the > file at all, they are basically read in by MySQL as "true", and it > does what it needs to do. Here's a bit of the my.cnf file in question: > > [mysqld] > server-id=2 > log-bin=mysql-binlog > log-slave-updates > relay-log=db2-relay-bin > datadir=/var/lib/mysql > tmpdir=/var/lib/mysql > socket=/var/lib/mysql/mysql.sock > enable-locking > max_allowed_packet = 4M > skip-name-resolve > skip-host-cache > skip-innodb > back_log=128 > connect_timeout=10 > ft_min_word_len=3 > key_buffer_size=512M > max_allowed_packet=1024M > max_connections=200 > max_connect_errors=100 > myisam_sort_buffer_size=512M > > There's a lot of information implied by some of those floating, lonely > values (and there are more that are available for use as well). If my > application, for example, could do something like this: > > if not 'skip-innodb' in mysqlcnf: > do_innodb_backup() > > or, better: > > if not mysqlcnf['skip-innodb'] > do_innodb_backup() > > So, I guess the short question is: can't ConfigObj just store these > "toggle" values in a dictionary along with everything else, but since > it doesn't have a value, just store the toggle value as the key, and > the boolean True as the value? > > If this is all very neophyte-level banter, please forgive my > ignorance. I don't profess to be a Python guru. That's why I created > PyMag and hired tech editors :-P - but I do like Python, and would > love to use ConfigObj for this particular project :-D > > Thanks for your work on this, and for working with us at PyMag! > brian. > > > > > On Thu, Feb 21, 2008 at 8:28 PM, Doug Hellmann <dou...@gm...> wrote: > >> Thanks, Michael, >> >> We're catching our breath from working on the March issue right now, >> but one of us will be looking at this shortly and will get back to you. >> >> Doug >> >> On Feb 21, 2008, at 3:34 PM, Michael Foord wrote: >> >> > Hello guys, >> > >> > Attached is the first draft of my ConfigObj article. I have ignored >> > formatting issues so far... >> > > |