FileOptionParser and DefaultOption

Dirk Groeneveld <[email protected]> Mon, 25 Jul 2005 15:31:25 -0700 (PDT)
Newsgroups gmane.comp.python.optik.user
Message-ID <[email protected]>
Hi!

As part of a bigger project I wrote an OptionParser class that reads 
option defaults from a configuration file (in the ConfigFile way). The 
configuration file itself is another command line option. Normal defaults 
are still supported as before, so the order of precedence becomes 
defaults, configuration file (if given), command line options, from low to 
high.

I know about cfgparse, but the combination of optik/optparse and cfgparse 
still leaves a lot of work to the user that has to be done for every 
project, so I decided to not use it.

My question is if you would consider including this class into the 
mainstream optik distribution. In that case I'd create some more 
documentation and make a patch ... and replace tabs with spaces ;-)


As part of the same project I also wrote a class that automatically adds 
information about a default to an option to the help text of that option. 
For example,

parser.add_option("-t", "--timeout", type="float", dest="timeout", \
     metavar="TIMEOUT", default=0.5, help="timeout on the serial port")

comes out in the help text as

   -t TIMEOUT, --timeout=TIMEOUT
                         timeout on the serial port. Default is 0.5.

I could prepare that one too for inclusion into optik, if someone is 
interested. There is a small problem though. The class is overwriting 
Option's constructor, and it should really be a mixin class. I'm not sure 
there is a way to write constructor-altering mixin classes with old-style 
classes.

Take care,
Dirk


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click