OpenQuizz
Une application de gestion des contenus pédagogiques
FancyGetopt Class Reference

Public Member Functions

def __init__ (self, option_table=None)
 
def set_option_table (self, option_table)
 
def add_option (self, long_option, short_option=None, help_string=None)
 
def has_option (self, long_option)
 
def get_attr_name (self, long_option)
 
def set_aliases (self, alias)
 
def set_negative_aliases (self, negative_alias)
 
def getopt (self, args=None, object=None)
 
def get_option_order (self)
 
def generate_help (self, header=None)
 
def print_help (self, header=None, file=None)
 

Data Fields

 option_table
 
 option_index
 
 alias
 
 negative_alias
 
 short_opts
 
 long_opts
 
 short2long
 
 attr_name
 
 takes_arg
 
 option_order
 
 repeat
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  option_table = None 
)

Member Function Documentation

◆ add_option()

def add_option (   self,
  long_option,
  short_option = None,
  help_string = None 
)

◆ generate_help()

def 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.

◆ get_attr_name()

def 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.

◆ get_option_order()

def 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.

◆ getopt()

def 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.

◆ has_option()

def has_option (   self,
  long_option 
)
Return true if the option table for this parser has an
option with long name 'long_option'.

◆ print_help()

def print_help (   self,
  header = None,
  file = None 
)

◆ set_aliases()

def set_aliases (   self,
  alias 
)
Set the aliases for this option parser.

◆ set_negative_aliases()

def 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.

◆ set_option_table()

def set_option_table (   self,
  option_table 
)

Field Documentation

◆ alias

alias

◆ attr_name

attr_name

◆ long_opts

long_opts

◆ negative_alias

negative_alias

◆ option_index

option_index

◆ option_order

option_order

◆ option_table

option_table

◆ repeat

repeat

◆ short2long

short2long

◆ short_opts

short_opts

◆ takes_arg

takes_arg

The documentation for this class was generated from the following file: