From 620f77cb77304e1b03d311204e5f942109b1a5f4 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 14 Feb 2010 14:45:15 +0000 Subject: Generate text documentation in a single file. --- .gitignore | 1 + doc/Makefile | 8 ++++++- doc/index.rst | 17 ++++++++------- doc/tools/stitch_text.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 9 deletions(-) create mode 100755 doc/tools/stitch_text.py diff --git a/.gitignore b/.gitignore index 1f125e0..9c7ec99 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ dist/* build/* doc/_build/* doc/html/* +doc/psycopg2.txt diff --git a/doc/Makefile b/doc/Makefile index d9619aa..7dc0f3d 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -17,7 +17,7 @@ ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest -doc: html +all: html text check: doctest @@ -48,6 +48,12 @@ dirhtml: @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + tools/stitch_text.py index.rst $(BUILDDIR)/text > psycopg2.txt + @echo + @echo "Build finished. The text file is psycopg2.txt." + pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo diff --git a/doc/index.rst b/doc/index.rst index 8fe8f89..4b32069 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -40,19 +40,20 @@ Contents: extras errorcodes -.. ifconfig:: todo_include_todos - .. note:: +.. ifconfig:: builder != 'text' - **To Do items in the documentation** + .. rubric:: Indices and tables - .. todolist:: + * :ref:`genindex` + * :ref:`search` -Indices and tables -================== +.. ifconfig:: todo_include_todos -* :ref:`genindex` -* :ref:`search` + .. note:: + + **To Do items in the documentation** + .. todolist:: diff --git a/doc/tools/stitch_text.py b/doc/tools/stitch_text.py new file mode 100755 index 0000000..c54f4b1 --- /dev/null +++ b/doc/tools/stitch_text.py @@ -0,0 +1,56 @@ +#! /usr/bin/env python +"""A script to stitch together the generated text files in the correct order. +""" + +import os +import sys + +def main(): + if len(sys.argv) != 3: + print >>sys.stderr, "usage: %s index.rst text-dir" + return 2 + + _, index, txt_dir = sys.argv + + for fb in iter_file_base(index): + emit(fb, txt_dir) + + return 0 + +def iter_file_base(fn): + have_line = iter(open(fn)).next + + while not have_line().startswith('.. toctree'): + pass + while have_line().strip().startswith(':'): + pass + + yield os.path.splitext(os.path.basename(fn))[0] + + n = 0 + while 1: + line = have_line() + if line.isspace(): + continue + if line.startswith(".."): + break + n += 1 + yield line.strip() + + if n < 5: + # maybe format changed? + raise Exception("Not enough files found. Format change in index.rst?") + +def emit(basename, txt_dir): + for line in open(os.path.join(txt_dir, basename + ".txt")): + line = line.replace("``", "'") + sys.stdout.write(line) + + # some space between sections + print + print + + +if __name__ == '__main__': + sys.exit(main()) + -- cgit v1.2.1