Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
optparse.TitledHelpFormatter Class Reference
Inheritance diagram for optparse.TitledHelpFormatter:
Inheritance graph
[legend]
Collaboration diagram for optparse.TitledHelpFormatter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def format_usage
def format_heading
def set_parser
def set_short_opt_delimiter
def set_long_opt_delimiter
def indent
def dedent
def format_description
def format_epilog
def expand_default
def format_option
def store_option_strings
def format_option_strings

Public Attributes

 parser
 indent_increment
 help_position
 max_help_position
 width
 current_indent
 level
 help_width
 short_first
 default_tag
 option_strings

Static Public Attributes

string NO_DEFAULT_VALUE = "none"

Detailed Description

Format help with underlined section headers.

Definition at line 379 of file optparse.py.


Constructor & Destructor Documentation

def optparse.TitledHelpFormatter.__init__ (   self,
  indent_increment = 0,
  max_help_position = 24,
  width = None,
  short_first = 0 
)

Reimplemented from optparse.HelpFormatter.

Definition at line 387 of file optparse.py.

00387 
00388                  short_first=0):
00389         HelpFormatter.__init__ (
00390             self, indent_increment, max_help_position, width, short_first)

Here is the caller graph for this function:


Member Function Documentation

def optparse.HelpFormatter.dedent (   self) [inherited]

Definition at line 242 of file optparse.py.

00242 
00243     def dedent(self):
00244         self.current_indent -= self.indent_increment
00245         assert self.current_indent >= 0, "Indent decreased below 0."
00246         self.level -= 1

Here is the caller graph for this function:

def optparse.HelpFormatter.expand_default (   self,
  option 
) [inherited]

Definition at line 278 of file optparse.py.

00278 
00279     def expand_default(self, option):
00280         if self.parser is None or not self.default_tag:
00281             return option.help
00282 
00283         default_value = self.parser.defaults.get(option.dest)
00284         if default_value is NO_DEFAULT or default_value is None:
00285             default_value = self.NO_DEFAULT_VALUE
00286 
00287         return option.help.replace(self.default_tag, str(default_value))

Here is the caller graph for this function:

def optparse.HelpFormatter.format_description (   self,
  description 
) [inherited]

Definition at line 265 of file optparse.py.

00265 
00266     def format_description(self, description):
00267         if description:
00268             return self._format_text(description) + "\n"
00269         else:
00270             return ""

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.HelpFormatter.format_epilog (   self,
  epilog 
) [inherited]

Definition at line 271 of file optparse.py.

00271 
00272     def format_epilog(self, epilog):
00273         if epilog:
00274             return "\n" + self._format_text(epilog) + "\n"
00275         else:
00276             return ""
00277 

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.TitledHelpFormatter.format_heading (   self,
  heading 
)

Reimplemented from optparse.HelpFormatter.

Definition at line 394 of file optparse.py.

00394 
00395     def format_heading(self, heading):
00396         return "%s\n%s\n" % (heading, "=-"[self.level] * len(heading))
00397 

def optparse.HelpFormatter.format_option (   self,
  option 
) [inherited]

Definition at line 288 of file optparse.py.

00288 
00289     def format_option(self, option):
00290         # The help for each option consists of two parts:
00291         #   * the opt strings and metavars
00292         #     eg. ("-x", or "-fFILENAME, --file=FILENAME")
00293         #   * the user-supplied help string
00294         #     eg. ("turn on expert mode", "read data from FILENAME")
00295         #
00296         # If possible, we write both of these on the same line:
00297         #   -x      turn on expert mode
00298         #
00299         # But if the opt string list is too long, we put the help
00300         # string on a second line, indented to the same column it would
00301         # start in if it fit on the first line.
00302         #   -fFILENAME, --file=FILENAME
00303         #           read data from FILENAME
00304         result = []
00305         opts = self.option_strings[option]
00306         opt_width = self.help_position - self.current_indent - 2
00307         if len(opts) > opt_width:
00308             opts = "%*s%s\n" % (self.current_indent, "", opts)
00309             indent_first = self.help_position
00310         else:                       # start help on same line as opts
00311             opts = "%*s%-*s  " % (self.current_indent, "", opt_width, opts)
00312             indent_first = 0
00313         result.append(opts)
00314         if option.help:
00315             help_text = self.expand_default(option)
00316             help_lines = textwrap.wrap(help_text, self.help_width)
00317             result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
00318             result.extend(["%*s%s\n" % (self.help_position, "", line)
00319                            for line in help_lines[1:]])
00320         elif opts[-1] != "\n":
00321             result.append("\n")
00322         return "".join(result)

