For example, with these changes we can build HTML output using: $ prerst2x.py rst2html ${SRCDIR} ${OUTDIR} html
The extension adjustment ensures that the output filenames from the above command match what we currently generate with sphinx-html. --- doc/Makefile.local | 4 +-- doc/prerst2man.py | 66 ----------------------------------------------- doc/prerst2x.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 68 deletions(-) delete mode 100644 doc/prerst2man.py create mode 100644 doc/prerst2x.py diff --git a/doc/Makefile.local b/doc/Makefile.local index d96cdd5..5fb526b 100644 --- a/doc/Makefile.local +++ b/doc/Makefile.local @@ -7,7 +7,7 @@ SPHINXOPTS := -q SPHINXBUILD = sphinx-build DOCBUILDDIR := $(dir)/_build -prerst2man := python $(srcdir)/$(dir)/prerst2man.py +prerst2x := python $(srcdir)/$(dir)/prerst2x.py mkdocdeps := python $(srcdir)/$(dir)/mkdocdeps.py # Internal variables. @@ -49,7 +49,7 @@ ifeq ($(HAVE_SPHINX),1) mv $(DOCBUILDDIR)/man/*.$${section} $(DOCBUILDDIR)/man/man$${section}; \ done else ifeq ($(HAVE_RST2MAN),1) - $(prerst2man) "$(RST2MAN)" $(srcdir)/doc $(DOCBUILDDIR)/man + $(prerst2x) "$(RST2MAN)" $(srcdir)/doc $(DOCBUILDDIR)/man else @echo "Fatal: build dependency fail." @false diff --git a/doc/prerst2man.py b/doc/prerst2man.py deleted file mode 100644 index 7d78e9b..0000000 --- a/doc/prerst2man.py +++ /dev/null @@ -1,66 +0,0 @@ -import sys -from datetime import date -from os.path import dirname, isdir -from os import makedirs, system -import re - -rst2man = sys.argv[1] -sourcedir = sys.argv[2] -outdir = sys.argv[3] - -sys.path.insert(0, sourcedir) -import conf - - -if not isdir(outdir): - makedirs(outdir, 0o755) - - -def header(file, startdocname, command, description, authors, section): - file.write(""" -{0:s} -{1:s} -{2:s} - -:Date: {3:s} -:Version: {4:s} -:Manual section: {5:d} -:Manual group: {6:s} - -""".format( -'-' * len(description), -description, -'-' * len(description), -date.today().isoformat(), conf.release, section, conf.project)) - -blankre = re.compile("^\s*$") -for page in conf.man_pages: - outdirname = outdir + '/' + dirname(page[0]) - if not isdir(outdirname): - makedirs(outdirname, 0o755) - filename = outdir + '/' + page[0] + '.rst' - outfile = open(filename, 'w') - infile = open(sourcedir + '/' + page[0] + '.rst', 'r') - - # this is a crude hack. We look for the first blank line, and - # insert the rst2man header there. - # - # XXX consider really parsing input - - count = 0 - lines = infile.readlines() - for line in lines: - outfile.write(line) - if (blankre.match(line)): - break - count = count + 1 - - del lines[0:count + 1] - - header(outfile, *page) - - outfile.write("".join(lines)) - outfile.close() - - system('set -x; {0} {1} {2}/{3}.{4}' - .format(rst2man, filename, outdir, page[0], page[4])) diff --git a/doc/prerst2x.py b/doc/prerst2x.py new file mode 100644 index 0000000..4f9213f --- /dev/null +++ b/doc/prerst2x.py @@ -0,0 +1,75 @@ +import sys +from datetime import date +from os.path import dirname, isdir +from os import makedirs, system +import re + +rst2x = sys.argv[1] +sourcedir = sys.argv[2] +outdir = sys.argv[3] +try: + extension = sys.argv[4] +except IndexError: + extension = '' + +sys.path.insert(0, sourcedir) +import conf + + +if not isdir(outdir): + makedirs(outdir, 0o755) + + +def header(file, startdocname, command, description, authors, section): + file.write(""" +{0:s} +{1:s} +{2:s} + +:Date: {3:s} +:Version: {4:s} +:Manual section: {5:d} +:Manual group: {6:s} + +""".format( +'-' * len(description), +description, +'-' * len(description), +date.today().isoformat(), conf.release, section, conf.project)) + +blankre = re.compile("^\s*$") +for page in conf.man_pages: + outdirname = outdir + '/' + dirname(page[0]) + if not isdir(outdirname): + makedirs(outdirname, 0o755) + filename = outdir + '/' + page[0] + '.rst' + outfile = open(filename, 'w') + infile = open(sourcedir + '/' + page[0] + '.rst', 'r') + + # this is a crude hack. We look for the first blank line, and + # insert the rst2x header there. + # + # XXX consider really parsing input + + count = 0 + lines = infile.readlines() + for line in lines: + outfile.write(line) + if (blankre.match(line)): + break + count = count + 1 + + del lines[0:count + 1] + + header(outfile, *page) + + outfile.write("".join(lines)) + outfile.close() + + if extension: + ext = extension + else: + ext = page[4] # man page section + + system('set -x; {0} {1} {2}/{3}.{4}' + .format(rst2x, filename, outdir, page[0], ext)) -- 1.9.1.353.gc66d89d