From 101671ae44e1686680c80cd07b452aabeb88fb63 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 20 Apr 2002 03:01:52 +0000 Subject: Initial revision git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@18 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/html.py | 31 +++++++ tools/publish.py | 27 ++++++ tools/quicktest.py | 185 ++++++++++++++++++++++++++++++++++++++++++ tools/stylesheets/default.css | 157 +++++++++++++++++++++++++++++++++++ 4 files changed, 400 insertions(+) create mode 100755 tools/html.py create mode 100755 tools/publish.py create mode 100755 tools/quicktest.py create mode 100644 tools/stylesheets/default.css (limited to 'tools') diff --git a/tools/html.py b/tools/html.py new file mode 100755 index 000000000..66f029364 --- /dev/null +++ b/tools/html.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +""" +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +A minimal front-end to the Docutils Publisher. + +This module takes advantage of the default values defined in `publish()`. +""" + +import sys +from docutils.core import publish +from docutils import utils + +reporter = utils.Reporter(2, 4) +#reporter.setconditions('nodes.Node.walkabout', 2, 4, debug=1) + +if len(sys.argv) == 2: + publish(writername='html', source=sys.argv[1], reporter=reporter) +elif len(sys.argv) == 3: + publish(writername='html', source=sys.argv[1], destination=sys.argv[2], + reporter=reporter) +elif len(sys.argv) > 3: + print >>sys.stderr, 'Maximum 2 arguments allowed.' + sys.exit(1) +else: + publish() diff --git a/tools/publish.py b/tools/publish.py new file mode 100755 index 000000000..539548911 --- /dev/null +++ b/tools/publish.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +""" +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +A minimal front-end to the Docutils Publisher. + +This module takes advantage of the default values defined in `publish()`. +""" + +import sys +from docutils.core import publish + + +if len(sys.argv) == 2: + publish(source=sys.argv[1]) +elif len(sys.argv) == 3: + publish(source=sys.argv[1], destination=sys.argv[2]) +elif len(sys.argv) > 3: + print >>sys.stderr, 'Maximum 2 arguments allowed.' + sys.exit(1) +else: + publish() diff --git a/tools/quicktest.py b/tools/quicktest.py new file mode 100755 index 000000000..df295f66a --- /dev/null +++ b/tools/quicktest.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python + +""" +:Author: Garth Kidd +:Contact: garth@deadlybloodyserious.com +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. +""" + +import sys, os, getopt +import docutils.utils +from docutils.parsers.rst import Parser + + +usage_header = """\ +quicktest.py: quickly test the restructuredtext parser. + +Usage:: + + quicktest.py [options] [filename] + +``filename`` is the name of the file to use as input (default is stdin). + +Options: +""" + +options = [('pretty', 'p', + 'output pretty pseudo-xml: no "&abc;" entities (default)'), + ('test', 't', 'output test-ready data (input & expected output, ' + 'ready to be copied to a parser test module)'), + ('rawxml', 'r', 'output raw XML'), + ('styledxml=', 's', 'output raw XML with XSL style sheet reference ' + '(filename supplied in the option argument)'), + ('xml', 'x', 'output pretty XML (indented)'), + ('debug', 'd', 'debug mode (lots of output)'), + ('help', 'h', 'show help text')] +"""See distutils.fancy_getopt.FancyGetopt.__init__ for a description of the +data structure: (long option, short option, description).""" + +def usage(): + print usage_header + for longopt, shortopt, description in options: + if longopt[-1:] == '=': + opts = '-%s arg, --%sarg' % (shortopt, longopt) + else: + opts = '-%s, --%s' % (shortopt, longopt), + print '%-15s' % opts, + if len(opts) > 14: + print '%-16s' % '\n', + while len(description) > 60: + limit = description.rindex(' ', 0, 60) + print description[:limit].strip() + description = description[limit + 1:] + print '%-15s' % ' ', + print description + +def _pretty(input, document, optargs): + return document.pformat() + +def _rawxml(input, document, optargs): + return document.asdom().toxml() + +def _styledxml(input, document, optargs): + docnode = document.asdom().childNodes[0] + return '%s\n%s\n%s' % ( + '', + '' % optargs['styledxml'], + docnode.toxml()) + +def _prettyxml(input, document, optargs): + return document.asdom().toprettyxml(' ', '\n') + +def _test(input, document, optargs): + tq = '"""' + output = document.pformat() # same as _pretty() + return """\ + totest['change_this_test_name'] = [ +[%s\\ +%s +%s, +%s\\ +%s +%s], +] +""" % ( tq, escape(input.rstrip()), tq, tq, escape(output.rstrip()), tq ) + +def escape(text): + """ + Return `text` in a form compatible with triple-double-quoted Python strings. + """ + text = text.replace('\\', '\\\\') # escape backslashes + text = text.replace('"""', '""\\"') # break up triple-double-quotes + text = text.replace(' \n', ' \\n\\\n') # protect trailing whitespace + return text + +_outputFormatters = { + 'rawxml': _rawxml, + 'styledxml': _styledxml, + 'xml': _prettyxml, + 'pretty' : _pretty, + 'test': _test + } + +def format(outputFormat, input, document, optargs): + formatter = _outputFormatters[outputFormat] + return formatter(input, document, optargs) + +def getArgs(): + if os.name == 'mac' and len(sys.argv) <= 1: + return macGetArgs() + else: + return posixGetArgs(sys.argv[1:]) + +def posixGetArgs(argv): + outputFormat = 'pretty' + # convert fancy_getopt style option list to getopt.getopt() arguments + shortopts = ''.join([option[1] + ':' * (option[0][-1:] == '=') + for option in options if option[1]]) + longopts = [option[0] for option in options if option[0]] + try: + opts, args = getopt.getopt(argv, shortopts, longopts) + except getopt.GetoptError: + usage() + sys.exit(2) + optargs = {'debug': 0} + for o, a in opts: + if o in ['-h', '--help']: + usage() + sys.exit() + elif o in ['-r', '--rawxml']: + outputFormat = 'rawxml' + elif o in ['-s', '--styledxml']: + outputFormat = 'styledxml' + optargs['styledxml'] = a + elif o in ['-x', '--xml']: + outputFormat = 'xml' + elif o in ['-p', '--pretty']: + outputFormat = 'pretty' + elif o in ['-t', '--test']: + outputFormat = 'test' + elif o in ['-d', '--debug']: + optargs['debug'] = 1 + else: + raise getopt.GetoptError, "getopt should have saved us!" + if len(args) > 1: + print "Only one file at a time, thanks." + usage() + sys.exit(1) + if len(args) == 1: + inputFile = open(args[0]) + else: + inputFile = sys.stdin + return inputFile, outputFormat, optargs + +def macGetArgs(): + import EasyDialogs + EasyDialogs.Message("""\ +In the following window, please: + +1. Choose an output format from the "Option" list. +2. Click "Add" (if you don't, the default format will + be "pretty"). +3. Click "Add existing file..." and choose an input file. +4. Click "OK".""") + optionlist = [(longopt, description) + for (longopt, shortopt, description) in options] + argv = EasyDialogs.GetArgv(optionlist=optionlist, addnewfile=0, addfolder=0) + return posixGetArgs(argv) + +def main(): + inputFile, outputFormat, optargs = getArgs() # process cmdline arguments + parser = Parser() + input = inputFile.read() + document = docutils.utils.newdocument(debug=optargs['debug']) + parser.parse(input, document) + output = format(outputFormat, input, document, optargs) + print output, + + +if __name__ == '__main__': + sys.stderr = sys.stdout + main() diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css new file mode 100644 index 000000000..2db991782 --- /dev/null +++ b/tools/stylesheets/default.css @@ -0,0 +1,157 @@ +/* +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:date: $Date$ +:version: $Revision$ +:copyright: This stylesheet has been placed in the public domain. + +Default cascading style sheet for the HTML output of Docutils. +*/ + +a.footnote-reference { + font-size: smaller ; + vertical-align: super } + +a.target { + color: blue } + +code { + background-color: #eeeeee } + +div.abstract { + margin: 2em 5em } + +div.abstract p.topic-title { + font-weight: bold ; + text-align: center } + +div.attention, div.caution, div.danger, div.error, div.hint, +div.important, div.note, div.tip, div.warning { + margin: 2em ; + border: medium outset ; + padding: 1em } + +div.attention p.admonition-title, div.caution p.admonition-title, +div.danger p.admonition-title, div.error p.admonition-title, +div.warning p.admonition-title { + color: red ; + font-weight: bold ; + font-family: sans-serif } + +div.hint p.admonition-title, div.important p.admonition-title, +div.note p.admonition-title, div.tip p.admonition-title { + font-weight: bold ; + font-family: sans-serif } + +div.field-body { + margin-bottom: 1em } + +div.field-list { + margin-bottom: -1em } + +div.figure { + margin-left: 2em } + +div.system-messages { + margin: 5em } + +div.system-messages h1 { + color: red } + +div.system-message { + border: medium outset ; + padding: 1em } + +div.system-message p.system-message-title { + color: red ; + font-weight: bold } + +div.topic { + margin: 2em } + +dt { + margin-bottom: -1em } + +h1.title { + text-align: center } + +h2.subtitle { + text-align: center } + +hr { + width: 75% } + +ol.arabic { + list-style: decimal } + +ol.loweralpha { + list-style: lower-alpha } + +ol.upperalpha { + list-style: upper-alpha } + +ol.lowerroman { + list-style: lower-roman } + +ol.upperroman { + list-style: upper-roman } + +p.caption { + font-style: italic } + +p.credits { + font-style: italic ; + font-size: smaller } + +p.docinfo-name { + font-weight: bold ; + text-align: right } + +p.field-name { + font-weight: bold ; + margin-bottom: 1em } + +p.label { + white-space: nowrap } + +p.topic-title { + font-weight: bold } + +pre.literal-block, pre.doctest-block { + margin-left: 2em ; + margin-right: 2em ; + background-color: #eeeeee } + +span.classifier { + font-family: sans-serif ; + font-style: oblique } + +span.classifier-delimiter { + font-family: sans-serif ; + font-weight: bold } + +span.field-argument { + font-style: italic } + +span.interpreted { + font-family: sans-serif } + +span.option-argument { + font-style: italic } + +span.problematic { + color: red } + +table { + margin-top: 1em } + +table.citation { + border-left: solid thin gray ; + padding-left: 0.5ex } + +table.docinfo { + margin: 2em 4em } + +table.footnote { + border-left: solid thin black ; + padding-left: 0.5ex } -- cgit v1.2.1 From 34f7a6d1ac6f52cf920a933aba804f54c7be5525 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 5 May 2002 15:49:41 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@91 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/quicktest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/quicktest.py b/tools/quicktest.py index df295f66a..fab25adce 100755 --- a/tools/quicktest.py +++ b/tools/quicktest.py @@ -174,7 +174,7 @@ def main(): inputFile, outputFormat, optargs = getArgs() # process cmdline arguments parser = Parser() input = inputFile.read() - document = docutils.utils.newdocument(debug=optargs['debug']) + document = docutils.utils.new_document(debug=optargs['debug']) parser.parse(input, document) output = format(outputFormat, input, document, optargs) print output, -- cgit v1.2.1 From cff9de2e203bbe10708a99c99b1d67672b1ae4a1 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 5 May 2002 15:50:10 +0000 Subject: simplified git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@92 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/html.py | 15 ++++++++++----- tools/publish.py | 13 ++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/html.py b/tools/html.py index 66f029364..2b9d727ea 100755 --- a/tools/html.py +++ b/tools/html.py @@ -16,16 +16,21 @@ import sys from docutils.core import publish from docutils import utils -reporter = utils.Reporter(2, 4) + +reporter = utils.Reporter(1, 4) #reporter.setconditions('nodes.Node.walkabout', 2, 4, debug=1) if len(sys.argv) == 2: - publish(writername='html', source=sys.argv[1], reporter=reporter) + source = sys.argv[1] + destination = None elif len(sys.argv) == 3: - publish(writername='html', source=sys.argv[1], destination=sys.argv[2], - reporter=reporter) + source = sys.argv[1] + destination = sys.argv[2] elif len(sys.argv) > 3: print >>sys.stderr, 'Maximum 2 arguments allowed.' sys.exit(1) else: - publish() + source = None + destination = None +publish(source=source, destination=destination, reporter=reporter, + writer_name='html') diff --git a/tools/publish.py b/tools/publish.py index 539548911..33655d6b6 100755 --- a/tools/publish.py +++ b/tools/publish.py @@ -14,14 +14,21 @@ This module takes advantage of the default values defined in `publish()`. import sys from docutils.core import publish +from docutils import utils +reporter = utils.Reporter(1, 4) + if len(sys.argv) == 2: - publish(source=sys.argv[1]) + source = sys.argv[1] + destination = None elif len(sys.argv) == 3: - publish(source=sys.argv[1], destination=sys.argv[2]) + source = sys.argv[1] + destination = sys.argv[2] elif len(sys.argv) > 3: print >>sys.stderr, 'Maximum 2 arguments allowed.' sys.exit(1) else: - publish() + source = None + destination = None +publish(source=source, destination=destination, reporter=reporter) -- cgit v1.2.1 From b21ee64ccb2daeb368843a84972bfdece858b6c3 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 24 May 2002 03:03:19 +0000 Subject: Removed
space reduction; didn't work. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@142 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 3 --- 1 file changed, 3 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index 2db991782..17bc06900 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -69,9 +69,6 @@ div.system-message p.system-message-title { div.topic { margin: 2em } -dt { - margin-bottom: -1em } - h1.title { text-align: center } -- cgit v1.2.1 From 00a4065f9d8c7bd420ab5e7662b06cb5e43639ab Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 30 May 2002 02:19:18 +0000 Subject: Updated front-ends to use the new command-line processing facilities of ``docutils.frontend`` (exposed in ``docutils.core.Publisher``), reducing each to just a few lines of code. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@156 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/html.py | 24 +++--------------------- tools/publish.py | 22 +++------------------- 2 files changed, 6 insertions(+), 40 deletions(-) (limited to 'tools') diff --git a/tools/html.py b/tools/html.py index 2b9d727ea..e93abe3ca 100755 --- a/tools/html.py +++ b/tools/html.py @@ -7,30 +7,12 @@ :Date: $Date$ :Copyright: This module has been placed in the public domain. -A minimal front-end to the Docutils Publisher. - -This module takes advantage of the default values defined in `publish()`. +A minimal front-end to the Docutils Publisher, producing HTML. """ -import sys from docutils.core import publish -from docutils import utils -reporter = utils.Reporter(1, 4) -#reporter.setconditions('nodes.Node.walkabout', 2, 4, debug=1) +usage = 'usage:\n %prog [options] [source [destination]]' -if len(sys.argv) == 2: - source = sys.argv[1] - destination = None -elif len(sys.argv) == 3: - source = sys.argv[1] - destination = sys.argv[2] -elif len(sys.argv) > 3: - print >>sys.stderr, 'Maximum 2 arguments allowed.' - sys.exit(1) -else: - source = None - destination = None -publish(source=source, destination=destination, reporter=reporter, - writer_name='html') +publish(writer_name='html', usage=usage) diff --git a/tools/publish.py b/tools/publish.py index 33655d6b6..606cb7645 100755 --- a/tools/publish.py +++ b/tools/publish.py @@ -7,28 +7,12 @@ :Date: $Date$ :Copyright: This module has been placed in the public domain. -A minimal front-end to the Docutils Publisher. - -This module takes advantage of the default values defined in `publish()`. +A minimal front-end to the Docutils Publisher, producing pseudo-XML. """ -import sys from docutils.core import publish -from docutils import utils -reporter = utils.Reporter(1, 4) +usage = 'usage:\n %prog [options] [source [destination]]' -if len(sys.argv) == 2: - source = sys.argv[1] - destination = None -elif len(sys.argv) == 3: - source = sys.argv[1] - destination = sys.argv[2] -elif len(sys.argv) > 3: - print >>sys.stderr, 'Maximum 2 arguments allowed.' - sys.exit(1) -else: - source = None - destination = None -publish(source=source, destination=destination, reporter=reporter) +publish(usage=usage) -- cgit v1.2.1 From 1be17ead1d6e210c5a8d76cd44a283879f932d69 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 30 May 2002 02:29:07 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@158 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/quicktest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/quicktest.py b/tools/quicktest.py index fab25adce..d76845023 100755 --- a/tools/quicktest.py +++ b/tools/quicktest.py @@ -10,7 +10,9 @@ :Copyright: This module has been placed in the public domain. """ -import sys, os, getopt +import sys +import os +import getopt import docutils.utils from docutils.parsers.rst import Parser -- cgit v1.2.1 From 14a0689d77ea855ef7f983a3cad114bb7ae4df5f Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 1 Jun 2002 01:45:11 +0000 Subject: - Added support for ``header`` and ``footer`` elements. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@174 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index 17bc06900..802c83c76 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -52,6 +52,11 @@ div.field-list { div.figure { margin-left: 2em } +div.footer, div.header { + font-size: smaller ; + font-style: italic ; + text-align: center } + div.system-messages { margin: 5em } -- cgit v1.2.1 From 147e98fd9a033cc75331cf9fe3417258e5ab761a Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 1 Jun 2002 02:38:12 +0000 Subject: Removed italics & centering from footer; hard to read. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@176 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index 802c83c76..690caf82b 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -53,9 +53,7 @@ div.figure { margin-left: 2em } div.footer, div.header { - font-size: smaller ; - font-style: italic ; - text-align: center } + font-size: smaller } div.system-messages { margin: 5em } -- cgit v1.2.1 From 87a136ed0c7a0e107cd58bb96e587daacd265eeb Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 13 Jun 2002 03:34:19 +0000 Subject: Updated for new Optik functionality. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@184 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/html.py | 6 ++++-- tools/publish.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/html.py b/tools/html.py index e93abe3ca..faee09f9c 100755 --- a/tools/html.py +++ b/tools/html.py @@ -13,6 +13,8 @@ A minimal front-end to the Docutils Publisher, producing HTML. from docutils.core import publish -usage = 'usage:\n %prog [options] [source [destination]]' +usage = '%prog [options] [source [destination]]' +description = ('Generate HTML documents from standalone reStructuredText ' + 'sources.') -publish(writer_name='html', usage=usage) +publish(writer_name='html', usage=usage, description=description) diff --git a/tools/publish.py b/tools/publish.py index 606cb7645..14c0ea09a 100755 --- a/tools/publish.py +++ b/tools/publish.py @@ -13,6 +13,8 @@ A minimal front-end to the Docutils Publisher, producing pseudo-XML. from docutils.core import publish -usage = 'usage:\n %prog [options] [source [destination]]' +usage = '%prog [options] [source [destination]]' +description = ('Generate pseudo-XML from standalone reStructuredText sources ' + '(for testing purposes).') -publish(usage=usage) +publish(usage=usage, description=description) -- cgit v1.2.1 From 12566a28180aa8448773ffd892fe841fa3f2314c Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 24 Jun 2002 04:32:42 +0000 Subject: Remove the extra whitespace from the top of the first paragraph of a
or
  • . git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@201 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index 690caf82b..ffeec0d69 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -96,6 +96,14 @@ ol.lowerroman { ol.upperroman { list-style: upper-roman } +dd p:first-child { + margin-top: 0px; +} + +li p:first-child { + margin-top: 0px; +} + p.caption { font-style: italic } -- cgit v1.2.1 From a9913f6dfaab8d568b019f4d700c966c44bb1032 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 27 Jun 2002 01:24:56 +0000 Subject: Added the "--attributes" option, hacked a bit. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@213 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/quicktest.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/quicktest.py b/tools/quicktest.py index d76845023..cf3884875 100755 --- a/tools/quicktest.py +++ b/tools/quicktest.py @@ -13,7 +13,8 @@ import sys import os import getopt -import docutils.utils +from docutils.frontend import OptionParser +from docutils.utils import new_document from docutils.parsers.rst import Parser @@ -37,6 +38,7 @@ options = [('pretty', 'p', ('styledxml=', 's', 'output raw XML with XSL style sheet reference ' '(filename supplied in the option argument)'), ('xml', 'x', 'output pretty XML (indented)'), + ('attributes', '', 'dump document attributes after processing'), ('debug', 'd', 'debug mode (lots of output)'), ('help', 'h', 'show help text')] """See distutils.fancy_getopt.FancyGetopt.__init__ for a description of the @@ -127,7 +129,7 @@ def posixGetArgs(argv): except getopt.GetoptError: usage() sys.exit(2) - optargs = {'debug': 0} + optargs = {'debug': 0, 'attributes': 0} for o, a in opts: if o in ['-h', '--help']: usage() @@ -143,6 +145,8 @@ def posixGetArgs(argv): outputFormat = 'pretty' elif o in ['-t', '--test']: outputFormat = 'test' + elif o == '--attributes': + optargs['attributes'] = 1 elif o in ['-d', '--debug']: optargs['debug'] = 1 else: @@ -174,12 +178,17 @@ In the following window, please: def main(): inputFile, outputFormat, optargs = getArgs() # process cmdline arguments + options = OptionParser().get_default_values() + options.debug = optargs['debug'] parser = Parser() input = inputFile.read() - document = docutils.utils.new_document(debug=optargs['debug']) + document = new_document(options) parser.parse(input, document) output = format(outputFormat, input, document, optargs) print output, + if optargs['attributes']: + import pprint + pprint.pprint(document.__dict__) if __name__ == '__main__': -- cgit v1.2.1 From 02b1f1efbb561ab4e396cd44f4edb4fa5f671863 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 4 Jul 2002 01:29:40 +0000 Subject: - Added ``locale.setlocale()`` calls to front-ends. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@246 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/html.py | 3 +++ tools/publish.py | 3 +++ tools/quicktest.py | 3 +++ 3 files changed, 9 insertions(+) (limited to 'tools') diff --git a/tools/html.py b/tools/html.py index faee09f9c..c1c29b2b6 100755 --- a/tools/html.py +++ b/tools/html.py @@ -10,6 +10,9 @@ A minimal front-end to the Docutils Publisher, producing HTML. """ +import locale +locale.setlocale(locale.LC_ALL, '') + from docutils.core import publish diff --git a/tools/publish.py b/tools/publish.py index 14c0ea09a..6e814ea67 100755 --- a/tools/publish.py +++ b/tools/publish.py @@ -10,6 +10,9 @@ A minimal front-end to the Docutils Publisher, producing pseudo-XML. """ +import locale +locale.setlocale(locale.LC_ALL, '') + from docutils.core import publish diff --git a/tools/quicktest.py b/tools/quicktest.py index cf3884875..9517b95cc 100755 --- a/tools/quicktest.py +++ b/tools/quicktest.py @@ -10,6 +10,9 @@ :Copyright: This module has been placed in the public domain. """ +import locale +locale.setlocale(locale.LC_ALL, '') + import sys import os import getopt -- cgit v1.2.1 From 0fd8121cc0dcf7cc0a8bd9c30856844e4e917134 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 4 Jul 2002 01:31:27 +0000 Subject: Added to project. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@247 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/docutils-xml.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 tools/docutils-xml.py (limited to 'tools') diff --git a/tools/docutils-xml.py b/tools/docutils-xml.py new file mode 100755 index 000000000..9269376bf --- /dev/null +++ b/tools/docutils-xml.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +""" +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +A minimal front-end to the Docutils Publisher, producing Docutils XML. +""" + +import locale +locale.setlocale(locale.LC_ALL, '') + +from docutils.core import publish + + +usage = '%prog [options] [source [destination]]' +description = ('Generate Docutils XML from standalone reStructuredText ' + 'sources.') + +publish(writer_name='xml', usage=usage, description=description) -- cgit v1.2.1 From 8139dee08117675b9882c2c5fc02be7c66a9341e Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 14 Jul 2002 03:14:29 +0000 Subject: Added to project; stylesheet for PEPs. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@286 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/pep.css | 206 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 tools/stylesheets/pep.css (limited to 'tools') diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css new file mode 100644 index 000000000..00e586c50 --- /dev/null +++ b/tools/stylesheets/pep.css @@ -0,0 +1,206 @@ +/* +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:date: $Date$ +:version: $Revision$ +:copyright: This stylesheet has been placed in the public domain. + +Default cascading style sheet for the PEP HTML output of Docutils. +*/ + +.navigation { + width: 100% ; + background: #99ccff } + +.navigation .navicon { + width: 150px ; + height: 35 } + +.navigation .textlinks { + padding-left: 1em ; + text-align: left } + +.rfc2822 { + margin-top: 0.5em ; + margin-left: 1em ; + margin-right: 1em } + +.rfc2822 div.field-body { + text-align: left } + +.rfc2822 p.field-name { + text-align: right ; + font-family: sans-serif ; + padding-right: 0.5em ; + font-weight: bold ; + margin-bottom: 0em } + +a.footnote-reference { + font-size: smaller ; + vertical-align: super } + +a.target { + color: blue } + +body { + margin: 0px ; + margin-bottom: 1em ; + padding: 0px } + +code { + background-color: #eeeeee } + +div.section { + margin-left: 1em ; + margin-right: 1em } + +div.abstract { + margin: 2em 5em } + +div.abstract p.topic-title { + font-weight: bold ; + text-align: center } + +div.attention, div.caution, div.danger, div.error, div.hint, +div.important, div.note, div.tip, div.warning { + margin: 2em ; + border: medium outset ; + padding: 1em } + +div.attention p.admonition-title, div.caution p.admonition-title, +div.danger p.admonition-title, div.error p.admonition-title, +div.warning p.admonition-title { + color: red ; + font-weight: bold ; + font-family: sans-serif } + +div.hint p.admonition-title, div.important p.admonition-title, +div.note p.admonition-title, div.tip p.admonition-title { + font-weight: bold ; + font-family: sans-serif } + +div.figure { + margin-left: 2em } + +div.footer, div.header { + font-size: smaller } + +div.footer p { + margin-left: 1em ; + margin-right: 1em } + +div.system-messages { + margin: 5em } + +div.system-messages h1 { + color: red } + +div.system-message { + border: medium outset ; + padding: 1em } + +div.system-message p.system-message-title { + color: red ; + font-weight: bold } + +div.topic { + margin: 2em } + +h1 { + font-family: sans-serif ; + font-size: large } + +h2 { + font-family: sans-serif ; + font-size: medium } + +h3 { + font-family: sans-serif ; + font-size: small } + +h4 { + font-family: sans-serif ; + font-style: italic ; + font-size: small } + +h5 { + font-family: sans-serif; + font-size: x-small } + +h6 { + font-family: sans-serif; + font-style: italic ; + font-size: x-small } + +.section hr { + width: 75% } + +ol.arabic { + list-style: decimal } + +ol.loweralpha { + list-style: lower-alpha } + +ol.upperalpha { + list-style: upper-alpha } + +ol.lowerroman { + list-style: lower-roman } + +ol.upperroman { + list-style: upper-roman } + +dd p:first-child { + margin-top: 0px } + +li p:first-child { + margin-top: 0px } + +p.caption { + font-style: italic } + +p.credits { + font-style: italic ; + font-size: smaller } + +p.field-name { + font-weight: bold ; + margin-bottom: 1em } + +p.label { + white-space: nowrap } + +p.topic-title { + font-family: sans-serif ; + font-weight: bold } + +pre.literal-block, pre.doctest-block { + margin-left: 2em ; + margin-right: 2em ; + background-color: #eeeeee } + +span.classifier { + font-family: sans-serif ; + font-style: oblique } + +span.classifier-delimiter { + font-family: sans-serif ; + font-weight: bold } + +span.field-argument { + font-style: italic } + +span.interpreted { + font-family: sans-serif } + +span.option-argument { + font-style: italic } + +span.problematic { + color: red } + +table.citation { + margin-bottom: 1em } + +table.footnote { + margin-bottom: 1em } -- cgit v1.2.1 From 4f9dc43240ea31269c8fdc2aa877ffed51f7060c Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 14 Jul 2002 03:15:19 +0000 Subject: Added to project; template for PEP HTML. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@287 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep-template.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tools/pep-template.html (limited to 'tools') diff --git a/tools/pep-template.html b/tools/pep-template.html new file mode 100644 index 000000000..eabd3bcb8 --- /dev/null +++ b/tools/pep-template.html @@ -0,0 +1,23 @@ + + + + + + + PEP %(pep)s -- %(title)s + + + + + + +%(body)s +%(body_suffix)s -- cgit v1.2.1 From 078916ea45ccd1d7e40328c148be92e69ad25519 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 14 Jul 2002 03:18:57 +0000 Subject: Added to project; PEP to HTML front-end. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@288 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 tools/pep.py (limited to 'tools') diff --git a/tools/pep.py b/tools/pep.py new file mode 100755 index 000000000..acaab10c4 --- /dev/null +++ b/tools/pep.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +""" +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +A minimal front-end to the Docutils Publisher, producing HTML from PEP +(Python Enhancement Proposal) documents. +""" + +import locale +locale.setlocale(locale.LC_ALL, '') + +from docutils.core import publish + + +usage = 'usage:\n %prog [options] [source [destination]]' + +publish(reader_name='pep', writer_name='pep_html', usage=usage) -- cgit v1.2.1 From acb21b5d5622d284a3ed98236bf15ee70bb03069 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 14 Jul 2002 03:40:35 +0000 Subject: parameterized the stylesheet reference git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@291 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep-template.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/pep-template.html b/tools/pep-template.html index eabd3bcb8..49e989ba4 100644 --- a/tools/pep-template.html +++ b/tools/pep-template.html @@ -5,7 +5,7 @@ PEP %(pep)s -- %(title)s - + Date: Thu, 18 Jul 2002 01:40:16 +0000 Subject: tweaking git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@310 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index ffeec0d69..81de8ba2c 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -43,12 +43,6 @@ div.note p.admonition-title, div.tip p.admonition-title { font-weight: bold ; font-family: sans-serif } -div.field-body { - margin-bottom: 1em } - -div.field-list { - margin-bottom: -1em } - div.figure { margin-left: 2em } @@ -111,14 +105,6 @@ p.credits { font-style: italic ; font-size: smaller } -p.docinfo-name { - font-weight: bold ; - text-align: right } - -p.field-name { - font-weight: bold ; - margin-bottom: 1em } - p.label { white-space: nowrap } @@ -163,3 +149,10 @@ table.docinfo { table.footnote { border-left: solid thin black ; padding-left: 0.5ex } + +td.docinfo-name { + font-weight: bold ; + text-align: right } + +td.field-name { + font-weight: bold } -- cgit v1.2.1 From 32367a27ba4aa267d9d0ecfe10c8395e4044ad47 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 18 Jul 2002 01:43:09 +0000 Subject: Parameterized the Python graphic. Separately parematerized the PEP index path. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@311 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep-template.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/pep-template.html b/tools/pep-template.html index 49e989ba4..de0c0d4c8 100644 --- a/tools/pep-template.html +++ b/tools/pep-template.html @@ -12,11 +12,11 @@ width="100%%" border="0"> %(body)s -- cgit v1.2.1 From d502067bbf507b4f370972b7ee8cc54645ca3ccc Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 18 Jul 2002 01:44:22 +0000 Subject: Renamed pep-template.html to pep-html-template git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@312 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep-html-template | 23 +++++++++++++++++++++++ tools/pep-template.html | 23 ----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 tools/pep-html-template delete mode 100644 tools/pep-template.html (limited to 'tools') diff --git a/tools/pep-html-template b/tools/pep-html-template new file mode 100644 index 000000000..de0c0d4c8 --- /dev/null +++ b/tools/pep-html-template @@ -0,0 +1,23 @@ + + + + + + + PEP %(pep)s -- %(title)s + + + + + + +%(body)s +%(body_suffix)s diff --git a/tools/pep-template.html b/tools/pep-template.html deleted file mode 100644 index de0c0d4c8..000000000 --- a/tools/pep-template.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - PEP %(pep)s -- %(title)s - - - - - - -%(body)s -%(body_suffix)s -- cgit v1.2.1 From 072c69c92964642a05d2b9c91b4e4321890d933b Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 18 Jul 2002 01:48:14 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@313 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/pep.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css index 00e586c50..69fc0f087 100644 --- a/tools/stylesheets/pep.css +++ b/tools/stylesheets/pep.css @@ -28,7 +28,7 @@ Default cascading style sheet for the PEP HTML output of Docutils. .rfc2822 div.field-body { text-align: left } -.rfc2822 p.field-name { +.rfc2822 td.field-name { text-align: right ; font-family: sans-serif ; padding-right: 0.5em ; -- cgit v1.2.1 From 2a27bb35bdadbee15b24709e03c1cca08c7c8615 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 19 Jul 2002 02:05:40 +0000 Subject: From python/nondist/peps. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@319 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep2html.py | 392 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 392 insertions(+) create mode 100755 tools/pep2html.py (limited to 'tools') diff --git a/tools/pep2html.py b/tools/pep2html.py new file mode 100755 index 000000000..47cf1be1e --- /dev/null +++ b/tools/pep2html.py @@ -0,0 +1,392 @@ +#!/usr/bin/env python +""" +convert PEP's to (X)HTML - courtesy of /F + +Usage: %(PROGRAM)s [options] [peps] + +Options: + + -u/--user + SF username + + -b/--browse + After generating the HTML, direct your web browser to view it + (using the Python webbrowser module). If both -i and -b are + given, this will browse the on-line HTML; otherwise it will + browse the local HTML. If no pep arguments are given, this + will browse PEP 0. + + -i/--install + After generating the HTML, install it and the plain text source file + (.txt) SourceForge. In that case the user's name is used in the scp + and ssh commands, unless -u sf_username is given (in which case, it is + used instead). Without -i, -u is ignored. + + -q/--quiet + Turn off verbose messages. + + -h/--help + Print this help message and exit. + +The optional argument `peps' is a list of either pep numbers or .txt files. +""" + +import sys +import os +import re +import cgi +import glob +import getopt +import errno +import random +import time + +PROGRAM = sys.argv[0] +RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html' +PEPURL = 'pep-%04d.html' +PEPCVSURL = 'http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/nondist/peps/pep-%04d.txt' +PEPDIRRUL = 'http://www.python.org/peps/' + + +HOST = "www.python.org" # host for update +HDIR = "/ftp/ftp.python.org/pub/www.python.org/peps" # target host directory +LOCALVARS = "Local Variables:" + +# The generated HTML doesn't validate -- you cannot use
    and

    inside +#
     tags.  But if I change that, the result doesn't look very nice...
    +DTD = ('')
    +
    +fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt)?)|"
    +                    "(RFC[- ]?(?P\d+))|"
    +                    "(PEP\s+(?P\d+))|"
    +                    ".")
    +
    +EMPTYSTRING = ''
    +SPACE = ' '
    +
    +
    +
    +def usage(code, msg=''):
    +    print >> sys.stderr, __doc__ % globals()
    +    if msg:
    +        print >> sys.stderr, msg
    +    sys.exit(code)
    +
    +
    +
    +def fixanchor(current, match):
    +    text = match.group(0)
    +    link = None
    +    if text.startswith('http:') or text.startswith('ftp:'):
    +        # Strip off trailing punctuation.  Pattern taken from faqwiz.
    +        ltext = list(text)
    +        while ltext:
    +            c = ltext.pop()
    +            if c not in '();:,.?\'"<>':
    +                ltext.append(c)
    +                break
    +        link = EMPTYSTRING.join(ltext)
    +    elif text.startswith('pep-') and text <> current:
    +        link = os.path.splitext(text)[0] + ".html"
    +    elif text.startswith('PEP'):
    +        pepnum = int(match.group('pepnum'))
    +        link = PEPURL % pepnum
    +    elif text.startswith('RFC'):
    +        rfcnum = int(match.group('rfcnum'))
    +        link = RFCURL % rfcnum
    +    if link:
    +        return '%s' % (link, cgi.escape(text))
    +    return cgi.escape(match.group(0)) # really slow, but it works...
    +
    +
    +
    +NON_MASKED_EMAILS = [
    +    'peps@python.org',
    +    'python-list@python.org',
    +    'python-dev@python.org',
    +    ]
    +
    +def fixemail(address, pepno):
    +    if address.lower() in NON_MASKED_EMAILS:
    +        # return hyperlinked version of email address
    +        return linkemail(address, pepno)
    +    else:
    +        # return masked version of email address
    +        parts = address.split('@', 1)
    +        return '%s at %s' % (parts[0], parts[1])
    +
    +
    +def linkemail(address, pepno):
    +    parts = address.split('@', 1)
    +    return (''
    +            '%s at %s'
    +            % (parts[0], parts[1], pepno, parts[0], parts[1]))
    +
    +
    +def fixfile(infile, outfile):
    +    basename = os.path.basename(infile)
    +    # convert plain text pep to minimal XHTML markup
    +    try:
    +        fi = open(infile)
    +    except IOError, e:
    +        if e.errno <> errno.ENOENT: raise
    +        print >> sys.stderr, 'Error: Skipping missing PEP file:', e.filename
    +        return
    +    fo = open(outfile, "w")
    +    print >> fo, DTD
    +    print >> fo, ''
    +    print >> fo, ''
    +    # head
    +    header = []
    +    pep = ""
    +    title = ""
    +    while 1:
    +        line = fi.readline()
    +        if not line.strip():
    +            break
    +        if line[0].strip():
    +            if ":" not in line:
    +                break
    +            key, value = line.split(":", 1)
    +            value = value.strip()
    +            header.append((key, value))
    +        else:
    +            # continuation line
    +            key, value = header[-1]
    +            value = value + line
    +            header[-1] = key, value
    +        if key.lower() == "title":
    +            title = value
    +        elif key.lower() == "pep":
    +            pep = value
    +    if pep:
    +        title = "PEP " + pep + " -- " + title
    +    if title:
    +        print >> fo, '  %s' % cgi.escape(title)
    +    print >> fo, '  '
    +    print >> fo, ''
    +    # body
    +    print >> fo, ''
    +    print >> fo, '> fo, '       width="100%" border="0">'
    +    print >> fo, ''
    +    print >> fo, ''
    +    print >> fo, '
    \n' + for k, v in header: + if k.lower() in ('author', 'discussions-to'): + mailtos = [] + for addr in v.split(): + if '@' in addr: + if k.lower() == 'discussions-to': + m = linkemail(addr, pep) + else: + m = fixemail(addr, pep) + mailtos.append(m) + elif addr.startswith('http:'): + mailtos.append( + '%s' % (addr, addr)) + else: + mailtos.append(addr) + v = SPACE.join(mailtos) + elif k.lower() in ('replaces', 'replaced-by'): + otherpeps = '' + for otherpep in v.split(): + otherpep = int(otherpep) + otherpeps += '%i ' % (otherpep, + otherpep) + v = otherpeps + elif k.lower() in ('last-modified',): + url = PEPCVSURL % int(pep) + date = v or time.strftime('%d-%b-%Y', + time.localtime(os.stat(infile)[8])) + v = '%s ' % (url, cgi.escape(date)) + else: + v = cgi.escape(v) + print >> fo, ' ' \ + % (cgi.escape(k), v) + print >> fo, '
    %s: %s
    ' + print >> fo, '
    ' + print >> fo, '
    ' + print >> fo, '
    ' + need_pre = 1 + while 1: + line = fi.readline() + if not line: + break + if line[0] == '\f': + continue + if line.strip() == LOCALVARS: + break + if line[0].strip(): + if line.strip() == LOCALVARS: + break + if not need_pre: + print >> fo, '
    ' + print >> fo, '

    %s

    ' % line.strip() + need_pre = 1 + elif not line.strip() and need_pre: + continue + else: + # PEP 0 has some special treatment + if basename == 'pep-0000.txt': + parts = line.split() + if len(parts) > 1 and re.match(r'\s*\d{1,4}', parts[1]): + # This is a PEP summary line, which we need to hyperlink + url = PEPURL % int(parts[1]) + if need_pre: + print >> fo, '
    '
    +                        need_pre = 0
    +                    print >> fo, re.sub(
    +                        parts[1],
    +                        '%s' % (url, parts[1]),
    +                        line, 1),
    +                    continue
    +                elif parts and '@' in parts[-1]:
    +                    # This is a pep email address line, so filter it.
    +                    url = fixemail(parts[-1], pep)
    +                    if need_pre:
    +                        print >> fo, '
    '
    +                        need_pre = 0
    +                    print >> fo, re.sub(
    +                        parts[-1], url, line, 1),
    +                    continue
    +            line = fixpat.sub(lambda x, c=infile: fixanchor(c, x), line)
    +            if need_pre:
    +                print >> fo, '
    '
    +                need_pre = 0
    +            fo.write(line)
    +    if not need_pre:
    +        print >> fo, '
    ' + print >> fo, '' + print >> fo, '' + print >> fo, '' + fo.close() + os.chmod(outfile, 0664) + + + +def find_pep(pep_str): + """Find the .txt file indicated by a cmd line argument""" + if os.path.exists(pep_str): + return pep_str + num = int(pep_str) + return "pep-%04d.txt" % num + +def make_html(file, verbose=0): + newfile = os.path.splitext(file)[0] + ".html" + if verbose: + print file, "->", newfile + fixfile(file, newfile) + return newfile + +def push_pep(htmlfiles, txtfiles, username, verbose): + if verbose: + quiet = "" + else: + quiet = "-q" + if username: + username = username + "@" + target = username + HOST + ":" + HDIR + files = htmlfiles[:] + files.extend(txtfiles) + files.append("style.css") + filelist = SPACE.join(files) + rc = os.system("scp %s %s %s" % (quiet, filelist, target)) + if rc: + sys.exit(rc) + rc = os.system("ssh %s%s chmod 664 %s/*" % (username, HOST, HDIR)) + if rc: + sys.exit(rc) + + +def browse_file(pep): + import webbrowser + file = find_pep(pep) + if file.endswith(".txt"): + file = file[:-3] + "html" + file = os.path.abspath(file) + url = "file:" + file + webbrowser.open(url) + +def browse_remote(pep): + import webbrowser + file = find_pep(pep) + if file.endswith(".txt"): + file = file[:-3] + "html" + url = PEPDIRRUL + file + webbrowser.open(url) + + +def main(): + # defaults + update = 0 + username = '' + verbose = 1 + browse = 0 + + try: + opts, args = getopt.getopt( + sys.argv[1:], 'bihqu:', + ['browse', 'install', 'help', 'quiet', 'user=']) + except getopt.error, msg: + usage(1, msg) + + for opt, arg in opts: + if opt in ('-h', '--help'): + usage(0) + elif opt in ('-i', '--install'): + update = 1 + elif opt in ('-u', '--user'): + username = arg + elif opt in ('-q', '--quiet'): + verbose = 0 + elif opt in ('-b', '--browse'): + browse = 1 + + if args: + peptxt = [] + html = [] + for pep in args: + file = find_pep(pep) + peptxt.append(file) + newfile = make_html(file, verbose=verbose) + html.append(newfile) + if browse and not update: + browse_file(pep) + else: + # do them all + peptxt = [] + files = glob.glob("pep-*.txt") + files.sort() + for file in files: + peptxt.append(file) + make_html(file, verbose=verbose) + html = ["pep-*.html"] + if browse and not update: + browse_file("0") + + if update: + push_pep(html, peptxt, username, verbose) + if browse: + if args: + for pep in args: + browse_remote(pep) + else: + browse_remote("0") + + + +if __name__ == "__main__": + main() -- cgit v1.2.1 From c999a0671a217dcdd8a6e2bd38332a021d48632a Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 19 Jul 2002 02:38:13 +0000 Subject: Added support for reStructuredText PEPs. Refactored naming in ``fixfile``. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@326 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep2html.py | 170 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 115 insertions(+), 55 deletions(-) (limited to 'tools') diff --git a/tools/pep2html.py b/tools/pep2html.py index 47cf1be1e..d5d3221d0 100755 --- a/tools/pep2html.py +++ b/tools/pep2html.py @@ -125,24 +125,17 @@ def linkemail(address, pepno): def fixfile(infile, outfile): - basename = os.path.basename(infile) + basename = os.path.basename(infile.name) # convert plain text pep to minimal XHTML markup - try: - fi = open(infile) - except IOError, e: - if e.errno <> errno.ENOENT: raise - print >> sys.stderr, 'Error: Skipping missing PEP file:', e.filename - return - fo = open(outfile, "w") - print >> fo, DTD - print >> fo, '' - print >> fo, '' + print >> outfile, DTD + print >> outfile, '' + print >> outfile, '' # head header = [] pep = "" title = "" while 1: - line = fi.readline() + line = infile.readline() if not line.strip(): break if line[0].strip(): @@ -163,27 +156,27 @@ def fixfile(infile, outfile): if pep: title = "PEP " + pep + " -- " + title if title: - print >> fo, ' %s' % cgi.escape(title) - print >> fo, ' ' - print >> fo, '' + print >> outfile, ' %s' % cgi.escape(title) + print >> outfile, ' ' + print >> outfile, '' # body - print >> fo, '' - print >> fo, '> fo, ' width="100%" border="0">' - print >> fo, '' + print >> outfile, '' + print >> outfile, '
    ' + print >> outfile, '
    ' need_pre = 1 while 1: - line = fi.readline() + line = infile.readline() if not line: break if line[0] == '\f': @@ -233,8 +226,8 @@ def fixfile(infile, outfile): if line.strip() == LOCALVARS: break if not need_pre: - print >> fo, '
    ' - print >> fo, '

    %s

    ' % line.strip() + print >> outfile, '
    ' + print >> outfile, '

    %s

    ' % line.strip() need_pre = 1 elif not line.strip() and need_pre: continue @@ -246,9 +239,9 @@ def fixfile(infile, outfile): # This is a PEP summary line, which we need to hyperlink url = PEPURL % int(parts[1]) if need_pre: - print >> fo, '
    '
    +                        print >> outfile, '
    '
                             need_pre = 0
    -                    print >> fo, re.sub(
    +                    print >> outfile, re.sub(
                             parts[1],
                             '%s' % (url, parts[1]),
                             line, 1),
    @@ -257,26 +250,86 @@ def fixfile(infile, outfile):
                         # This is a pep email address line, so filter it.
                         url = fixemail(parts[-1], pep)
                         if need_pre:
    -                        print >> fo, '
    '
    +                        print >> outfile, '
    '
                             need_pre = 0
    -                    print >> fo, re.sub(
    +                    print >> outfile, re.sub(
                             parts[-1], url, line, 1),
                         continue
    -            line = fixpat.sub(lambda x, c=infile: fixanchor(c, x), line)
    +            line = fixpat.sub(lambda x, c=infile.name: fixanchor(c, x), line)
                 if need_pre:
    -                print >> fo, '
    '
    +                print >> outfile, '
    '
                     need_pre = 0
    -            fo.write(line)
    +            outfile.write(line)
         if not need_pre:
    -        print >> fo, '
    ' - print >> fo, '' - print >> fo, '' - print >> fo, '' - fo.close() - os.chmod(outfile, 0664) + print >> outfile, '
    ' + print >> outfile, '' + print >> outfile, '' + print >> outfile, '' + +def fix_rst_pep(infile, outfile): + from docutils import core, io + pub = core.Publisher() + pub.set_reader(reader_name='pep', parser_name='restructuredtext', + parser=None) + pub.set_writer(writer_name='pep_html') + options = pub.set_options(generator=1, datestamp='%Y-%m-%d %H:%M UTC') + pub.source = io.FileIO(options, source=infile, source_path=infile.name) + pub.destination = io.FileIO(options, destination=outfile, + destination_path=outfile.name) + pub.publish() + + +underline = re.compile('[!-/:-@[-`{-~]{4,}$') + +def check_rst_pep(infile): + """ + Check if `infile` is a reStructuredText PEP. Return 1 for yes, 0 for no. + + If the result is indeterminate, return None. Reset `infile` to the + beginning. + """ + result = None + underline_match = underline.match + # Find the end of the RFC 2822 header (first blank line): + while 1: + line = infile.readline().strip() + if not line: + break + # Determine if the PEP is old-style or new (reStructuredText): + while result is None: + line = infile.readline() + if not line: + break + line = line.rstrip() + if len(line.lstrip()) < len(line): + # Indented section; this is an old-style PEP. + result = 0 + elif underline_match(line): + # Matched a section header underline; + # this is a reStructuredText PEP. + result = 1 + infile.seek(0) + return result +def open_files(inpath, outpath): + try: + infile = open(inpath) + except IOError, e: + if e.errno <> errno.ENOENT: raise + print >> sys.stderr, 'Error: Skipping missing PEP file:', e.filename + sys.stderr.flush() + return None, None + outfile = open(outpath, "w") + return infile, outfile + +def close_files(infile, outfile): + infile.close() + outfile.close() + os.chmod(outfile.name, 0664) + + def find_pep(pep_str): """Find the .txt file indicated by a cmd line argument""" if os.path.exists(pep_str): @@ -284,12 +337,19 @@ def find_pep(pep_str): num = int(pep_str) return "pep-%04d.txt" % num -def make_html(file, verbose=0): - newfile = os.path.splitext(file)[0] + ".html" +def make_html(inpath, verbose=0): + outpath = os.path.splitext(inpath)[0] + ".html" if verbose: - print file, "->", newfile - fixfile(file, newfile) - return newfile + print inpath, "->", outpath + sys.stdout.flush() + infile, outfile = open_files(inpath, outpath) + if infile is not None: + if check_rst_pep(infile): + fix_rst_pep(infile, outfile) + else: + fixfile(infile, outfile) + close_files(infile, outfile) + return outpath def push_pep(htmlfiles, txtfiles, username, verbose): if verbose: -- cgit v1.2.1 From d485602ebab4977879b816aa4f2ba0c9eaedf6b3 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 19 Jul 2002 02:42:34 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@328 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 9 ++------- tools/stylesheets/pep.css | 8 ++------ 2 files changed, 4 insertions(+), 13 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index 81de8ba2c..b5b2d148c 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -15,9 +15,6 @@ a.footnote-reference { a.target { color: blue } -code { - background-color: #eeeeee } - div.abstract { margin: 2em 5em } @@ -91,12 +88,10 @@ ol.upperroman { list-style: upper-roman } dd p:first-child { - margin-top: 0px; -} + margin-top: 0px } li p:first-child { - margin-top: 0px; -} + margin-top: 0px } p.caption { font-style: italic } diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css index 69fc0f087..e84b7a7cf 100644 --- a/tools/stylesheets/pep.css +++ b/tools/stylesheets/pep.css @@ -47,8 +47,8 @@ body { margin-bottom: 1em ; padding: 0px } -code { - background-color: #eeeeee } +col.num { + text-align: center } div.section { margin-left: 1em ; @@ -163,10 +163,6 @@ p.credits { font-style: italic ; font-size: smaller } -p.field-name { - font-weight: bold ; - margin-bottom: 1em } - p.label { white-space: nowrap } -- cgit v1.2.1 From 6f03aeb4f23233eca8173b07f195560eef55fcec Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 23 Jul 2002 02:40:35 +0000 Subject: Many changes to optimize vertical space: compact simple lists etc. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@350 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 28 ++++++++++++++++++++------- tools/stylesheets/pep.css | 44 +++++++++++++++++++++++++++++-------------- 2 files changed, 51 insertions(+), 21 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index b5b2d148c..dc8881606 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -63,6 +63,10 @@ div.system-message p.system-message-title { div.topic { margin: 2em } +h1 a, h2 a, h3 a, h4 a, h5 a, h6 a { + text-decoration: none ; + color: black } + h1.title { text-align: center } @@ -72,6 +76,9 @@ h2.subtitle { hr { width: 75% } +ol.simple, ul.simple { + margin-bottom: 1em } + ol.arabic { list-style: decimal } @@ -87,12 +94,10 @@ ol.lowerroman { ol.upperroman { list-style: upper-roman } -dd p:first-child { - margin-top: 0px } - -li p:first-child { - margin-top: 0px } - +/*dd p:first-child, li p:first-child, td p:first-child, th p:first-child { + margin-top: 0 ; + padding-top: 0 } +*/ p.caption { font-style: italic } @@ -100,6 +105,9 @@ p.credits { font-style: italic ; font-size: smaller } +p.first { + margin-top: 0 } + p.label { white-space: nowrap } @@ -132,7 +140,8 @@ span.problematic { color: red } table { - margin-top: 1em } + margin-top: 0.5em ; + margin-bottom: 0.5em } table.citation { border-left: solid thin gray ; @@ -145,6 +154,11 @@ table.footnote { border-left: solid thin black ; padding-left: 0.5ex } +td, th { + padding-left: 0.5em ; + padding-right: 0.5em ; + vertical-align: baseline } + td.docinfo-name { font-weight: bold ; text-align: right } diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css index e84b7a7cf..53b67b303 100644 --- a/tools/stylesheets/pep.css +++ b/tools/stylesheets/pep.css @@ -10,7 +10,9 @@ Default cascading style sheet for the PEP HTML output of Docutils. .navigation { width: 100% ; - background: #99ccff } + background: #99ccff ; + margin-top: 0px ; + margin-bottom: 0px } .navigation .navicon { width: 150px ; @@ -20,10 +22,16 @@ Default cascading style sheet for the PEP HTML output of Docutils. padding-left: 1em ; text-align: left } +.navigation td, .navigation th { + padding-left: 0em ; + padding-right: 0em ; + vertical-align: middle } + .rfc2822 { margin-top: 0.5em ; - margin-left: 1em ; - margin-right: 1em } + margin-left: 0.5em ; + margin-right: 0.5em ; + margin-bottom: 0em } .rfc2822 div.field-body { text-align: left } @@ -42,17 +50,22 @@ a.footnote-reference { a.target { color: blue } +h1 a, h2 a, h3 a, h4 a, h5 a, h6 a { + text-decoration: none ; + color: black } + body { margin: 0px ; margin-bottom: 1em ; padding: 0px } -col.num { - text-align: center } +td.num { + text-align: right } div.section { margin-left: 1em ; - margin-right: 1em } + margin-right: 1em ; + margin-bottom: 1.5em } div.abstract { margin: 2em 5em } @@ -135,6 +148,9 @@ h6 { .section hr { width: 75% } +ol, ul { + margin-bottom: 1em } + ol.arabic { list-style: decimal } @@ -150,10 +166,7 @@ ol.lowerroman { ol.upperroman { list-style: upper-roman } -dd p:first-child { - margin-top: 0px } - -li p:first-child { +dd p:first-child, li p:first-child, td p:first-child, th p:first-child { margin-top: 0px } p.caption { @@ -195,8 +208,11 @@ span.option-argument { span.problematic { color: red } -table.citation { - margin-bottom: 1em } +table { + margin-top: 0.5em ; + margin-bottom: 0.5em } -table.footnote { - margin-bottom: 1em } +td, th { + padding-left: 0.5em ; + padding-right: 0.5em ; + vertical-align: baseline } -- cgit v1.2.1 From 18fba0d32c5d883296ddb64ee8ad6dc9fa1ddcd2 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 24 Jul 2002 01:51:41 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@364 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index dc8881606..a9bd01a18 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -94,10 +94,6 @@ ol.lowerroman { ol.upperroman { list-style: upper-roman } -/*dd p:first-child, li p:first-child, td p:first-child, th p:first-child { - margin-top: 0 ; - padding-top: 0 } -*/ p.caption { font-style: italic } -- cgit v1.2.1 From 880c53928e14b1c38276722cb82a60e1c6dd10f8 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 25 Jul 2002 01:52:07 +0000 Subject: updates & improvements git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@370 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 11 +++++++---- tools/stylesheets/pep.css | 15 +++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index a9bd01a18..8d880c7cb 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -15,6 +15,13 @@ a.footnote-reference { a.target { color: blue } +h1 a, h2 a, h3 a, h4 a, h5 a, h6 a { + text-decoration: none ; + color: black } + +dd { + margin-bottom: 0.5em } + div.abstract { margin: 2em 5em } @@ -63,10 +70,6 @@ div.system-message p.system-message-title { div.topic { margin: 2em } -h1 a, h2 a, h3 a, h4 a, h5 a, h6 a { - text-decoration: none ; - color: black } - h1.title { text-align: center } diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css index 53b67b303..3a41e6b58 100644 --- a/tools/stylesheets/pep.css +++ b/tools/stylesheets/pep.css @@ -59,8 +59,8 @@ body { margin-bottom: 1em ; padding: 0px } -td.num { - text-align: right } +dd { + margin-bottom: 0.5em } div.section { margin-left: 1em ; @@ -148,7 +148,7 @@ h6 { .section hr { width: 75% } -ol, ul { +ol.simple, ul.simple { margin-bottom: 1em } ol.arabic { @@ -166,9 +166,6 @@ ol.lowerroman { ol.upperroman { list-style: upper-roman } -dd p:first-child, li p:first-child, td p:first-child, th p:first-child { - margin-top: 0px } - p.caption { font-style: italic } @@ -176,6 +173,9 @@ p.credits { font-style: italic ; font-size: smaller } +p.first { + margin-top: 0 } + p.label { white-space: nowrap } @@ -212,6 +212,9 @@ table { margin-top: 0.5em ; margin-bottom: 0.5em } +td.num { + text-align: right } + td, th { padding-left: 0.5em ; padding-right: 0.5em ; -- cgit v1.2.1 From c1cdf743e8823711597a7a0ed47822af56c030e2 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 25 Jul 2002 01:55:51 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@371 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/docutils-xml.py | 11 +++++------ tools/html.py | 11 +++++------ tools/pep.py | 9 +++++---- tools/publish.py | 11 +++++------ 4 files changed, 20 insertions(+), 22 deletions(-) (limited to 'tools') diff --git a/tools/docutils-xml.py b/tools/docutils-xml.py index 9269376bf..72f72ca86 100755 --- a/tools/docutils-xml.py +++ b/tools/docutils-xml.py @@ -7,17 +7,16 @@ :Date: $Date$ :Copyright: This module has been placed in the public domain. -A minimal front-end to the Docutils Publisher, producing Docutils XML. +A minimal front end to the Docutils Publisher, producing Docutils XML. """ import locale locale.setlocale(locale.LC_ALL, '') -from docutils.core import publish +from docutils.core import publish, default_description -usage = '%prog [options] [source [destination]]' -description = ('Generate Docutils XML from standalone reStructuredText ' - 'sources.') +description = ('Generates Docutils-native XML from standalone ' + 'reStructuredText sources. ' + default_description) -publish(writer_name='xml', usage=usage, description=description) +publish(writer_name='xml', description=description) diff --git a/tools/html.py b/tools/html.py index c1c29b2b6..a79aefca8 100755 --- a/tools/html.py +++ b/tools/html.py @@ -7,17 +7,16 @@ :Date: $Date$ :Copyright: This module has been placed in the public domain. -A minimal front-end to the Docutils Publisher, producing HTML. +A minimal front end to the Docutils Publisher, producing HTML. """ import locale locale.setlocale(locale.LC_ALL, '') -from docutils.core import publish +from docutils.core import publish, default_description -usage = '%prog [options] [source [destination]]' -description = ('Generate HTML documents from standalone reStructuredText ' - 'sources.') +description = ('Generates (X)HTML documents from standalone reStructuredText ' + 'sources. ' + default_description) -publish(writer_name='html', usage=usage, description=description) +publish(writer_name='html', description=description) diff --git a/tools/pep.py b/tools/pep.py index acaab10c4..837221495 100755 --- a/tools/pep.py +++ b/tools/pep.py @@ -7,16 +7,17 @@ :Date: $Date$ :Copyright: This module has been placed in the public domain. -A minimal front-end to the Docutils Publisher, producing HTML from PEP +A minimal front end to the Docutils Publisher, producing HTML from PEP (Python Enhancement Proposal) documents. """ import locale locale.setlocale(locale.LC_ALL, '') -from docutils.core import publish +from docutils.core import publish, default_description -usage = 'usage:\n %prog [options] [source [destination]]' +description = ('Generates (X)HTML from reStructuredText-format PEP files. ' + + default_description) -publish(reader_name='pep', writer_name='pep_html', usage=usage) +publish(reader_name='pep', writer_name='pep_html', description=description) diff --git a/tools/publish.py b/tools/publish.py index 6e814ea67..edd643b04 100755 --- a/tools/publish.py +++ b/tools/publish.py @@ -7,17 +7,16 @@ :Date: $Date$ :Copyright: This module has been placed in the public domain. -A minimal front-end to the Docutils Publisher, producing pseudo-XML. +A minimal front end to the Docutils Publisher, producing pseudo-XML. """ import locale locale.setlocale(locale.LC_ALL, '') -from docutils.core import publish +from docutils.core import publish, default_description -usage = '%prog [options] [source [destination]]' -description = ('Generate pseudo-XML from standalone reStructuredText sources ' - '(for testing purposes).') +description = ('Generates pseudo-XML from standalone reStructuredText ' + 'sources (for testing purposes). ' + default_description) -publish(usage=usage, description=description) +publish(description=description) -- cgit v1.2.1 From f03140adb17f496124ff185331d2ab204eccb4fa Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 27 Jul 2002 03:52:46 +0000 Subject: Added a second command-line argument (output file); cleaned up. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@380 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/quicktest.py | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'tools') diff --git a/tools/quicktest.py b/tools/quicktest.py index 9517b95cc..133cfc815 100755 --- a/tools/quicktest.py +++ b/tools/quicktest.py @@ -26,9 +26,11 @@ quicktest.py: quickly test the restructuredtext parser. Usage:: - quicktest.py [options] [filename] + quicktest.py [options] [ []] -``filename`` is the name of the file to use as input (default is stdin). +``source`` is the name of the file to use as input (default is stdin). +``destination`` is the name of the file to create as output (default is +stdout). Options: """ @@ -38,8 +40,8 @@ options = [('pretty', 'p', ('test', 't', 'output test-ready data (input & expected output, ' 'ready to be copied to a parser test module)'), ('rawxml', 'r', 'output raw XML'), - ('styledxml=', 's', 'output raw XML with XSL style sheet reference ' - '(filename supplied in the option argument)'), + ('styledxml=', 's', 'output raw XML with XSL style sheet ' + 'reference (filename supplied in the option argument)'), ('xml', 'x', 'output pretty XML (indented)'), ('attributes', '', 'dump document attributes after processing'), ('debug', 'd', 'debug mode (lots of output)'), @@ -74,8 +76,8 @@ def _styledxml(input, document, optargs): docnode = document.asdom().childNodes[0] return '%s\n%s\n%s' % ( '', - '' % optargs['styledxml'], - docnode.toxml()) + '' + % optargs['styledxml'], docnode.toxml()) def _prettyxml(input, document, optargs): return document.asdom().toprettyxml(' ', '\n') @@ -96,7 +98,7 @@ def _test(input, document, optargs): def escape(text): """ - Return `text` in a form compatible with triple-double-quoted Python strings. + Return `text` in triple-double-quoted Python string form. """ text = text.replace('\\', '\\\\') # escape backslashes text = text.replace('"""', '""\\"') # break up triple-double-quotes @@ -154,33 +156,36 @@ def posixGetArgs(argv): optargs['debug'] = 1 else: raise getopt.GetoptError, "getopt should have saved us!" - if len(args) > 1: - print "Only one file at a time, thanks." + if len(args) > 2: + print 'Maximum 2 arguments allowed.' usage() sys.exit(1) - if len(args) == 1: - inputFile = open(args[0]) - else: - inputFile = sys.stdin - return inputFile, outputFormat, optargs + inputFile = sys.stdin + outputFile = sys.stdout + if args: + inputFile = open(args.pop(0)) + if args: + outputFile = open(args.pop(0), 'w') + return inputFile, outputFile, outputFormat, optargs def macGetArgs(): import EasyDialogs EasyDialogs.Message("""\ -In the following window, please: +Use the next dialog to build a command line: -1. Choose an output format from the "Option" list. -2. Click "Add" (if you don't, the default format will - be "pretty"). -3. Click "Add existing file..." and choose an input file. -4. Click "OK".""") +1. Choose an output format from the [Option] list +2. Click [Add] +3. Choose an input file: [Add existing file...] +4. Save the output: [Add new file...] +5. [OK]""") optionlist = [(longopt, description) for (longopt, shortopt, description) in options] - argv = EasyDialogs.GetArgv(optionlist=optionlist, addnewfile=0, addfolder=0) + argv = EasyDialogs.GetArgv(optionlist=optionlist, addfolder=0) return posixGetArgs(argv) def main(): - inputFile, outputFormat, optargs = getArgs() # process cmdline arguments + # process cmdline arguments: + inputFile, outputFile, outputFormat, optargs = getArgs() options = OptionParser().get_default_values() options.debug = optargs['debug'] parser = Parser() @@ -188,7 +193,7 @@ def main(): document = new_document(options) parser.parse(input, document) output = format(outputFormat, input, document, optargs) - print output, + outputFile.write(output) if optargs['attributes']: import pprint pprint.pprint(document.__dict__) -- cgit v1.2.1 From 983fbe0421320e73abaf91159e3eac91db386a2e Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 27 Jul 2002 04:33:42 +0000 Subject: Added a style for dedications. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@385 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index 8d880c7cb..495188af2 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -47,6 +47,15 @@ div.note p.admonition-title, div.tip p.admonition-title { font-weight: bold ; font-family: sans-serif } +div.dedication { + margin: 2em 5em ; + text-align: center ; + font-style: italic } + +div.dedication p.topic-title { + font-weight: bold ; + font-style: normal } + div.figure { margin-left: 2em } -- cgit v1.2.1 From ee4147188574574db105b733162e3ce6c854555e Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 27 Jul 2002 14:56:03 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@390 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 2 +- tools/stylesheets/pep.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index 495188af2..a7842ed3c 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -15,7 +15,7 @@ a.footnote-reference { a.target { color: blue } -h1 a, h2 a, h3 a, h4 a, h5 a, h6 a { +a.toc-backref { text-decoration: none ; color: black } diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css index 3a41e6b58..601872253 100644 --- a/tools/stylesheets/pep.css +++ b/tools/stylesheets/pep.css @@ -50,7 +50,7 @@ a.footnote-reference { a.target { color: blue } -h1 a, h2 a, h3 a, h4 a, h5 a, h6 a { +a.toc-backref { text-decoration: none ; color: black } -- cgit v1.2.1 From 1cc7535a35c2fc5cd335e6c91aad7226f47ddb24 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 27 Jul 2002 15:08:43 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@392 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/pep.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css index 601872253..a38cb1d61 100644 --- a/tools/stylesheets/pep.css +++ b/tools/stylesheets/pep.css @@ -98,7 +98,7 @@ div.figure { div.footer, div.header { font-size: smaller } -div.footer p { +div.footer { margin-left: 1em ; margin-right: 1em } -- cgit v1.2.1 From 52307a7656fe38d3f35126a9bd90170e4fd10912 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 28 Jul 2002 17:20:00 +0000 Subject: Source & destination paths now returned inside option values object. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@397 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep2html.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/pep2html.py b/tools/pep2html.py index d5d3221d0..49d925b37 100755 --- a/tools/pep2html.py +++ b/tools/pep2html.py @@ -273,7 +273,8 @@ def fix_rst_pep(infile, outfile): pub.set_reader(reader_name='pep', parser_name='restructuredtext', parser=None) pub.set_writer(writer_name='pep_html') - options = pub.set_options(generator=1, datestamp='%Y-%m-%d %H:%M UTC') + options = pub.set_options(source=infile.name, destination=outfile.name, + generator=1, datestamp='%Y-%m-%d %H:%M UTC') pub.source = io.FileIO(options, source=infile, source_path=infile.name) pub.destination = io.FileIO(options, destination=outfile, destination_path=outfile.name) -- cgit v1.2.1 From 9d05481bb58063c956fc9c9bf910ee4ef7956b14 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 28 Jul 2002 18:51:20 +0000 Subject: Moved from spec/ to tools/, since that's where processing is done now. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@407 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/docutils.conf | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tools/docutils.conf (limited to 'tools') diff --git a/tools/docutils.conf b/tools/docutils.conf new file mode 100644 index 000000000..5d53f9b7d --- /dev/null +++ b/tools/docutils.conf @@ -0,0 +1,6 @@ +[options] + +# These entries affect reStructuredText-style PEPs: +pep-stylesheet: stylesheets/pep.css +python-home: http://www.python.org +no-random: 1 -- cgit v1.2.1 From 22cd52f0533d812aa24cdc92226e148adf9d168e Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 28 Jul 2002 19:55:59 +0000 Subject: Made footer options persistent. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@410 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/docutils.conf | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tools') diff --git a/tools/docutils.conf b/tools/docutils.conf index 5d53f9b7d..88838eac6 100644 --- a/tools/docutils.conf +++ b/tools/docutils.conf @@ -1,5 +1,10 @@ [options] +# These entries affect all processing: +source-link: 1 +datestamp: %%Y-%%m-%%d %%H:%%M UTC +generator: 1 + # These entries affect reStructuredText-style PEPs: pep-stylesheet: stylesheets/pep.css python-home: http://www.python.org -- cgit v1.2.1 From 77eae9bf49c5f60bd96f133b02499dc6034f25d0 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 28 Jul 2002 20:00:56 +0000 Subject: Single "%" is OK git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@412 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/docutils.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/docutils.conf b/tools/docutils.conf index 88838eac6..26ddddb5c 100644 --- a/tools/docutils.conf +++ b/tools/docutils.conf @@ -2,7 +2,7 @@ # These entries affect all processing: source-link: 1 -datestamp: %%Y-%%m-%%d %%H:%%M UTC +datestamp: %Y-%m-%d %H:%M UTC generator: 1 # These entries affect reStructuredText-style PEPs: -- cgit v1.2.1 From 777adc1e1ebbcef09ddf6c07ed2e2c7ab607a334 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 31 Jul 2002 01:41:46 +0000 Subject: updated for improved front-end handling git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@423 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/docutils.conf | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools') diff --git a/tools/docutils.conf b/tools/docutils.conf index 26ddddb5c..4dfabae6e 100644 --- a/tools/docutils.conf +++ b/tools/docutils.conf @@ -5,7 +5,11 @@ source-link: 1 datestamp: %Y-%m-%d %H:%M UTC generator: 1 +# These entries affect HTML output: +stylesheet: default.css + # These entries affect reStructuredText-style PEPs: +pep-template: pep-html-template pep-stylesheet: stylesheets/pep.css python-home: http://www.python.org no-random: 1 -- cgit v1.2.1 From 9e2088dd544b377896ec7c893212cd6f0aa6422d Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 31 Jul 2002 01:42:43 +0000 Subject: made importable (for RST PEP handling) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@424 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep2html.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/pep2html.py b/tools/pep2html.py index 49d925b37..c4b52d47b 100755 --- a/tools/pep2html.py +++ b/tools/pep2html.py @@ -267,14 +267,21 @@ def fixfile(infile, outfile): print >> outfile, '' +docutils_options = None + def fix_rst_pep(infile, outfile): from docutils import core, io pub = core.Publisher() pub.set_reader(reader_name='pep', parser_name='restructuredtext', parser=None) pub.set_writer(writer_name='pep_html') - options = pub.set_options(source=infile.name, destination=outfile.name, - generator=1, datestamp='%Y-%m-%d %H:%M UTC') + if docutils_options: + options = docutils_options + pub.options = options + else: + options = pub.set_options() + options._source = infile.name + options._destination = outfile.name pub.source = io.FileIO(options, source=infile, source_path=infile.name) pub.destination = io.FileIO(options, destination=outfile, destination_path=outfile.name) @@ -287,8 +294,8 @@ def check_rst_pep(infile): """ Check if `infile` is a reStructuredText PEP. Return 1 for yes, 0 for no. - If the result is indeterminate, return None. Reset `infile` to the - beginning. + If the result is indeterminate, return None. When the check is complete, + rewind `infile` to the beginning. """ result = None underline_match = underline.match -- cgit v1.2.1 From b2f915ec237d6c11b15261ae4e0b70baf2bb53bf Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 31 Jul 2002 01:54:01 +0000 Subject: Added to project; batch-generates .html from all the .txt files in directories and subdirectories. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@426 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/buildhtml.py | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100755 tools/buildhtml.py (limited to 'tools') diff --git a/tools/buildhtml.py b/tools/buildhtml.py new file mode 100755 index 000000000..310790899 --- /dev/null +++ b/tools/buildhtml.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python + +""" +Generates .html from all the .txt files in a directory. + +Ordinary .txt files are understood to be standalone reStructuredText. +Files named ``pep-*.txt`` are interpreted as PEPs (either old-style or +new reStructuredText PEPs). +""" +# Once PySource is here, build .html from .py as well. + +__docformat__ = 'reStructuredText' + + +import sys +import os +import os.path +import copy +from docutils import core, frontend, io +from docutils.parsers import rst +from docutils.readers import pep +from docutils.writers import pep_html +import pep2html + + +usage = '%prog [options] [ ...]' +description = ('Generates .html from all the .txt files (including PEPs) ' + 'in each (default is the current directory).') + + +class OptionSpec: + + """ + Command-line options for the ``buildhtml.py`` front end. + """ + + # Can't be included in OptionParser below because we don't want to + # override the base class. + cmdline_options = ( + 'Build-HTML Options', + None, + (('Recursively scan subdirectories for files to process. This is ' + 'the default.', + ['--recurse'], {'action': 'store_true', 'default': 1}), + ('Do not scan subdirectories for files to process.', + ['--local'], {'dest': 'recurse', 'action': 'store_false'}),)) + + +class OptionParser(frontend.OptionParser): + + """ + Command-line option processing for the ``buildhtml.py`` front end. + """ + + def check_values(self, values, args): + frontend.OptionParser.check_values(self, values, args) + values._source = None + return values + + def check_args(self, args): + source = destination = None + if args: + self.values._directories = args + else: + self.values._directories = [os.getcwd()] + return source, destination + + +class Builder: + + def run(self, directory=None, recurse=1): + self.process_command_line() + initial_options = self.get_options() + recurse = recurse and initial_options.recurse + self.setup_html_publisher() + if directory: + self.directories = [directory] + elif self.cmdline_options._directories: + self.directories = self.cmdline_options._directories + else: + self.directories = [os.getcwd()] + for directory in self.directories: + os.path.walk(directory, self.visit, recurse) + + def visit(self, recurse, directory, names): + print >>sys.stderr, '/// Processing directory:', directory + sys.stderr.flush() + options = self.get_options(directory) + peps_found = 0 + for name in names: + if name.endswith('.txt'): + if name.startswith('pep-'): + peps_found = 1 + else: + self.process_txt(directory, name, options) + if peps_found: + self.process_peps(options, directory) + if not recurse: + del names[:] + + def process_txt(self, directory, name, options): + options._source = os.path.normpath(os.path.join(directory, name)) + options._destination = options._source[:-4]+'.html' + self.pub.options = options + print >>sys.stderr, ' ::: Processing .txt:', name + sys.stderr.flush() + self.pub.source = io.FileIO(options, source_path=options._source) + self.pub.destination = io.FileIO( + options, destination_path=options._destination) + self.pub.publish() + + def process_peps(self, options, directory): + old_directory = os.getcwd() + os.chdir(directory) + print >>sys.stderr, ' ::: Processing PEPs:' + sys.stderr.flush() + pep2html.docutils_options = options + pep2html.main() + os.chdir(old_directory) + + def process_command_line(self): + option_parser = OptionParser( + components=(OptionSpec, pep.Reader, rst.Parser, pep_html.Writer), + usage=usage, description=description) + self.option_defaults = option_parser.get_default_values() + config_parser = frontend.ConfigParser() + config_parser.read_standard_files() + self.config_settings = config_parser.get_section('options') + frontend.make_paths_absolute(self.config_settings) + self.cmdline_options = option_parser.parse_args( + values=frontend.Values()) # no defaults + # Clear out the command-line options so pep2html doesn't see them: + del sys.argv[1:] + + def get_options(self, directory=None): + """ + Return an option values object, from multiple sources. + + Copy the option defaults, overlay the startup config file settings, + then the local config file settings, then the command-line options. + Assumes the current directory has been set. + """ + options = copy.deepcopy(self.option_defaults) + options.__dict__.update(self.config_settings) + if directory: + config_parser = frontend.ConfigParser() + config_parser.read(os.path.join(directory, 'docutils.conf')) + local_config = config_parser.get_section('options') + frontend.make_paths_absolute(local_config, directory) + options.__dict__.update(local_config) + options.__dict__.update(self.cmdline_options.__dict__) + return options + + def setup_html_publisher(self): + pub = core.Publisher() + pub.set_reader(reader_name='standalone', + parser_name='restructuredtext', parser=None) + pub.set_writer(writer_name='html') + self.pub = pub + + +if __name__ == "__main__": + Builder().run() -- cgit v1.2.1 From e8d4289000e3ab952b2e465f462b89deed93bbdb Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 31 Jul 2002 02:21:49 +0000 Subject: be gone! git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@429 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/buildhtml.py | 163 ----------------------------------------------------- 1 file changed, 163 deletions(-) delete mode 100755 tools/buildhtml.py (limited to 'tools') diff --git a/tools/buildhtml.py b/tools/buildhtml.py deleted file mode 100755 index 310790899..000000000 --- a/tools/buildhtml.py +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python - -""" -Generates .html from all the .txt files in a directory. - -Ordinary .txt files are understood to be standalone reStructuredText. -Files named ``pep-*.txt`` are interpreted as PEPs (either old-style or -new reStructuredText PEPs). -""" -# Once PySource is here, build .html from .py as well. - -__docformat__ = 'reStructuredText' - - -import sys -import os -import os.path -import copy -from docutils import core, frontend, io -from docutils.parsers import rst -from docutils.readers import pep -from docutils.writers import pep_html -import pep2html - - -usage = '%prog [options] [ ...]' -description = ('Generates .html from all the .txt files (including PEPs) ' - 'in each (default is the current directory).') - - -class OptionSpec: - - """ - Command-line options for the ``buildhtml.py`` front end. - """ - - # Can't be included in OptionParser below because we don't want to - # override the base class. - cmdline_options = ( - 'Build-HTML Options', - None, - (('Recursively scan subdirectories for files to process. This is ' - 'the default.', - ['--recurse'], {'action': 'store_true', 'default': 1}), - ('Do not scan subdirectories for files to process.', - ['--local'], {'dest': 'recurse', 'action': 'store_false'}),)) - - -class OptionParser(frontend.OptionParser): - - """ - Command-line option processing for the ``buildhtml.py`` front end. - """ - - def check_values(self, values, args): - frontend.OptionParser.check_values(self, values, args) - values._source = None - return values - - def check_args(self, args): - source = destination = None - if args: - self.values._directories = args - else: - self.values._directories = [os.getcwd()] - return source, destination - - -class Builder: - - def run(self, directory=None, recurse=1): - self.process_command_line() - initial_options = self.get_options() - recurse = recurse and initial_options.recurse - self.setup_html_publisher() - if directory: - self.directories = [directory] - elif self.cmdline_options._directories: - self.directories = self.cmdline_options._directories - else: - self.directories = [os.getcwd()] - for directory in self.directories: - os.path.walk(directory, self.visit, recurse) - - def visit(self, recurse, directory, names): - print >>sys.stderr, '/// Processing directory:', directory - sys.stderr.flush() - options = self.get_options(directory) - peps_found = 0 - for name in names: - if name.endswith('.txt'): - if name.startswith('pep-'): - peps_found = 1 - else: - self.process_txt(directory, name, options) - if peps_found: - self.process_peps(options, directory) - if not recurse: - del names[:] - - def process_txt(self, directory, name, options): - options._source = os.path.normpath(os.path.join(directory, name)) - options._destination = options._source[:-4]+'.html' - self.pub.options = options - print >>sys.stderr, ' ::: Processing .txt:', name - sys.stderr.flush() - self.pub.source = io.FileIO(options, source_path=options._source) - self.pub.destination = io.FileIO( - options, destination_path=options._destination) - self.pub.publish() - - def process_peps(self, options, directory): - old_directory = os.getcwd() - os.chdir(directory) - print >>sys.stderr, ' ::: Processing PEPs:' - sys.stderr.flush() - pep2html.docutils_options = options - pep2html.main() - os.chdir(old_directory) - - def process_command_line(self): - option_parser = OptionParser( - components=(OptionSpec, pep.Reader, rst.Parser, pep_html.Writer), - usage=usage, description=description) - self.option_defaults = option_parser.get_default_values() - config_parser = frontend.ConfigParser() - config_parser.read_standard_files() - self.config_settings = config_parser.get_section('options') - frontend.make_paths_absolute(self.config_settings) - self.cmdline_options = option_parser.parse_args( - values=frontend.Values()) # no defaults - # Clear out the command-line options so pep2html doesn't see them: - del sys.argv[1:] - - def get_options(self, directory=None): - """ - Return an option values object, from multiple sources. - - Copy the option defaults, overlay the startup config file settings, - then the local config file settings, then the command-line options. - Assumes the current directory has been set. - """ - options = copy.deepcopy(self.option_defaults) - options.__dict__.update(self.config_settings) - if directory: - config_parser = frontend.ConfigParser() - config_parser.read(os.path.join(directory, 'docutils.conf')) - local_config = config_parser.get_section('options') - frontend.make_paths_absolute(local_config, directory) - options.__dict__.update(local_config) - options.__dict__.update(self.cmdline_options.__dict__) - return options - - def setup_html_publisher(self): - pub = core.Publisher() - pub.set_reader(reader_name='standalone', - parser_name='restructuredtext', parser=None) - pub.set_writer(writer_name='html') - self.pub = pub - - -if __name__ == "__main__": - Builder().run() -- cgit v1.2.1 From 8225e8771b884608aed60523eef8daa2981927e5 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 31 Jul 2002 02:24:34 +0000 Subject: give up git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@430 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/buildhtml.py | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100755 tools/buildhtml.py (limited to 'tools') diff --git a/tools/buildhtml.py b/tools/buildhtml.py new file mode 100755 index 000000000..310790899 --- /dev/null +++ b/tools/buildhtml.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python + +""" +Generates .html from all the .txt files in a directory. + +Ordinary .txt files are understood to be standalone reStructuredText. +Files named ``pep-*.txt`` are interpreted as PEPs (either old-style or +new reStructuredText PEPs). +""" +# Once PySource is here, build .html from .py as well. + +__docformat__ = 'reStructuredText' + + +import sys +import os +import os.path +import copy +from docutils import core, frontend, io +from docutils.parsers import rst +from docutils.readers import pep +from docutils.writers import pep_html +import pep2html + + +usage = '%prog [options] [ ...]' +description = ('Generates .html from all the .txt files (including PEPs) ' + 'in each (default is the current directory).') + + +class OptionSpec: + + """ + Command-line options for the ``buildhtml.py`` front end. + """ + + # Can't be included in OptionParser below because we don't want to + # override the base class. + cmdline_options = ( + 'Build-HTML Options', + None, + (('Recursively scan subdirectories for files to process. This is ' + 'the default.', + ['--recurse'], {'action': 'store_true', 'default': 1}), + ('Do not scan subdirectories for files to process.', + ['--local'], {'dest': 'recurse', 'action': 'store_false'}),)) + + +class OptionParser(frontend.OptionParser): + + """ + Command-line option processing for the ``buildhtml.py`` front end. + """ + + def check_values(self, values, args): + frontend.OptionParser.check_values(self, values, args) + values._source = None + return values + + def check_args(self, args): + source = destination = None + if args: + self.values._directories = args + else: + self.values._directories = [os.getcwd()] + return source, destination + + +class Builder: + + def run(self, directory=None, recurse=1): + self.process_command_line() + initial_options = self.get_options() + recurse = recurse and initial_options.recurse + self.setup_html_publisher() + if directory: + self.directories = [directory] + elif self.cmdline_options._directories: + self.directories = self.cmdline_options._directories + else: + self.directories = [os.getcwd()] + for directory in self.directories: + os.path.walk(directory, self.visit, recurse) + + def visit(self, recurse, directory, names): + print >>sys.stderr, '/// Processing directory:', directory + sys.stderr.flush() + options = self.get_options(directory) + peps_found = 0 + for name in names: + if name.endswith('.txt'): + if name.startswith('pep-'): + peps_found = 1 + else: + self.process_txt(directory, name, options) + if peps_found: + self.process_peps(options, directory) + if not recurse: + del names[:] + + def process_txt(self, directory, name, options): + options._source = os.path.normpath(os.path.join(directory, name)) + options._destination = options._source[:-4]+'.html' + self.pub.options = options + print >>sys.stderr, ' ::: Processing .txt:', name + sys.stderr.flush() + self.pub.source = io.FileIO(options, source_path=options._source) + self.pub.destination = io.FileIO( + options, destination_path=options._destination) + self.pub.publish() + + def process_peps(self, options, directory): + old_directory = os.getcwd() + os.chdir(directory) + print >>sys.stderr, ' ::: Processing PEPs:' + sys.stderr.flush() + pep2html.docutils_options = options + pep2html.main() + os.chdir(old_directory) + + def process_command_line(self): + option_parser = OptionParser( + components=(OptionSpec, pep.Reader, rst.Parser, pep_html.Writer), + usage=usage, description=description) + self.option_defaults = option_parser.get_default_values() + config_parser = frontend.ConfigParser() + config_parser.read_standard_files() + self.config_settings = config_parser.get_section('options') + frontend.make_paths_absolute(self.config_settings) + self.cmdline_options = option_parser.parse_args( + values=frontend.Values()) # no defaults + # Clear out the command-line options so pep2html doesn't see them: + del sys.argv[1:] + + def get_options(self, directory=None): + """ + Return an option values object, from multiple sources. + + Copy the option defaults, overlay the startup config file settings, + then the local config file settings, then the command-line options. + Assumes the current directory has been set. + """ + options = copy.deepcopy(self.option_defaults) + options.__dict__.update(self.config_settings) + if directory: + config_parser = frontend.ConfigParser() + config_parser.read(os.path.join(directory, 'docutils.conf')) + local_config = config_parser.get_section('options') + frontend.make_paths_absolute(local_config, directory) + options.__dict__.update(local_config) + options.__dict__.update(self.cmdline_options.__dict__) + return options + + def setup_html_publisher(self): + pub = core.Publisher() + pub.set_reader(reader_name='standalone', + parser_name='restructuredtext', parser=None) + pub.set_writer(writer_name='html') + self.pub = pub + + +if __name__ == "__main__": + Builder().run() -- cgit v1.2.1 From e3645352686aa984895833ad4c300e570c506ee8 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 2 Aug 2002 03:27:50 +0000 Subject: Made ``argv`` a parameter to ``main()``. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@437 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep2html.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/pep2html.py b/tools/pep2html.py index c4b52d47b..b03a6019a 100755 --- a/tools/pep2html.py +++ b/tools/pep2html.py @@ -397,16 +397,19 @@ def browse_remote(pep): webbrowser.open(url) -def main(): +def main(argv=None): # defaults update = 0 username = '' verbose = 1 browse = 0 + if argv is None: + argv = sys.argv[1:] + try: opts, args = getopt.getopt( - sys.argv[1:], 'bihqu:', + argv, 'bihqu:', ['browse', 'install', 'help', 'quiet', 'user=']) except getopt.error, msg: usage(1, msg) -- cgit v1.2.1 From 7991633913061d37950de322af8b9367f26e6fdc Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 2 Aug 2002 03:30:22 +0000 Subject: Added "--silent" option. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@438 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/buildhtml.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/buildhtml.py b/tools/buildhtml.py index 310790899..97b1bf000 100755 --- a/tools/buildhtml.py +++ b/tools/buildhtml.py @@ -43,7 +43,9 @@ class OptionSpec: 'the default.', ['--recurse'], {'action': 'store_true', 'default': 1}), ('Do not scan subdirectories for files to process.', - ['--local'], {'dest': 'recurse', 'action': 'store_false'}),)) + ['--local'], {'dest': 'recurse', 'action': 'store_false'}), + ('Work silently (no progress messages). Independent of "--quiet".', + ['--silent'], {'action': 'store_true'}),)) class OptionParser(frontend.OptionParser): @@ -83,9 +85,10 @@ class Builder: os.path.walk(directory, self.visit, recurse) def visit(self, recurse, directory, names): - print >>sys.stderr, '/// Processing directory:', directory - sys.stderr.flush() options = self.get_options(directory) + if not options.silent: + print >>sys.stderr, '/// Processing directory:', directory + sys.stderr.flush() peps_found = 0 for name in names: if name.endswith('.txt'): @@ -102,8 +105,9 @@ class Builder: options._source = os.path.normpath(os.path.join(directory, name)) options._destination = options._source[:-4]+'.html' self.pub.options = options - print >>sys.stderr, ' ::: Processing .txt:', name - sys.stderr.flush() + if not options.silent: + print >>sys.stderr, ' ::: Processing .txt:', name + sys.stderr.flush() self.pub.source = io.FileIO(options, source_path=options._source) self.pub.destination = io.FileIO( options, destination_path=options._destination) @@ -112,10 +116,14 @@ class Builder: def process_peps(self, options, directory): old_directory = os.getcwd() os.chdir(directory) - print >>sys.stderr, ' ::: Processing PEPs:' - sys.stderr.flush() + if options.silent: + argv = ['-q'] + else: + print >>sys.stderr, ' ::: Processing PEPs:' + sys.stderr.flush() + argv = [] pep2html.docutils_options = options - pep2html.main() + pep2html.main(argv) os.chdir(old_directory) def process_command_line(self): @@ -129,8 +137,6 @@ class Builder: frontend.make_paths_absolute(self.config_settings) self.cmdline_options = option_parser.parse_args( values=frontend.Values()) # no defaults - # Clear out the command-line options so pep2html doesn't see them: - del sys.argv[1:] def get_options(self, directory=None): """ -- cgit v1.2.1 From 3876764b213354e4a6e86017ca3fc7d12fadf235 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 3 Aug 2002 20:23:00 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@452 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/default.css | 4 ++-- tools/stylesheets/pep.css | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css index a7842ed3c..d1dd52155 100644 --- a/tools/stylesheets/default.css +++ b/tools/stylesheets/default.css @@ -167,9 +167,9 @@ td, th { padding-right: 0.5em ; vertical-align: baseline } -td.docinfo-name { +th.docinfo-name { font-weight: bold ; text-align: right } -td.field-name { +th.field-name { font-weight: bold } diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css index a38cb1d61..0af6d129d 100644 --- a/tools/stylesheets/pep.css +++ b/tools/stylesheets/pep.css @@ -36,7 +36,7 @@ Default cascading style sheet for the PEP HTML output of Docutils. .rfc2822 div.field-body { text-align: left } -.rfc2822 td.field-name { +.rfc2822 th.field-name { text-align: right ; font-family: sans-serif ; padding-right: 0.5em ; @@ -219,3 +219,6 @@ td, th { padding-left: 0.5em ; padding-right: 0.5em ; vertical-align: baseline } + +th.field-name { + font-weight: bold } -- cgit v1.2.1 From a55a4fb8cf2a716bfecabe1e292fa945a4d3b06a Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 4 Aug 2002 04:10:07 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@453 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/stylesheets/pep.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css index 0af6d129d..8c6a2424f 100644 --- a/tools/stylesheets/pep.css +++ b/tools/stylesheets/pep.css @@ -33,10 +33,10 @@ Default cascading style sheet for the PEP HTML output of Docutils. margin-right: 0.5em ; margin-bottom: 0em } -.rfc2822 div.field-body { +.rfc2822 td { text-align: left } -.rfc2822 th.field-name { +.rfc2822 th { text-align: right ; font-family: sans-serif ; padding-right: 0.5em ; -- cgit v1.2.1 From 9ce4ad12cb84b65e8c52697119ed2fce6dc3babe Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 4 Aug 2002 20:04:20 +0000 Subject: Merged changes from Python's revision 1.39. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@454 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep2html.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/pep2html.py b/tools/pep2html.py index b03a6019a..9952087d2 100755 --- a/tools/pep2html.py +++ b/tools/pep2html.py @@ -31,6 +31,8 @@ Options: The optional argument `peps' is a list of either pep numbers or .txt files. """ +# Requires Python 2.2 + import sys import os import re @@ -40,6 +42,7 @@ import getopt import errno import random import time +from email.Utils import parseaddr PROGRAM = sys.argv[0] RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html' @@ -64,6 +67,7 @@ fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt)?)|" EMPTYSTRING = '' SPACE = ' ' +COMMASPACE = ', ' @@ -180,19 +184,20 @@ def fixfile(infile, outfile): for k, v in header: if k.lower() in ('author', 'discussions-to'): mailtos = [] - for addr in v.split(): - if '@' in addr: + for part in re.split(',\s*', v): + if '@' in part: + realname, addr = parseaddr(part) if k.lower() == 'discussions-to': m = linkemail(addr, pep) else: m = fixemail(addr, pep) - mailtos.append(m) - elif addr.startswith('http:'): + mailtos.append('%s <%s>' % (realname, m)) + elif part.startswith('http:'): mailtos.append( - '%s' % (addr, addr)) + '%s' % (part, part)) else: - mailtos.append(addr) - v = SPACE.join(mailtos) + mailtos.append(part) + v = COMMASPACE.join(mailtos) elif k.lower() in ('replaces', 'replaced-by'): otherpeps = '' for otherpep in v.split(): -- cgit v1.2.1 From e9989ec41dc36cbef0e6e199ce65d786965643bc Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 5 Aug 2002 19:51:20 +0000 Subject: Added support for "Content-Type:" header & arbitrary PEP formats. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@459 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- tools/pep2html.py | 126 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 56 deletions(-) (limited to 'tools') diff --git a/tools/pep2html.py b/tools/pep2html.py index 9952087d2..28cfd9a0b 100755 --- a/tools/pep2html.py +++ b/tools/pep2html.py @@ -44,6 +44,11 @@ import random import time from email.Utils import parseaddr +try: + import docutils +except ImportError: + docutils = None + PROGRAM = sys.argv[0] RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html' PEPURL = 'pep-%04d.html' @@ -128,8 +133,9 @@ def linkemail(address, pepno): % (parts[0], parts[1], pepno, parts[0], parts[1])) -def fixfile(infile, outfile): - basename = os.path.basename(infile.name) +def fixfile(inpath, input_lines, outfile): + basename = os.path.basename(inpath) + infile = iter(input_lines) # convert plain text pep to minimal XHTML markup print >> outfile, DTD print >> outfile, '' @@ -139,7 +145,10 @@ def fixfile(infile, outfile): pep = "" title = "" while 1: - line = infile.readline() + try: + line = infile.next() + except StopIteration: + break if not line.strip(): break if line[0].strip(): @@ -202,13 +211,13 @@ def fixfile(infile, outfile): otherpeps = '' for otherpep in v.split(): otherpep = int(otherpep) - otherpeps += '%i ' % (otherpep, + otherpeps += '%i ' % (otherpep, otherpep) v = otherpeps elif k.lower() in ('last-modified',): url = PEPCVSURL % int(pep) date = v or time.strftime('%d-%b-%Y', - time.localtime(os.stat(infile.name)[8])) + time.localtime(os.stat(inpath)[8])) v = '%s ' % (url, cgi.escape(date)) else: v = cgi.escape(v) @@ -220,8 +229,9 @@ def fixfile(infile, outfile): print >> outfile, '
    ' need_pre = 1 while 1: - line = infile.readline() - if not line: + try: + line = infile.next() + except StopIteration: break if line[0] == '\f': continue @@ -260,7 +270,7 @@ def fixfile(infile, outfile): print >> outfile, re.sub( parts[-1], url, line, 1), continue - line = fixpat.sub(lambda x, c=infile.name: fixanchor(c, x), line) + line = fixpat.sub(lambda x, c=inpath: fixanchor(c, x), line) if need_pre: print >> outfile, '
    '
                     need_pre = 0
    @@ -273,8 +283,10 @@ def fixfile(infile, outfile):
     
     
     docutils_options = None
    +"""Option value object used by Docutils.  Can be set by the client application
    +when this module is imported."""
     
    -def fix_rst_pep(infile, outfile):
    +def fix_rst_pep(inpath, input_lines, outfile):
         from docutils import core, io
         pub = core.Publisher()
         pub.set_reader(reader_name='pep', parser_name='restructuredtext',
    @@ -285,48 +297,36 @@ def fix_rst_pep(infile, outfile):
             pub.options = options
         else:
             options = pub.set_options()
    -    options._source = infile.name
    +    options._source = inpath
         options._destination = outfile.name
    -    pub.source = io.FileIO(options, source=infile, source_path=infile.name)
    -    pub.destination = io.FileIO(options, destination=outfile,
    -                                destination_path=outfile.name)
    +    pub.source = io.StringIO(
    +        options, source=''.join(input_lines), source_path=inpath)
    +    pub.destination = io.FileIO(
    +        options, destination=outfile, destination_path=outfile.name)
         pub.publish()
     
     
    -underline = re.compile('[!-/:-@[-`{-~]{4,}$')
    -
    -def check_rst_pep(infile):
    +def get_pep_type(input_lines):
         """
    -    Check if `infile` is a reStructuredText PEP.  Return 1 for yes, 0 for no.
    -
    -    If the result is indeterminate, return None.  When the check is complete,
    -    rewind `infile` to the beginning.
    +    Return the Content-Type of the input.  "text/plain" is the default.
    +    Return ``None`` if the input is not a PEP.
         """
    -    result = None
    -    underline_match = underline.match
    -    # Find the end of the RFC 2822 header (first blank line):
    -    while 1:
    -        line = infile.readline().strip()
    +    pep_type = None
    +    for line in input_lines:
    +        line = line.rstrip().lower()
             if not line:
    +            # End of the RFC 2822 header (first blank line).
                 break
    -    # Determine if the PEP is old-style or new (reStructuredText):
    -    while result is None:
    -        line = infile.readline()
    -        if not line:
    +        elif line.startswith('content-type: '):
    +            pep_type = line.split()[1]
                 break
    -        line = line.rstrip()
    -        if len(line.lstrip()) < len(line):
    -            # Indented section; this is an old-style PEP.
    -            result = 0
    -        elif underline_match(line):
    -            # Matched a section header underline;
    -            # this is a reStructuredText PEP.
    -            result = 1
    -    infile.seek(0)
    -    return result
    +        elif line.startswith('pep: '):
    +            # Default PEP type, used if no explicit content-type specified:
    +            pep_type = 'text/plain'
    +    return pep_type
     
     
    -def open_files(inpath, outpath):
    +def get_input_lines(inpath):
         try:
             infile = open(inpath)
         except IOError, e:
    @@ -334,14 +334,10 @@ def open_files(inpath, outpath):
             print >> sys.stderr, 'Error: Skipping missing PEP file:', e.filename
             sys.stderr.flush()
             return None, None
    -    outfile = open(outpath, "w")
    -    return infile, outfile
    -
    -def close_files(infile, outfile):
    +    lines = infile.readlines()
         infile.close()
    -    outfile.close()
    -    os.chmod(outfile.name, 0664)
    -    
    +    return lines
    +
     
     def find_pep(pep_str):
         """Find the .txt file indicated by a cmd line argument"""
    @@ -350,18 +346,35 @@ def find_pep(pep_str):
         num = int(pep_str)
         return "pep-%04d.txt" % num
     
    +PEP_TYPE_DISPATCH = {'text/plain': fixfile,
    +                     'text/x-rst': fix_rst_pep}
    +
     def make_html(inpath, verbose=0):
    +    input_lines = get_input_lines(inpath)
    +    pep_type = get_pep_type(input_lines)
    +    if pep_type is None:
    +        print >> sys.stderr, 'Error: Input file %s is not a PEP.' % inpath
    +        sys.stdout.flush()
    +        return None
    +    elif not PEP_TYPE_DISPATCH.has_key(pep_type):
    +        print >> sys.stderr, ('Error: Unknown PEP type for input file %s: %s'
    +                              % (inpath, pep_type))
    +        sys.stdout.flush()
    +        return None
    +    elif pep_type == 'text/x-rst' and not docutils:
    +        print >> sys.stderr, ('Error: Docutils not present for "%s" PEP file '
    +                              '%s.  See README.txt for installation.'
    +                              % (pep_type, inpath))
    +        sys.stdout.flush()
    +        return None
         outpath = os.path.splitext(inpath)[0] + ".html"
         if verbose:
    -        print inpath, "->", outpath
    +        print inpath, "(%s)" % pep_type, "->", outpath
             sys.stdout.flush()
    -    infile, outfile = open_files(inpath, outpath)
    -    if infile is not None:
    -        if check_rst_pep(infile):
    -            fix_rst_pep(infile, outfile)
    -        else:
    -            fixfile(infile, outfile)
    -        close_files(infile, outfile)
    +    outfile = open(outpath, "w")
    +    PEP_TYPE_DISPATCH[pep_type](inpath, input_lines, outfile)
    +    outfile.close()
    +    os.chmod(outfile.name, 0664)
         return outpath
     
     def push_pep(htmlfiles, txtfiles, username, verbose):
    @@ -438,7 +451,8 @@ def main(argv=None):
                 file = find_pep(pep)
                 peptxt.append(file)
                 newfile = make_html(file, verbose=verbose)
    -            html.append(newfile)
    +            if newfile:
    +                html.append(newfile)
                 if browse and not update:
                     browse_file(pep)
         else:
    -- 
    cgit v1.2.1
    
    
    From 60e31f05a8a0edd5eca8ea046c3ff6a98e46e581 Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Wed, 7 Aug 2002 01:20:34 +0000
    Subject: Fixed nested section margins.  Added style for chunks of inline
     literals.
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@471 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/stylesheets/pep.css | 8 ++++++++
     1 file changed, 8 insertions(+)
    
    (limited to 'tools')
    
    diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css
    index 8c6a2424f..818c4cd20 100644
    --- a/tools/stylesheets/pep.css
    +++ b/tools/stylesheets/pep.css
    @@ -67,6 +67,11 @@ div.section {
       margin-right: 1em ;
       margin-bottom: 1.5em }
     
    +div.section div.section {
    +  margin-left: 0em ;
    +  margin-right: 0em ;
    +  margin-top: 1.5em }
    +
     div.abstract {
       margin: 2em 5em }
     
    @@ -205,6 +210,9 @@ span.interpreted {
     span.option-argument {
       font-style: italic }
     
    +span.pre {
    +  white-space: pre }
    +
     span.problematic {
       color: red }
     
    -- 
    cgit v1.2.1
    
    
    From f5b6a9b7a5bd51366e4878b953bb7cf42b5f1a6e Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Wed, 7 Aug 2002 01:20:52 +0000
    Subject: Added style for chunks of inline literals.
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@472 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/stylesheets/default.css | 3 +++
     1 file changed, 3 insertions(+)
    
    (limited to 'tools')
    
    diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css
    index d1dd52155..6f4cde5b4 100644
    --- a/tools/stylesheets/default.css
    +++ b/tools/stylesheets/default.css
    @@ -144,6 +144,9 @@ span.interpreted {
     span.option-argument {
       font-style: italic }
     
    +span.pre {
    +  white-space: pre }
    +
     span.problematic {
       color: red }
     
    -- 
    cgit v1.2.1
    
    
    From 9eb27da5f41ace80bb1ecd48f6cc5839cd96b6e7 Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Wed, 7 Aug 2002 01:22:54 +0000
    Subject: Linked "Content-Type: text/plain" to PEP 9.  Updated.
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@473 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/pep2html.py | 12 ++++++++----
     1 file changed, 8 insertions(+), 4 deletions(-)
    
    (limited to 'tools')
    
    diff --git a/tools/pep2html.py b/tools/pep2html.py
    index 28cfd9a0b..42328ae9c 100755
    --- a/tools/pep2html.py
    +++ b/tools/pep2html.py
    @@ -207,9 +207,9 @@ def fixfile(inpath, input_lines, outfile):
                     else:
                         mailtos.append(part)
                 v = COMMASPACE.join(mailtos)
    -        elif k.lower() in ('replaces', 'replaced-by'):
    +        elif k.lower() in ('replaces', 'replaced-by', 'requires'):
                 otherpeps = ''
    -            for otherpep in v.split():
    +            for otherpep in re.split(',?\s+', v):
                     otherpep = int(otherpep)
                     otherpeps += '%i ' % (otherpep,
                                                                       otherpep)
    @@ -219,6 +219,10 @@ def fixfile(inpath, input_lines, outfile):
                 date = v or time.strftime('%d-%b-%Y',
                                           time.localtime(os.stat(inpath)[8]))
                 v = '%s ' % (url, cgi.escape(date))
    +        elif k.lower() in ('content-type',):
    +            url = PEPURL % 9
    +            pep_type = v or 'text/plain'
    +            v = '%s ' % (url, cgi.escape(pep_type))
             else:
                 v = cgi.escape(v)
             print >> outfile, '  %s: %s' \
    @@ -318,7 +322,7 @@ def get_pep_type(input_lines):
                 # End of the RFC 2822 header (first blank line).
                 break
             elif line.startswith('content-type: '):
    -            pep_type = line.split()[1]
    +            pep_type = line.split()[1] or 'text/plain'
                 break
             elif line.startswith('pep: '):
                 # Default PEP type, used if no explicit content-type specified:
    @@ -334,7 +338,7 @@ def get_input_lines(inpath):
             print >> sys.stderr, 'Error: Skipping missing PEP file:', e.filename
             sys.stderr.flush()
             return None, None
    -    lines = infile.readlines()
    +    lines = infile.read().splitlines(1) # handles x-platform line endings
         infile.close()
         return lines
     
    -- 
    cgit v1.2.1
    
    
    From 10d83bcc524ddbd5f8c9f7399aca1f8bb8633dc1 Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Thu, 8 Aug 2002 00:27:19 +0000
    Subject: Fixed bug with absolute paths & ``--config``.
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@482 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/buildhtml.py | 1 +
     1 file changed, 1 insertion(+)
    
    (limited to 'tools')
    
    diff --git a/tools/buildhtml.py b/tools/buildhtml.py
    index 97b1bf000..b04f811d1 100755
    --- a/tools/buildhtml.py
    +++ b/tools/buildhtml.py
    @@ -131,6 +131,7 @@ class Builder:
                 components=(OptionSpec, pep.Reader, rst.Parser, pep_html.Writer),
                 usage=usage, description=description)
             self.option_defaults = option_parser.get_default_values()
    +        frontend.make_paths_absolute(self.option_defaults.__dict__)
             config_parser = frontend.ConfigParser()
             config_parser.read_standard_files()
             self.config_settings = config_parser.get_section('options')
    -- 
    cgit v1.2.1
    
    
    From ed4dad1927fd297c6312aacac6e4d1295fe9de63 Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Thu, 8 Aug 2002 00:28:48 +0000
    Subject: Removed margin for first child of table cells.  Right-aligned field
     list names.
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@483 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/stylesheets/default.css |  6 +++++-
     tools/stylesheets/pep.css     | 12 ++++++++----
     2 files changed, 13 insertions(+), 5 deletions(-)
    
    (limited to 'tools')
    
    diff --git a/tools/stylesheets/default.css b/tools/stylesheets/default.css
    index 6f4cde5b4..d160c6b9d 100644
    --- a/tools/stylesheets/default.css
    +++ b/tools/stylesheets/default.css
    @@ -170,9 +170,13 @@ td, th {
       padding-right: 0.5em ;
       vertical-align: baseline }
     
    +td > p:first-child, th > p:first-child {
    +  margin-top: 0em }
    +
     th.docinfo-name {
       font-weight: bold ;
       text-align: right }
     
     th.field-name {
    -  font-weight: bold }
    +  font-weight: bold ;
    +  text-align: right }
    diff --git a/tools/stylesheets/pep.css b/tools/stylesheets/pep.css
    index 818c4cd20..2e0c7865e 100644
    --- a/tools/stylesheets/pep.css
    +++ b/tools/stylesheets/pep.css
    @@ -220,13 +220,17 @@ table {
       margin-top: 0.5em ;
       margin-bottom: 0.5em }
     
    -td.num {
    -  text-align: right }
    -
     td, th {
       padding-left: 0.5em ;
       padding-right: 0.5em ;
       vertical-align: baseline }
     
    +td > :first-child, th > :first-child {
    +  margin-top: 0em }
    +
    +td.num {
    +  text-align: right }
    +
     th.field-name {
    -  font-weight: bold }
    +  font-weight: bold ;
    +  text-align: right }
    -- 
    cgit v1.2.1
    
    
    From af07d173f8976717923b4bf4b188fec0e86d6670 Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Thu, 8 Aug 2002 00:29:40 +0000
    Subject: Parameterized output encoding.
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@484 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/pep-html-template | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    (limited to 'tools')
    
    diff --git a/tools/pep-html-template b/tools/pep-html-template
    index de0c0d4c8..47d71daef 100644
    --- a/tools/pep-html-template
    +++ b/tools/pep-html-template
    @@ -1,8 +1,8 @@
    -
    +
     
     
     
    -  
    +  
       
       PEP %(pep)s -- %(title)s
       
    -- 
    cgit v1.2.1
    
    
    From b926207786b97cc60fe4480fa55ee8ba5286415d Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Thu, 8 Aug 2002 00:30:45 +0000
    Subject: Files skipped (due to an error) are not pushed onto the server.
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@485 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/pep2html.py | 6 ++++--
     1 file changed, 4 insertions(+), 2 deletions(-)
    
    (limited to 'tools')
    
    diff --git a/tools/pep2html.py b/tools/pep2html.py
    index 42328ae9c..e48ee6bd7 100755
    --- a/tools/pep2html.py
    +++ b/tools/pep2html.py
    @@ -462,12 +462,14 @@ def main(argv=None):
         else:
             # do them all
             peptxt = []
    +        html = []
             files = glob.glob("pep-*.txt")
             files.sort()
             for file in files:
                 peptxt.append(file)
    -            make_html(file, verbose=verbose)
    -        html = ["pep-*.html"]
    +            newfile = make_html(file, verbose=verbose)
    +            if newfile:
    +                html.append(newfile)
             if browse and not update:
                 browse_file("0")
     
    -- 
    cgit v1.2.1
    
    
    From 080ca828742f9e92ad4f5eca867035ae4bd7bf8e Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Fri, 9 Aug 2002 01:17:21 +0000
    Subject:   - Updated for new I/O classes.   - Added ``check_requirements()`` &
     ``pep_type_error()``.
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@491 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/pep2html.py | 66 +++++++++++++++++++++++++++++++++++++++----------------
     1 file changed, 47 insertions(+), 19 deletions(-)
    
    (limited to 'tools')
    
    diff --git a/tools/pep2html.py b/tools/pep2html.py
    index e48ee6bd7..42f6809c2 100755
    --- a/tools/pep2html.py
    +++ b/tools/pep2html.py
    @@ -31,8 +31,6 @@ Options:
     The optional argument `peps' is a list of either pep numbers or .txt files.
     """
     
    -# Requires Python 2.2
    -
     import sys
     import os
     import re
    @@ -42,13 +40,9 @@ import getopt
     import errno
     import random
     import time
    -from email.Utils import parseaddr
    -
    -try:
    -    import docutils
    -except ImportError:
    -    docutils = None
     
    +REQUIRES = {'python': '2.2',
    +            'docutils': '0.2.1'}
     PROGRAM = sys.argv[0]
     RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html'
     PEPURL = 'pep-%04d.html'
    @@ -134,6 +128,7 @@ def linkemail(address, pepno):
     
     
     def fixfile(inpath, input_lines, outfile):
    +    from email.Utils import parseaddr
         basename = os.path.basename(inpath)
         infile = iter(input_lines)
         # convert plain text pep to minimal XHTML markup
    @@ -303,10 +298,11 @@ def fix_rst_pep(inpath, input_lines, outfile):
             options = pub.set_options()
         options._source = inpath
         options._destination = outfile.name
    -    pub.source = io.StringIO(
    +    pub.source = io.StringInput(
             options, source=''.join(input_lines), source_path=inpath)
    -    pub.destination = io.FileIO(
    -        options, destination=outfile, destination_path=outfile.name)
    +    pub.destination = io.FileOutput(
    +        options, destination=outfile, destination_path=outfile.name,
    +        autoclose=0)
         pub.publish()
     
     
    @@ -350,9 +346,6 @@ def find_pep(pep_str):
         num = int(pep_str)
         return "pep-%04d.txt" % num
     
    -PEP_TYPE_DISPATCH = {'text/plain': fixfile,
    -                     'text/x-rst': fix_rst_pep}
    -
     def make_html(inpath, verbose=0):
         input_lines = get_input_lines(inpath)
         pep_type = get_pep_type(input_lines)
    @@ -365,11 +358,8 @@ def make_html(inpath, verbose=0):
                                   % (inpath, pep_type))
             sys.stdout.flush()
             return None
    -    elif pep_type == 'text/x-rst' and not docutils:
    -        print >> sys.stderr, ('Error: Docutils not present for "%s" PEP file '
    -                              '%s.  See README.txt for installation.'
    -                              % (pep_type, inpath))
    -        sys.stdout.flush()
    +    elif PEP_TYPE_DISPATCH[pep_type] == None:
    +        pep_type_error(inpath, pep_type)
             return None
         outpath = os.path.splitext(inpath)[0] + ".html"
         if verbose:
    @@ -401,6 +391,42 @@ def push_pep(htmlfiles, txtfiles, username, verbose):
             sys.exit(rc)
     
     
    +PEP_TYPE_DISPATCH = {'text/plain': fixfile,
    +                     'text/x-rst': fix_rst_pep}
    +PEP_TYPE_MESSAGES = {}
    +
    +def check_requirements():
    +    # Check Python:
    +    try:
    +        from email.Utils import parseaddr
    +    except ImportError:
    +        PEP_TYPE_DISPATCH['text/plain'] = None
    +        PEP_TYPE_MESSAGES['text/plain'] = (
    +            'Python %s or better required for "%%(pep_type)s" PEP '
    +            'processing; %s present (%%(inpath)s).'
    +            % (REQUIRES['python'], sys.version.split()[0]))
    +    # Check Docutils:
    +    try:
    +        import docutils
    +    except ImportError:
    +        PEP_TYPE_DISPATCH['text/x-rst'] = None
    +        PEP_TYPE_MESSAGES['text/x-rst'] = (
    +            'Docutils not present for "%(pep_type)s" PEP file %(inpath)s.  '
    +            'See README.txt for installation.')
    +    else:
    +        if docutils.__version__ < REQUIRES['docutils']:
    +            PEP_TYPE_DISPATCH['text/x-rst'] = None
    +            PEP_TYPE_MESSAGES['text/x-rst'] = (
    +                'Docutils must be reinstalled for "%%(pep_type)s" PEP '
    +                'processing (%%(inpath)s).  Version %s or better required; '
    +                '%s present.  See README.txt for installation.'
    +                % (REQUIRES['docutils'], docutils.__version__))
    +
    +def pep_type_error(inpath, pep_type):
    +    print >> sys.stderr, 'Error: ' + PEP_TYPE_MESSAGES[pep_type] % locals()
    +    sys.stdout.flush()
    +
    +
     def browse_file(pep):
         import webbrowser
         file = find_pep(pep)
    @@ -426,6 +452,8 @@ def main(argv=None):
         verbose = 1
         browse = 0
     
    +    check_requirements()
    +
         if argv is None:
             argv = sys.argv[1:]
     
    -- 
    cgit v1.2.1
    
    
    From d5f026e798598f57d02ab02ffa4b20efb818473f Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Fri, 9 Aug 2002 01:19:11 +0000
    Subject: updated
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@492 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/buildhtml.py | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    (limited to 'tools')
    
    diff --git a/tools/buildhtml.py b/tools/buildhtml.py
    index b04f811d1..ac9ab75b0 100755
    --- a/tools/buildhtml.py
    +++ b/tools/buildhtml.py
    @@ -108,8 +108,8 @@ class Builder:
             if not options.silent:
                 print >>sys.stderr, '    ::: Processing .txt:', name
                 sys.stderr.flush()
    -        self.pub.source = io.FileIO(options, source_path=options._source)
    -        self.pub.destination = io.FileIO(
    +        self.pub.source = io.FileInput(options, source_path=options._source)
    +        self.pub.destination = io.FileOutput(
                 options, destination_path=options._destination)
             self.pub.publish()
     
    -- 
    cgit v1.2.1
    
    
    From 4f85bd78669fa7afd0cc5e0f531bd2a357554b1c Mon Sep 17 00:00:00 2001
    From: goodger 
    Date: Sat, 10 Aug 2002 19:48:17 +0000
    Subject: Cleaned up long lines.  Simplified line iteration.
    
    git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@497 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
    ---
     tools/pep2html.py | 39 ++++++++++++++++-----------------------
     1 file changed, 16 insertions(+), 23 deletions(-)
    
    (limited to 'tools')
    
    diff --git a/tools/pep2html.py b/tools/pep2html.py
    index 42f6809c2..fc0814a39 100755
    --- a/tools/pep2html.py
    +++ b/tools/pep2html.py
    @@ -46,7 +46,8 @@ REQUIRES = {'python': '2.2',
     PROGRAM = sys.argv[0]
     RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html'
     PEPURL = 'pep-%04d.html'
    -PEPCVSURL = 'http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/nondist/peps/pep-%04d.txt'
    +PEPCVSURL = ('http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python'
    +             '/nondist/peps/pep-%04d.txt')
     PEPDIRRUL = 'http://www.python.org/peps/'
     
     
    @@ -139,11 +140,7 @@ def fixfile(inpath, input_lines, outfile):
         header = []
         pep = ""
         title = ""
    -    while 1:
    -        try:
    -            line = infile.next()
    -        except StopIteration:
    -            break
    +    for line in infile:
             if not line.strip():
                 break
             if line[0].strip():
    @@ -165,19 +162,19 @@ def fixfile(inpath, input_lines, outfile):
             title = "PEP " + pep + " -- " + title
         if title:
             print >> outfile, '  %s' % cgi.escape(title)
    -    print >> outfile, '  '
    -    print >> outfile, ''
    -    # body
    -    print >> outfile, ''
    -    print >> outfile, '> outfile, '       width="100%" border="0">'
    -    print >> outfile, ''
    -    print >> outfile, '