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 E7935431FBF for ; Sat, 10 May 2014 10:04:31 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001] 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 CSeZ4DHy4zwm for ; Sat, 10 May 2014 10:04:26 -0700 (PDT) Received: from qmta05.westchester.pa.mail.comcast.net (qmta05.westchester.pa.mail.comcast.net [76.96.62.48]) by olra.theworths.org (Postfix) with ESMTP id 3DAEB431FC3 for ; Sat, 10 May 2014 10:04:20 -0700 (PDT) Received: from omta24.westchester.pa.mail.comcast.net ([76.96.62.76]) by qmta05.westchester.pa.mail.comcast.net with comcast id 0Git1o0041ei1Bg55H4Jkl; Sat, 10 May 2014 17:04:18 +0000 Received: from odin.tremily.us ([24.18.63.50]) by omta24.westchester.pa.mail.comcast.net with comcast id 0H4H1o00W152l3L3kH4JMG; Sat, 10 May 2014 17:04:18 +0000 Received: from mjolnir.tremily.us (unknown [192.168.0.140]) by odin.tremily.us (Postfix) with ESMTPS id 39D3511969A9; Sat, 10 May 2014 10:04:17 -0700 (PDT) Received: (nullmailer pid 24533 invoked by uid 1000); Sat, 10 May 2014 17:03:44 -0000 From: "W. Trevor King" To: notmuch@notmuchmail.org Subject: [PATCH v2 3/5] doc/prerst2x.py: Adjust to handle any output format, not just man pages Date: Sat, 10 May 2014 10:03:34 -0700 Message-Id: X-Mailer: git-send-email 1.9.1.353.gc66d89d In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1399741458; bh=i0e9QngBX2US8UgqLpR6RGdcPlw3GAWa9kqKAw1c+h8=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-Id; b=LzW7NSErwCxCU+TVENMIDHpK1wY5kk1C6kcbGPCOHJgvOfMVWv5PdWzaOzYW0nh7n KrphLmgHwgmAwdmSM1lPWDHGUorb4KANOmlICG9U+xvC2y/P97M4QUC+yMP8LuWNX0 gR6WBWWb8vq8si/q36l+lKzdx+XqDg8prJzQWtkNY2nZ0C6gCB4yoo+K962o+TLxfV sllmP3Fgwiw5VL2RwckTcKsiWulMDqyR7cSeuNf/H48Al5oyiWqNcV9H+y6DZ1IL2j vDLCSvGMWaXZNIXZ1TmpojchecLf1hHwIbhZWVznx5XEcDyMEzyqrXTr0aoMbvsufj XJiexHeauRLLQ== Cc: Tomi Ollila 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: Sat, 10 May 2014 17:04:32 -0000 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