[Spambayes-checkins] spambayes/spambayes OptionsClass.py,1.25,1.26

Tony Meyer anadelonbrin at users.sourceforge.net
Sun Jan 16 23:20:25 CET 2005


Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10535/spambayes

Modified Files:
	OptionsClass.py 
Log Message:
Add a method to generate documentation for options that suits a HTML documentation
 file.

Add an optional flag add_comments to display().  If this is True (False by default)
 then the help string for the option is added in comments above the option.

Index: OptionsClass.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/OptionsClass.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** OptionsClass.py	2 Jun 2004 00:28:35 -0000	1.25
--- OptionsClass.py	16 Jan 2005 22:20:21 -0000	1.26
***************
*** 235,238 ****
--- 235,258 ----
          return strval
  
+     def as_documentation_string(self, section=None):
+         '''Summarise the option in a format suitable for unmodified
+         insertion in HTML documentation.'''
+         strval = ["<tr>"]
+         if section is not None:
+             strval.append("\t<td>[%s]</td>" % (section,))
+         strval.append("\t<td>%s</td>" % (self.name,))
+         strval.append("\t<td>%s</td>" % \
+                       ", ".join([str(s) for s in self.valid_input()]))
+         default = self.default()
+         if isinstance(default, types.TupleType):
+             default = ", ".join([str(s) for s in default])
+         else:
+             default = str(default)
+         strval.append("\t<td>%s</td>" % (default,))
+         strval.append("\t<td><strong>%s</strong>: %s</td>" \
+                       % (self.display_name(), self.doc()))
+         strval.append("</tr>\n")
+         return "\n".join(strval)
+ 
      def write_config(self, file):
          '''Output value in configuration file format.'''
***************
*** 697,702 ****
          return all
  
!     def display(self):
          '''Display options in a config file form.'''
          output = StringIO.StringIO()
          keys = self._options.keys()
--- 717,723 ----
          return all
  
!     def display(self, add_comments=False):
          '''Display options in a config file form.'''
+         import textwrap
          output = StringIO.StringIO()
          keys = self._options.keys()
***************
*** 711,719 ****
                  output.write("]\n")
                  currentSection = sect
              self._options[sect, opt].write_config(output)
          return output.getvalue()
  
!     def display_full(self, section=None, option=None):
!         '''Display options including all information.'''
          # Given that the Options class is no longer as nice looking
          # as it once was, this returns all the information, i.e.
--- 732,746 ----
                  output.write("]\n")
                  currentSection = sect
+             if add_comments:
+                 doc = self._options[sect, opt].doc()
+                 if not doc:
+                     doc = "No information available, sorry."
+                 doc = re.sub(r"\s+", " ", doc)
+                 output.write("\n# %s\n" % ("\n# ".join(textwrap.wrap(doc)),))
              self._options[sect, opt].write_config(output)
          return output.getvalue()
  
!     def _display_nice(self, section, option, formatter):
!         '''Display a nice output of the options'''
          # Given that the Options class is no longer as nice looking
          # as it once was, this returns all the information, i.e.
***************
*** 724,729 ****
          # is nothing more than a call to as_nice_string
          if section is not None and option is not None:
!             output.write(self._options[section,
!                                        option.lower()].as_nice_string(section))
              return output.getvalue()
  
--- 751,756 ----
          # is nothing more than a call to as_nice_string
          if section is not None and option is not None:
!             opt = self._options[section, option.lower()]
!             output.write(getattr(opt, formatter)(section))
              return output.getvalue()
  
***************
*** 733,739 ****
              if section is not None and sect != section:
                  continue
!             output.write(self._options[sect, opt.lower()].as_nice_string(sect))
          return output.getvalue()
  
  # These are handy references to commonly used regex/tuples defining
  # permitted values. Although the majority of options use one of these,
--- 760,776 ----
              if section is not None and sect != section:
                  continue
!             opt = self._options[sect, opt.lower()]
!             output.write(getattr(opt, formatter)(sect))
          return output.getvalue()
  
+     def display_full(self, section=None, option=None):
+         '''Display options including all information.'''
+         return self._display_nice(section, option, 'as_nice_string')
+         
+     def output_for_docs(self, section=None, option=None):
+         '''Return output suitable for inserting into documentation for
+         the available options.'''
+         return self._display_nice(section, option, 'as_documentation_string')
+ 
  # These are handy references to commonly used regex/tuples defining
  # permitted values. Although the majority of options use one of these,



More information about the Spambayes-checkins mailing list