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 3E845431FCF for ; Sat, 22 Feb 2014 16:16:49 -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 Vrauy91cHGzj for ; Sat, 22 Feb 2014 16:16:47 -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 B0A0D431E84 for ; Sat, 22 Feb 2014 16:16:43 -0800 (PST) Received: from remotemail by yantan.tethera.net with local (Exim 4.80) (envelope-from ) id 1WHMkL-0003q7-8L; Sat, 22 Feb 2014 20:16:41 -0400 Received: (nullmailer pid 19429 invoked by uid 1000); Sun, 23 Feb 2014 00:16:31 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [RFC Patch v3 2/3] doc: add target rst2man to build man pages using rst2man Date: Sat, 22 Feb 2014 20:16:14 -0400 Message-Id: <1393114575-8756-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1393114575-8756-1-git-send-email-david@tethera.net> References: <87fvo7btu8.fsf@qmul.ac.uk> <1393114575-8756-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: Sun, 23 Feb 2014 00:16:49 -0000 Many people have docutils installed, but not sphinx. Allow these people to build the man pages. --- Makefile | 2 +- doc/conf.py | 2 +- doc/rst2man/Makefile | 5 +++++ doc/rst2man/Makefile.local | 37 ++++++++++++++++++++++++++++++++ doc/rst2man/prerst2man.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 2 deletions(-) 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/conf.py b/doc/conf.py index d80b2af..9180d86 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -21,7 +21,7 @@ release = '0.17' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ['_build','rst2man'] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' 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..bc821fe --- /dev/null +++ b/doc/rst2man/Makefile.local @@ -0,0 +1,37 @@ +# -*- Makefile -*- +dir := doc/rst2man + +prerst2man := python $(dir)/prerst2man.py $(dir)/.. $(dir) + +%.1 :%.rst + rst2man $< > $@ + +%.5 :%.rst + rst2man $< > $@ + +%.7: %.rst + rst2man $< > $@ + +# actual source files +RST1SRC := $(wildcard doc/man1/*.rst) +RST5SRC := $(wildcard doc/man5/*.rst) +RST7SRC := $(wildcard doc/man7/*.rst) + +RST2MAN1SRC := $(patsubst doc/man1/%,doc/rst2man/man1/%,$(RST1SRC)) +RST2MAN5SRC := $(patsubst doc/man5/%,doc/rst2man/man5/%,$(RST5SRC)) +RST2MAN7SRC := $(patsubst doc/man7/%,doc/rst2man/man7/%,$(RST7SRC)) + +RST2MANSRC := ${RST2MAN1SRC} ${RST2MAN5SRC} ${RST2MAN7SRC} + +MAN1SRC := $(patsubst $(dir)/man1/%.rst,$(dir)/man1/%.1,${RST2MAN1SRC}) +MAN5SRC := $(patsubst $(dir)/man5/%.rst,$(dir)/man5/%.5,${RST2MAN5SRC}) +MAN7SRC := $(patsubst $(dir)/man7/%.rst,$(dir)/man7/%.7,${RST2MAN7SRC}) +MANSRC := ${MAN1SRC} ${MAN5SRC} ${MAN7SRC} + +rst2man: ${MANSRC} + +${RST2MANSRC}: ${RSTSRC} + mkdir -p doc/rst2man/man1 doc/rst2man/man5 doc/rst2man/man7 + $(prerst2man) + +CLEAN := ${CLEAN} ${RST2MANSRC} ${MANSRC} diff --git a/doc/rst2man/prerst2man.py b/doc/rst2man/prerst2man.py new file mode 100644 index 0000000..797dd20 --- /dev/null +++ b/doc/rst2man/prerst2man.py @@ -0,0 +1,53 @@ +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} +{:s} +{:s} + +:Date: {:s} +:Version: {:s} +:Manual section: {:d} +:Manual group: {:s} + +""".format( +'-' * len(description), +description, +'-' * len(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.3