[Zope3-checkins] CVS: Zope3/utilities - rst2html:1.1
Fred L. Drake, Jr.
fred at zope.com
Thu Aug 28 19:54:34 EDT 2003
Update of /cvs-repository/Zope3/utilities
In directory cvs.zope.org:/tmp/cvs-serv28909
Added Files:
rst2html
Log Message:
Driver script for formatting ReST documentation included with Zope
using the docutils provided with Zope. This sets up some default
behaviors and links in the right stylesheet.
=== Added File Zope3/utilities/rst2html ===
#! /usr/local/bin/python2.2
import errno
import os
import sys
try:
__file__
except NameError:
__file__ = sys.argv[0]
here = os.path.dirname(os.path.realpath(__file__))
top = os.path.dirname(here)
src = os.path.join(top, "src")
if src not in sys.path:
sys.path.insert(0, src)
cssfn = os.path.join(top, "doc", "style", "rest.css")
# Insert some arguments into the command line to define the default
# behavior:
sys.argv[1:1] = [
"--no-generator",
"--no-datestamp",
"--pep-references",
"--rfc-references",
"--link-stylesheet",
# Using --stylesheet-path causes docutils to create a relative
# link from the output file to the stylesheet; we don't have to
# figure it out ourselves.
"--stylesheet-path", cssfn,
]
from docutils.core import default_description, Publisher
class MyPublisher(Publisher):
__source = None
def set_source(self, source=None, source_path=None):
self.__source = source_path
Publisher.set_source(self, source, source_path)
def set_destination(self, destination=None, destination_path=None):
src = self.__source
if src is None:
if destination_path is None and self.settings._destination is None:
src = self.settings._source
if src:
dest = os.path.splitext(src)[0] + ".html"
Publisher.set_destination(self, None, dest)
else:
Publisher.set_destination(self, destination, destination_path)
if sys.stdout.isatty():
publisher = MyPublisher()
else:
publisher = Publisher()
publisher.set_components("standalone", "restructuredtext", "html")
try:
publisher.publish()
except IOError, e:
# This suppresses a traceback when shoving data into a pipe and it
# doesn't all get read; mostly helpful when piping directly into a
# pager like "more" or "less" and quiting before the pager reads
# everything.
if e.errno != errno.EPIPE:
raise
More information about the Zope3-Checkins
mailing list