diff --git a/.gitignore b/.gitignore index 1f125e0f..9c7ec994 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 d9619aa4..7dc0f3dd 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 8fe8f89a..4b32069b 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -40,6 +40,15 @@ Contents: extras errorcodes + +.. ifconfig:: builder != 'text' + + .. rubric:: Indices and tables + + * :ref:`genindex` + * :ref:`search` + + .. ifconfig:: todo_include_todos .. note:: @@ -48,11 +57,3 @@ Contents: .. todolist:: - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`search` - - diff --git a/doc/tools/stitch_text.py b/doc/tools/stitch_text.py new file mode 100755 index 00000000..c54f4b11 --- /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()) +