Back to index

python-cliapp  1.20120630
Public Member Functions | Public Attributes
cliapp.genman.ManpageGenerator Class Reference

List of all members.

Public Member Functions

def __init__
def options
def format_template
def format_synopsis
def format_option_for_synopsis
def format_options
def format_option_for_options
def expand_default
def esc_dashes
def esc_dots
def format_argspec

Public Attributes

 template
 parser
 arg_synopsis
 cmd_synopsis

Detailed Description

Fill in a manual page template from an OptionParser instance.

Definition at line 22 of file genman.py.


Constructor & Destructor Documentation

def cliapp.genman.ManpageGenerator.__init__ (   self,
  template,
  parser,
  arg_synopsis,
  cmd_synopsis 
)

Definition at line 26 of file genman.py.

00026 
00027     def __init__(self, template, parser, arg_synopsis, cmd_synopsis):
00028         self.template = template
00029         self.parser = parser
00030         self.arg_synopsis = arg_synopsis
00031         self.cmd_synopsis = cmd_synopsis
        

Member Function Documentation

def cliapp.genman.ManpageGenerator.esc_dashes (   self,
  optname 
)

Definition at line 103 of file genman.py.

00103 
00104     def esc_dashes(self, optname):
00105         return '\\-'.join(optname.split('-'))
    

Here is the caller graph for this function:

def cliapp.genman.ManpageGenerator.esc_dots (   self,
  line 
)

Definition at line 106 of file genman.py.

00106 
00107     def esc_dots(self, line):
00108         if line.startswith('.'):
00109             return '\\' + line
00110         else:
00111             return line
            

Here is the caller graph for this function:

def cliapp.genman.ManpageGenerator.expand_default (   self,
  option 
)

Definition at line 95 of file genman.py.

00095 
00096     def expand_default(self, option):
00097         default = self.parser.defaults.get(option.dest)
00098         if default is optparse.NO_DEFAULT or default is None:
00099             default = 'none'
00100         else:
00101             default = str(default)
00102         return option.help.replace('%default', default)
        

Here is the caller graph for this function:

def cliapp.genman.ManpageGenerator.format_argspec (   self,
  argspec 
)

Definition at line 112 of file genman.py.

00112 
00113     def format_argspec(self, argspec):
00114         roman = re.compile(r'[^A-Z]+')
00115         italic = re.compile(r'[A-Z]+')
00116         words = ['.RI']
00117         while argspec:
00118             m = roman.match(argspec)
00119             if m:
00120                 words += [self.esc_dashes(m.group(0))]
00121                 argspec = argspec[m.end():]
00122             else:
00123                 words += ['""']
00124             m = italic.match(argspec)
00125             if m:
00126                 words += [self.esc_dashes(m.group(0))]
00127                 argspec = argspec[m.end():]
00128             else:
00129                 words += ['""']
00130         return [' '.join(words)]
00131 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 81 of file genman.py.

00081 
00082     def format_option_for_options(self, option):
00083         lines = []
00084         lines += ['.TP']
00085         shorts = [self.esc_dashes(x) for x in option._short_opts]
00086         if option.metavar:
00087             longs = ['%s =\\fI%s' % (self.esc_dashes(x), option.metavar)
00088                      for x in option._long_opts]
00089         else:
00090             longs = ['%s' % self.esc_dashes(x)
00091                      for x in option._long_opts]
00092         lines += ['.BR ' + ' ", " '.join(shorts + longs)]
00093         lines += [self.esc_dots(self.expand_default(option).strip())]
00094         return ''.join('%s\n' % line for line in lines)
        

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 69 of file genman.py.

00069 
00070     def format_option_for_synopsis(self, option):
00071         if option.metavar:
00072             suffix = '\\fR=\\fI%s' % self.esc_dashes(option.metavar)
00073         else:
00074             suffix = ''
00075         for name in option._short_opts + option._long_opts:
00076             yield '%s%s' % (self.esc_dashes(name), suffix)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 77 of file genman.py.

00077 
00078     def format_options(self):
00079         return ''.join(self.format_option_for_options(option)
00080                        for option in self.options)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 46 of file genman.py.

00046 
00047     def format_synopsis(self):
00048         lines = []
00049         lines += ['.nh']
00050         lines += ['.B %s' % self.esc_dashes(self.parser.prog)]
00051         
00052         for option in self.options:
00053             for spec in self.format_option_for_synopsis(option):
00054                 lines += ['.RB [ %s ]' % spec]
00055 
00056         if self.cmd_synopsis:
00057             lines += ['.PP']
00058             for cmd in sorted(self.cmd_synopsis):
00059                 lines += ['.br',
00060                           '.B %s' % self.esc_dashes(self.parser.prog),
00061                           '.RI [ options ]',
00062                           self.esc_dashes(cmd)]
00063                 lines += self.format_argspec(self.cmd_synopsis[cmd])
00064         elif self.arg_synopsis:
00065             lines += self.format_argspec(self.arg_synopsis)
00066 
00067         lines += ['.hy']
00068         return ''.join('%s\n' % line for line in lines)
                      

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 37 of file genman.py.

00037 
00038     def format_template(self):
00039         sections = (('SYNOPSIS', self.format_synopsis()),
00040                     ('OPTIONS', self.format_options()))
00041         text = self.template
00042         for section, contents in sections:
00043             pattern = '\n.SH %s\n' % section
00044             text = text.replace(pattern, pattern + contents)
00045         return text
                      

Here is the call graph for this function:

Definition at line 33 of file genman.py.

00033 
00034     def options(self):
00035         return sorted(self.parser.option_list,
00036                       key=lambda o: (o._long_opts + o._short_opts)[0])
                      

Here is the caller graph for this function:


Member Data Documentation

Definition at line 29 of file genman.py.

Definition at line 30 of file genman.py.

Definition at line 28 of file genman.py.

Definition at line 27 of file genman.py.


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