view example.py @ 0:3081763b099b

initial commit of ConfigOptionParser
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 20 May 2010 08:47:35 -0700
parents
children
line wrap: on
line source

#!/usr/bin/env python

"""
Example script to illustrate ConfigOptionParser.
Run from the command line and give some arguments to see how this works.

Read values from .ini file:
 python example.py -c example.ini

Read values from .ini file but override the setting for the foo
 python example.py -c example.ini -f blah

Override/add variables from the command line:
 python example.py -c example.ini blah=bleem fargo=bah -f blah
"""

import sys
from configoptionparser import ConfigOptionParser

parser = ConfigOptionParser(dict_section='variables')
parser.add_option('-f', dest='foo')
parser.add_option('--baz', default='the baz default string')
parser.add_option('--fleem')
parser.add_option('--list', dest='list', action='append')
parser.add_option('--verbose', dest='verbose', action='store_true',
                  default=False)

def main(args=sys.argv[1:]):
  options, args = parser.parse_args(args)
  for key in sorted(options.__dict__):
    print '%s: %s' % (key, options.__dict__[key])
  print 'args: %s' % args

if __name__ == '__main__':
  main()