[PATCH v2 11/14] cli/reply: return internet address list from get header funcs
[notmuch-archives.git] / a1 / f44de8442f7ba881bae89b718ff81f9f085b5c
1 Return-Path: <wking@tremily.us>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 78B29431FC0\r
6         for <notmuch@notmuchmail.org>; Sat, 12 Jul 2014 20:12:19 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: 0\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
13         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001]\r
14         autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id SpCliUMAQKww for <notmuch@notmuchmail.org>;\r
18         Sat, 12 Jul 2014 20:12:12 -0700 (PDT)\r
19 Received: from qmta12.emeryville.ca.mail.comcast.net\r
20         (qmta12.emeryville.ca.mail.comcast.net [76.96.27.227])\r
21         by olra.theworths.org (Postfix) with ESMTP id 6D29B431FBD\r
22         for <notmuch@notmuchmail.org>; Sat, 12 Jul 2014 20:11:48 -0700 (PDT)\r
23 Received: from omta01.emeryville.ca.mail.comcast.net ([76.96.30.11])\r
24         by qmta12.emeryville.ca.mail.comcast.net with comcast\r
25         id RfAY1o0030EPcho01fBndl; Sun, 13 Jul 2014 03:11:48 +0000\r
26 Received: from odin.tremily.us ([24.18.63.50])\r
27         by omta01.emeryville.ca.mail.comcast.net with comcast\r
28         id RfBU1o00n152l3L8MfBlCe; Sun, 13 Jul 2014 03:11:47 +0000\r
29 Received: from mjolnir.tremily.us (unknown [192.168.0.150])\r
30         by odin.tremily.us (Postfix) with ESMTPS id 48C551286F05;\r
31         Sat, 12 Jul 2014 20:11:27 -0700 (PDT)\r
32 Received: (nullmailer pid 31452 invoked by uid 1000);\r
33         Sun, 13 Jul 2014 03:10:44 -0000\r
34 From: "W. Trevor King" <wking@tremily.us>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: [PATCH v3 3/5] doc/rst-man2any.py: Adjust to handle any output\r
37  format,        not just man pages\r
38 Date: Sat, 12 Jul 2014 20:10:35 -0700\r
39 Message-Id:\r
40  <bb3c2c35d9332fd062717baa6f15a464cb04eda1.1405220724.git.wking@tremily.us>\r
41 X-Mailer: git-send-email 1.9.1.353.gc66d89d\r
42 In-Reply-To: <cover.1405220724.git.wking@tremily.us>\r
43 References: <cover.1405220724.git.wking@tremily.us>\r
44 In-Reply-To: <cover.1405220724.git.wking@tremily.us>\r
45 References: <cover.1405220724.git.wking@tremily.us>\r
46 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;\r
47         s=q20140121; t=1405221108;\r
48         bh=3WWFZti79msppoZ960v8bCxxX9vSsferWsk0hyU7J+A=;\r
49         h=Received:Received:Received:Received:From:To:Subject:Date:\r
50         Message-Id;\r
51         b=DaOUAM/puyCay51B44Rg51PGxWdR1gh75+H1swojVHSlsAaVWrN+PbiE7L2JPS/yz\r
52         85HpQfMpTiGM6sTqteZ/rLUq711z5pGYepkQy/KidT86cyF3POdl8ZVAcbTfn/i4Ph\r
53         vX8wEmOvCsHphx8dA/pTdHHYBGgWprdin5eSSj0WP/SAWR8KA1aj4w+GoMVq+RSlO4\r
54         ECmCoNsYjlEJ+p7qLEMIeHSQzqCSnXH1vGJlCt+KWsT7b5XBDUnh7ReubYXG4r/2o5\r
55         OFOXBZ8oXW/3tSYUjYN+UJR4sO/2UJjZOqF+W/C/e4hk4WHKQkrsCggqOPMTUhuQ0Q\r
56         0vzQmyNJEiydw==\r
57 Cc: Tomi Ollila <tomi.ollila@iki.fi>\r
58 X-BeenThere: notmuch@notmuchmail.org\r
59 X-Mailman-Version: 2.1.13\r
60 Precedence: list\r
61 List-Id: "Use and development of the notmuch mail system."\r
62         <notmuch.notmuchmail.org>\r
63 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
64         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
65 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
66 List-Post: <mailto:notmuch@notmuchmail.org>\r
67 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
68 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
69         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
70 X-List-Received-Date: Sun, 13 Jul 2014 03:12:19 -0000\r
71 \r
72 For example, with these changes we can build HTML output using:\r
73 \r
74   $ rst-man2any.py -c rst2html -i ${SRCDIR} -o ${OUTDIR} -e html\r
75 \r
76 The extension adjustment ensures that the output filenames from the\r
77 above command match what we currently generate with sphinx-html.\r
78 \r
79 Adding argparse handling at the top of the script tipped this over\r
80 into "complicated enough to refactor" for me, so I've shifted the\r
81 single-file-conversion logic into a new convert() function and\r
82 streamlined things a bit.\r
83 ---\r
84  doc/Makefile.local |   4 +-\r
85  doc/prerst2man.py  |  66 ---------------------------------\r
86  doc/rst-man2any.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
87  3 files changed, 107 insertions(+), 68 deletions(-)\r
88  delete mode 100644 doc/prerst2man.py\r
89  create mode 100755 doc/rst-man2any.py\r
90 \r
91 diff --git a/doc/Makefile.local b/doc/Makefile.local\r
92 index d96cdd5..045f823 100644\r
93 --- a/doc/Makefile.local\r
94 +++ b/doc/Makefile.local\r
95 @@ -7,7 +7,7 @@ SPHINXOPTS    := -q\r
96  SPHINXBUILD   = sphinx-build\r
97  DOCBUILDDIR      := $(dir)/_build\r
98  \r
99 -prerst2man := python $(srcdir)/$(dir)/prerst2man.py\r
100 +rstman2any := python $(srcdir)/$(dir)/rst-man2any.py\r
101  mkdocdeps := python $(srcdir)/$(dir)/mkdocdeps.py\r
102  \r
103  # Internal variables.\r
104 @@ -49,7 +49,7 @@ ifeq ($(HAVE_SPHINX),1)\r
105             mv $(DOCBUILDDIR)/man/*.$${section} $(DOCBUILDDIR)/man/man$${section}; \\r
106         done\r
107  else ifeq ($(HAVE_RST2MAN),1)\r
108 -       $(prerst2man) "$(RST2MAN)" $(srcdir)/doc $(DOCBUILDDIR)/man\r
109 +       $(rstman2any) --converter "$(RST2MAN)" --input $(srcdir)/doc --output $(DOCBUILDDIR)/man\r
110  else\r
111         @echo "Fatal: build dependency fail."\r
112         @false\r
113 diff --git a/doc/prerst2man.py b/doc/prerst2man.py\r
114 deleted file mode 100644\r
115 index 7d78e9b..0000000\r
116 --- a/doc/prerst2man.py\r
117 +++ /dev/null\r
118 @@ -1,66 +0,0 @@\r
119 -import sys\r
120 -from datetime import date\r
121 -from os.path import dirname, isdir\r
122 -from os import makedirs, system\r
123 -import re\r
124 -\r
125 -rst2man = sys.argv[1]\r
126 -sourcedir = sys.argv[2]\r
127 -outdir = sys.argv[3]\r
128 -\r
129 -sys.path.insert(0, sourcedir)\r
130 -import conf\r
131 -\r
132 -\r
133 -if not isdir(outdir):\r
134 -    makedirs(outdir, 0o755)\r
135 -\r
136 -\r
137 -def header(file, startdocname, command, description, authors, section):\r
138 -    file.write("""\r
139 -{0:s}\r
140 -{1:s}\r
141 -{2:s}\r
142 -\r
143 -:Date:   {3:s}\r
144 -:Version: {4:s}\r
145 -:Manual section: {5:d}\r
146 -:Manual group: {6:s}\r
147 -\r
148 -""".format(\r
149 -'-' * len(description),\r
150 -description,\r
151 -'-' * len(description),\r
152 -date.today().isoformat(), conf.release, section, conf.project))\r
153 -\r
154 -blankre = re.compile("^\s*$")\r
155 -for page in conf.man_pages:\r
156 -    outdirname = outdir + '/' + dirname(page[0])\r
157 -    if not isdir(outdirname):\r
158 -        makedirs(outdirname, 0o755)\r
159 -    filename = outdir + '/' + page[0] + '.rst'\r
160 -    outfile = open(filename, 'w')\r
161 -    infile = open(sourcedir + '/' + page[0] + '.rst', 'r')\r
162 -\r
163 -    # this is a crude hack. We look for the first blank line, and\r
164 -    # insert the rst2man header there.\r
165 -    #\r
166 -    # XXX consider really parsing input\r
167 -\r
168 -    count = 0\r
169 -    lines = infile.readlines()\r
170 -    for line in lines:\r
171 -        outfile.write(line)\r
172 -        if (blankre.match(line)):\r
173 -            break\r
174 -        count = count + 1\r
175 -\r
176 -    del lines[0:count + 1]\r
177 -\r
178 -    header(outfile, *page)\r
179 -\r
180 -    outfile.write("".join(lines))\r
181 -    outfile.close()\r
182 -\r
183 -    system('set -x; {0} {1} {2}/{3}.{4}'\r
184 -           .format(rst2man, filename, outdir, page[0], page[4]))\r
185 diff --git a/doc/rst-man2any.py b/doc/rst-man2any.py\r
186 new file mode 100755\r
187 index 0000000..52a4f9e\r
188 --- /dev/null\r
189 +++ b/doc/rst-man2any.py\r
190 @@ -0,0 +1,105 @@\r
191 +#!/usr/bin/python\r
192 +\r
193 +import argparse\r
194 +import datetime\r
195 +import os\r
196 +import sys\r
197 +\r
198 +\r
199 +def header(stream, description, authors, section, group, version):\r
200 +    "Write a man-page's ReST headers to 'stream'."\r
201 +    if len(authors) != 1:\r
202 +        raise NotImplementedError(\r
203 +            'cannot handle {count} authors ({authors}'.format(\r
204 +                count=len(authors), authors=authors))\r
205 +    stream.write('\n'.join([\r
206 +        '{description_rule}',\r
207 +        '{description}',\r
208 +        '{description_rule}',\r
209 +        '',\r
210 +        ':Author: {author}',\r
211 +        ':Date: {date}',\r
212 +        ':Version: {version}',\r
213 +        ':Manual section: {section:d}',\r
214 +        ':Manual group: {group}',\r
215 +        '',\r
216 +        '']).format(\r
217 +            description=description,\r
218 +            description_rule='-' * len(description),\r
219 +            author=authors[0],\r
220 +            date=datetime.date.today().isoformat(),\r
221 +            version=version,\r
222 +            section=section,\r
223 +            group=group))\r
224 +\r
225 +\r
226 +def convert(startdocname, description, authors, section,\r
227 +            group, version, source_dir, output_dir, command, extension=None):\r
228 +    """Convert the ReST source at path to the target format in 'output_dir'.\r
229 +\r
230 +    The initial arguments (startdocname through section) follow\r
231 +    Sphinx's man_pages option [1].\r
232 +\r
233 +    [1]: http://sphinx-doc.org/config.html#confval-man_pages\r
234 +    """\r
235 +    source_path = os.path.join(source_dir, startdocname) + '.rst'\r
236 +    output_base = os.path.join(output_dir, startdocname)\r
237 +    temp_path = output_base + '.rst'\r
238 +    if extension:\r
239 +        ext = extension\r
240 +    else:\r
241 +        ext = str(section)\r
242 +    output_path = '{base}.{ext}'.format(base=output_base, ext=ext)\r
243 +    dirname = os.path.dirname(output_path)\r
244 +    if not os.path.isdir(dirname):\r
245 +        os.makedirs(dirname, 0o755)\r
246 +    with open(source_path, 'r') as source:\r
247 +        with open(temp_path, 'w') as temp:\r
248 +            # this is a crude hack. We look for the first blank line, and\r
249 +            # insert the man-page headers there.\r
250 +            #\r
251 +            # XXX consider really parsing input\r
252 +            need_header = True\r
253 +            for line in source:\r
254 +                temp.write(line)\r
255 +                if need_header and not line.strip():\r
256 +                    header(\r
257 +                        stream=temp, description=description, authors=authors,\r
258 +                        section=section, group=group, version=version)\r
259 +                    need_header = False\r
260 +    os.system('set -x; {command} {source_path} {output_path}'.format(\r
261 +        command=command,\r
262 +        source_path=temp_path,\r
263 +        output_path=output_path))\r
264 +\r
265 +\r
266 +if __name__ == '__main__':\r
267 +    import argparse\r
268 +\r
269 +    parser = argparse.ArgumentParser(\r
270 +        description='Convert reStructuredText man pages to other formats.')\r
271 +    parser.add_argument(\r
272 +        '-i', '--input', default='_build',\r
273 +        help='Input directory')\r
274 +    parser.add_argument(\r
275 +        '-o', '--output', default='.',\r
276 +        help='Output directory')\r
277 +    parser.add_argument(\r
278 +        '-c', '--converter', default='rst2man',\r
279 +        help='ReST converter for your target output')\r
280 +    parser.add_argument(\r
281 +        '-e', '--extension',\r
282 +        help='Optional extension for the output files')\r
283 +\r
284 +    args = parser.parse_args()\r
285 +\r
286 +    sys.path.insert(0, args.input)\r
287 +    import conf\r
288 +\r
289 +    for startdocname, name, description, authors, section in conf.man_pages:\r
290 +        convert(\r
291 +            startdocname=startdocname, description=description,\r
292 +            authors=authors, section=section, group=conf.project,\r
293 +            version=conf.release, source_dir=args.input,\r
294 +            output_dir=args.output, command=args.converter,\r
295 +            extension=args.extension)\r
296 -- \r
297 1.9.1.353.gc66d89d\r
298 \r