# HG changeset patch # User Jeff Hammel # Date 1332873189 25200 # Node ID b3db38b145671df1fc3bf2b6d0b3270e2e06d3d5 # Parent f09982d47b3c9b312f3b07a00e08ce49c5cf3d35 stub adding an option of keeping track of what is parsed diff -r f09982d47b3c -r b3db38b14567 configuration/config.py --- a/configuration/config.py Tue Mar 27 11:19:33 2012 -0700 +++ b/configuration/config.py Tue Mar 27 11:33:09 2012 -0700 @@ -22,7 +22,7 @@ except ImportError: yaml = None -__all__ = ['Configuration', 'configuration_providers', 'types', 'MissingValueException'] +__all__ = ['Configuration', 'configuration_providers', 'types', 'MissingValueException', 'ConfigurationProviderException', 'ConfigurationOption'] ### exceptions @@ -87,6 +87,18 @@ __all__.extend([i.__class__.__name__ for i in configuration_providers]) +### optparse interface + +class ConfigurationOption(optparse.Option): + """option that keeps track if it is seen""" + # TODO: this should be configurable or something + def take_action(self, action, dest, opt, value, values, parser): + """add the parsed option to the set of things parsed""" + optparse.Option.take_action(self, action, dest, opt, value, values, parser) + if not hasattr(parser, 'parsed'): + parser.parsed = set() + parser.parsed.add(dest) + ### plugins for option types ### TODO: this could use a bit of thought ### They should probably be classes @@ -257,6 +269,7 @@ - dump : option for dumping configuration - 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: