From 4910fd219d417c83b0e8e4376d6276a7f757b4dc Mon Sep 17 00:00:00 2001 From: David Bremner Date: Mon, 10 Mar 2014 09:56:58 +2100 Subject: [PATCH] [Patch v3 2/4] doc: add target rst2man to build man pages using rst2man --- 4b/2188041f6b9cc968b00f7dedd4c2c2c77b7c4c | 155 ++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 4b/2188041f6b9cc968b00f7dedd4c2c2c77b7c4c diff --git a/4b/2188041f6b9cc968b00f7dedd4c2c2c77b7c4c b/4b/2188041f6b9cc968b00f7dedd4c2c2c77b7c4c new file mode 100644 index 000000000..d93ba2587 --- /dev/null +++ b/4b/2188041f6b9cc968b00f7dedd4c2c2c77b7c4c @@ -0,0 +1,155 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id CC341431FDB + for ; Sun, 9 Mar 2014 05:57:40 -0700 (PDT) +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 cvgBL6vod6nu for ; + Sun, 9 Mar 2014 05:57:35 -0700 (PDT) +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 4DF70431FBC + for ; Sun, 9 Mar 2014 05:57:25 -0700 (PDT) +Received: from remotemail by yantan.tethera.net with local (Exim 4.80) + (envelope-from ) + id 1WMdIA-0003qY-NF; Sun, 09 Mar 2014 09:57:22 -0300 +Received: (nullmailer pid 8483 invoked by uid 1000); Sun, 09 Mar 2014 + 12:57:08 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [Patch v3 2/4] doc: add target rst2man to build man pages using + rst2man +Date: Sun, 9 Mar 2014 09:56:58 -0300 +Message-Id: <1394369820-8319-3-git-send-email-david@tethera.net> +X-Mailer: git-send-email 1.8.5.3 +In-Reply-To: <1394369820-8319-1-git-send-email-david@tethera.net> +References: <1394369820-8319-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, 09 Mar 2014 12:57:41 -0000 + +Many people have docutils installed, but not sphinx. Allow these +people to build the man pages. +--- + doc/Makefile.local | 7 ++++++ + doc/prerst2man.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 69 insertions(+) + create mode 100644 doc/prerst2man.py + +diff --git a/doc/Makefile.local b/doc/Makefile.local +index ec23012..4719247 100644 +--- a/doc/Makefile.local ++++ b/doc/Makefile.local +@@ -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 +index 0000000..720deb6 +--- /dev/null ++++ b/doc/prerst2man.py +@@ -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]))) +-- +1.8.5.3 + -- 2.26.2