# HG changeset patch # User Jeff Hammel # Date 1332788689 25200 # Node ID a78ab14ae376aacc6e1dbb094d590c8216f5f8f6 # Parent b7e7f450ad1a08a146733e5a4e28ef5364072b6a separate thing to add options to its own function diff -r b7e7f450ad1a -r a78ab14ae376 configuration/config.py --- a/configuration/config.py Mon Mar 26 11:10:30 2012 -0700 +++ b/configuration/config.py Mon Mar 26 12:04:49 2012 -0700 @@ -72,26 +72,8 @@ self.config.update(config) # TODO: option to extend; augment lists/dicts - def parser(self, configuration_provider_option=None, **parser_args): - """ - return OptionParser for this Configuration instance - - configuration_provider_options : option for configuration files [TODO] - (also TODO: a special value that equates to the first file extension value - for the configuration_providers) - - parser_args : arguments to the OptionParser constructor - """ - 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 = optparse.OptionParser(**parser_args) + def optparse_options(self, parser): + """add optparse options to a OptionParser instance""" for key, value in self.items(): # TODO: move adding options to a separate function @@ -113,6 +95,28 @@ kw['help'] = help kw['action'] = 'store' # TODO: types parser.add_option(*args, **kw) + + def parser(self, configuration_provider_option=None, **parser_args): + """ + return OptionParser for this Configuration instance + - configuration_provider_options : option for configuration files [TODO] + (also TODO: a special value that equates to the first file extension value + for the configuration_providers) + - parser_args : arguments to the OptionParser constructor + """ + 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 = optparse.OptionParser(**parser_args) + self.optparse_options(parser) return parser def main(args=sys.argv[:]):