Here is the call graph for this function:

def optparse.HelpFormatter.format_option_strings (   self,
  option 
) [inherited]
Return a comma-separated list of option strings & metavariables.

Definition at line 341 of file optparse.py.

00341 
00342     def format_option_strings(self, option):
00343         """Return a comma-separated list of option strings & metavariables."""
00344         if option.takes_value():
00345             metavar = option.metavar or option.dest.upper()
00346             short_opts = [self._short_opt_fmt % (sopt, metavar)
00347                           for sopt in option._short_opts]
00348             long_opts = [self._long_opt_fmt % (lopt, metavar)
00349                          for lopt in option._long_opts]
00350         else:
00351             short_opts = option._short_opts
00352             long_opts = option._long_opts
00353 
00354         if self.short_first:
00355             opts = short_opts + long_opts
00356         else:
00357             opts = long_opts + short_opts
00358 
00359         return ", ".join(opts)

Here is the caller graph for this function:

def optparse.TitledHelpFormatter.format_usage (   self,
  usage 
)

Reimplemented from optparse.HelpFormatter.

Definition at line 391 of file optparse.py.

00391 
00392     def format_usage(self, usage):
00393         return "%s  %s\n" % (self.format_heading(_("Usage")), usage)

Here is the call graph for this function:

def optparse.HelpFormatter.indent (   self) [inherited]

Definition at line 238 of file optparse.py.

00238 
00239     def indent(self):
00240         self.current_indent += self.indent_increment
00241         self.level += 1

Here is the caller graph for this function:

def optparse.HelpFormatter.set_long_opt_delimiter (   self,
  delim 
) [inherited]

Definition at line 232 of file optparse.py.

00232 
00233     def set_long_opt_delimiter(self, delim):
00234         if delim not in ("=", " "):
00235             raise ValueError(
00236                 "invalid metavar delimiter for long options: %r" % delim)
00237         self._long_opt_fmt = "%s" + delim + "%s"

def optparse.HelpFormatter.set_parser (   self,
  parser 
) [inherited]

Definition at line 223 of file optparse.py.

00223 
00224     def set_parser(self, parser):
00225         self.parser = parser

def optparse.HelpFormatter.set_short_opt_delimiter (   self,
  delim 
) [inherited]

Definition at line 226 of file optparse.py.

00226 
00227     def set_short_opt_delimiter(self, delim):
00228         if delim not in ("", " "):
00229             raise ValueError(
00230                 "invalid metavar delimiter for short options: %r" % delim)
00231         self._short_opt_fmt = "%s" + delim + "%s"

def optparse.HelpFormatter.store_option_strings (   self,
  parser 
) [inherited]

Definition at line 323 of file optparse.py.

00323 
00324     def store_option_strings(self, parser):
00325         self.indent()
00326         max_len = 0
00327         for opt in parser.option_list:
00328             strings = self.format_option_strings(opt)
00329             self.option_strings[opt] = strings
00330             max_len = max(max_len, len(strings) + self.current_indent)
00331         self.indent()
00332         for group in parser.option_groups:
00333             for opt in group.option_list:
00334                 strings = self.format_option_strings(opt)
00335                 self.option_strings[opt] = strings
00336                 max_len = max(max_len, len(strings) + self.current_indent)
00337         self.dedent()
00338         self.dedent()
00339         self.help_position = min(max_len + 2, self.max_help_position)
00340         self.help_width = self.width - self.help_position

Here is the call graph for this function:


Member Data Documentation

Definition at line 214 of file optparse.py.

Definition at line 218 of file optparse.py.

Definition at line 206 of file optparse.py.

Definition at line 216 of file optparse.py.

Definition at line 205 of file optparse.py.

Definition at line 215 of file optparse.py.

Definition at line 206 of file optparse.py.

string optparse.HelpFormatter.NO_DEFAULT_VALUE = "none" [static, inherited]

Definition at line 197 of file optparse.py.

Definition at line 219 of file optparse.py.

Definition at line 204 of file optparse.py.

Definition at line 217 of file optparse.py.

Definition at line 213 of file optparse.py.


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