]> git.notmuchmail.org Git - notmuch/commitdiff
doc: add target rst2man to build man pages using rst2man
authorDavid Bremner <david@tethera.net>
Tue, 28 Jan 2014 16:12:38 +0000 (12:12 -0400)
committerDavid Bremner <david@tethera.net>
Sun, 9 Mar 2014 13:41:09 +0000 (10:41 -0300)
Many people have docutils installed, but not sphinx. Allow these
people to build the man pages.

doc/Makefile.local
doc/prerst2man.py [new file with mode: 0644]

index ec23012537f4884b3aee7a1a6b32d608834652e1..471924736124af44a7138a3eb774530667d3e3ee 100644 (file)
@@ -7,10 +7,13 @@ SPHINXOPTS    := -q -c $(dir)
 SPHINXBUILD   = sphinx-build
 DOCBUILDDIR      := $(dir)/_build
 
+prerst2man := python $(dir)/prerst2man.py
+
 # Internal variables.
 ALLSPHINXOPTS   := -d $(DOCBUILDDIR)/doctrees $(SPHINXOPTS) $(dir)
 
 .PHONY: sphinx-html sphinx-man sphinx-texinfo sphinx-info
+.PHONY: rst2man
 
 sphinx-html:
        $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(DOCBUILDDIR)/html
@@ -24,4 +27,8 @@ sphinx-texinfo:
 sphinx-info: sphinx-texinfo
        make -C $(DOCBUILDDIR)/texinfo info
 
+# fallback target in case sphinx not installed
+rst2man:
+       $(prerst2man) $(DOCBUILDDIR)/.. $(DOCBUILDDIR)/man
+
 CLEAN := $(CLEAN) $(DOCBUILDDIR)
diff --git a/doc/prerst2man.py b/doc/prerst2man.py
new file mode 100644 (file)
index 0000000..720deb6
--- /dev/null
@@ -0,0 +1,62 @@
+from sys import argv
+from datetime import date
+from os.path import dirname, isdir
+from os import makedirs, system
+import re
+
+sourcedir = argv[1]
+outdir = argv[2]
+
+if not isdir(outdir):
+    makedirs(outdir, 0755)
+
+execfile(sourcedir + "/conf.py")
+
+
+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(), release, section, project))
+
+blankre = re.compile("^\s*$")
+for page in man_pages:
+    outdirname = outdir + '/' + dirname(page[0])
+    if not isdir(outdirname):
+        makedirs(outdirname, 0755)
+    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()
+
+    os.system('set -x; rst2man {0} {1}'.format(filename, outdir + '/' + page[0] + '.' + str(page[4])))