From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 463CE431FC3 for ; Tue, 28 Jan 2014 08:13:11 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sb75CNUeLKah for ; Tue, 28 Jan 2014 08:13:09 -0800 (PST) Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B0B9E431FC0 for ; Tue, 28 Jan 2014 08:13:07 -0800 (PST) Received: from remotemail by yantan.tethera.net with local (Exim 4.80) (envelope-from ) id 1W8BHf-00036J-8U; Tue, 28 Jan 2014 12:13:07 -0400 Received: (nullmailer pid 15969 invoked by uid 1000); Tue, 28 Jan 2014 16:13:03 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [RFC Patch v2 2/2] doc: add target rst2man to build man pages using rst2man Date: Tue, 28 Jan 2014 12:12:38 -0400 Message-Id: <1390925558-15873-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1390925558-15873-1-git-send-email-david@tethera.net> References: <87vbxfkdex.fsf@zancas.localnet> <1390925558-15873-1-git-send-email-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jan 2014 16:13:11 -0000 Many people have docutils installed, but not sphinx. Allow these people to build the man pages. --- Makefile | 2 +- doc/rst2man/Makefile | 5 +++++ doc/rst2man/Makefile.local | 28 ++++++++++++++++++++++++++++ doc/rst2man/prerst2man.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 doc/rst2man/Makefile create mode 100644 doc/rst2man/Makefile.local create mode 100644 doc/rst2man/prerst2man.py diff --git a/Makefile b/Makefile index 39f0e62..3c7f0be 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ all: # List all subdirectories here. Each contains its own Makefile.local. # Use of '=', without '+=', seems to be required for out-of-tree # builds to work. -subdirs = compat completion doc emacs lib man parse-time-string performance-test util test +subdirs = compat completion doc doc/rst2man emacs lib man parse-time-string performance-test util test # We make all targets depend on the Makefiles themselves. global_deps = Makefile Makefile.config Makefile.local \ diff --git a/doc/rst2man/Makefile b/doc/rst2man/Makefile new file mode 100644 index 0000000..0a0815d --- /dev/null +++ b/doc/rst2man/Makefile @@ -0,0 +1,5 @@ +all: + $(MAKE) -C ../.. all + +.DEFAULT: + $(MAKE) -C ../.. $@ diff --git a/doc/rst2man/Makefile.local b/doc/rst2man/Makefile.local new file mode 100644 index 0000000..5bb3e43 --- /dev/null +++ b/doc/rst2man/Makefile.local @@ -0,0 +1,28 @@ +# -*- Makefile -*- +dir := doc/rst2man + +prerst2man := python $(dir)/prerst2man.py $(dir)/.. $(dir) + +MANSRC := $(dir)/notmuch.1 $(dir)/notmuch-search.1 $(dir)/notmuch-search-terms.7 + +%.1 : %.rst + rst2man $< > $@ + +%.7: %.rst + rst2man $< > $@ + +# preprocessed source files suitable for rst2man +RST2MANSRC := $(dir)/notmuch.rst $(dir)/notmuch-search.rst $(dir)/notmuch-search-terms.rst + +# actual source files + +RSTSRC := $(patsubst ${dir}/%,$(dir)/../%,${RST2MANSRC}) + +RSTMANSRC := $(patsubst %.rst,%.1,${RST2MANSRC}) + +rst2man: ${MANSRC} + +${RST2MANSRC}: ${RSTSRC} + $(prerst2man) + +CLEAN := ${CLEAN} ${RST2MANSRC} ${MANSRC} diff --git a/doc/rst2man/prerst2man.py b/doc/rst2man/prerst2man.py new file mode 100644 index 0000000..4222f11 --- /dev/null +++ b/doc/rst2man/prerst2man.py @@ -0,0 +1,46 @@ +from sys import argv +from datetime import date +import re + +sourcedir=argv[1] +outdir=argv[2] + +execfile(sourcedir+"/conf.py"); + +def header(file,startdocname, command, description, authors, section): + file.write(""" +--------------------------------------------- +{:s} +--------------------------------------------- + +:Date: {:s} +:Version: {:s} +:Manual section: {:d} +:Manual group: {:s} + +""".format(description,date.today().isoformat(),release,section,project)) + +blankre = re.compile("^\s*$") +for page in man_pages: + outfile = open(outdir+"/"+page[0]+'.rst','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)) -- 1.8.5.2