Package distutils :: Module fancy_getopt :: Class FancyGetopt
[hide private]
[frames] | no frames]

_ClassType FancyGetopt

Wrapper around the standard 'getopt()' module that provides some
handy extra functionality:
  * short and long options are tied together
  * options have help strings, and help text can be assembled
    from them
  * options set attributes of a passed-in object
  * boolean options can have "negative aliases" -- eg. if
    --quiet is the "negative alias" of --verbose, then "--quiet"
    on the command line sets 'verbose' to false

Instance Methods [hide private]
 
__init__(self, option_table=None)
 
_build_index(self)
 
set_option_table(self, option_table)
 
add_option(self, long_option, short_option=None, help_string=None)
 
has_option(self, long_option)
Return true if the option table for this parser has an option with long name 'long_option'.
 
get_attr_name(self, long_option)
Translate long option name 'long_option' to the form it has as an attribute of some object: ie., translate hyphens to underscores.
 
_check_alias_dict(self, aliases, what)
 
set_aliases(self, alias)
Set the aliases for this option parser.
 
set_negative_aliases(self, negative_alias)
Set the negative aliases for this option parser.
 
_grok_option_table(self)
Populate the various data structures that keep tabs on the option table.
 
getopt(self, args=None, object=None)
Parse command-line options in args.
 
get_option_order(self)
Returns the list of (option, value) tuples processed by the previous run of 'getopt()'.
 
generate_help(self, header=None)
Generate help text (a list of strings, one per suggested line of output) from the option table for this FancyGetopt object.
 
print_help(self, header=None, file=None)
Method Details [hide private]

set_negative_aliases(self, negative_alias)

 

Set the negative aliases for this option parser. 'negative_alias' should be a dictionary mapping option names to option names, both the key and value must already be defined in the option table.

_grok_option_table(self)

 

Populate the various data structures that keep tabs on the option table. Called by 'getopt()' before it can do anything worthwhile.

getopt(self, args=None, object=None)

 

Parse command-line options in args. Store as attributes on object.

If 'args' is None or not supplied, uses 'sys.argv[1:]'. If 'object' is None or not supplied, creates a new OptionDummy object, stores option values there, and returns a tuple (args, object). If 'object' is supplied, it is modified in place and 'getopt()' just returns 'args'; in both cases, the returned 'args' is a modified copy of the passed-in 'args' list, which is left untouched.

get_option_order(self)

 

Returns the list of (option, value) tuples processed by the previous run of 'getopt()'. Raises RuntimeError if 'getopt()' hasn't been called yet.