Mercurial > hg > configuration
changeset 61:ef2d1c6211b9
more stubbing to make Configuration an OptionParser
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 27 Mar 2012 17:04:31 -0700 |
parents | 4f5ea5a8ccb0 |
children | 81996be938bb |
files | configuration/config.py |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/configuration/config.py Tue Mar 27 16:58:48 2012 -0700 +++ b/configuration/config.py Tue Mar 27 17:04:31 2012 -0700 @@ -183,10 +183,28 @@ options = {} # configuration basis def __init__(self, configuration_providers=configuration_providers, types=types, **parser_args): + + # setup configuration self.config = {} self.configuration_providers = configuration_providers self.types = types + + # setup optionparser + if 'description' not in parser_args: + parser_args['description'] = getattr(self, '__doc__', '') + if 'formatter' not in parser_args: + class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): + """description formatter for console script entry point""" + def format_description(self, description): + if description: + return description.strip() + '\n' + else: + return '' + parser_args['formatter'] = PlainDescriptionFormatter() + parser_args.setdefault('option_class', ConfigurationOption) optparse.OptionParser.__init__(self, **parser_args) + self.parsed = set() + self.optparse_options(self) ### methods for iteration ### TODO: make this a real iterator