]> git.notmuchmail.org Git - notmuch/blob - doc/prerst2man.py
lib: Internal support for querying and creating ghost messages
[notmuch] / doc / prerst2man.py
1 from sys import argv
2 from datetime import date
3 from os.path import dirname, isdir
4 from os import makedirs, system
5 import re
6
7 sourcedir = argv[1]
8 outdir = argv[2]
9
10 if not isdir(outdir):
11     makedirs(outdir, 0o755)
12
13 execfile(sourcedir + "/conf.py")
14
15
16 def header(file, startdocname, command, description, authors, section):
17     file.write("""
18 {0:s}
19 {1:s}
20 {2:s}
21
22 :Date:   {3:s}
23 :Version: {4:s}
24 :Manual section: {5:d}
25 :Manual group: {6:s}
26
27 """.format(
28 '-' * len(description),
29 description,
30 '-' * len(description),
31 date.today().isoformat(), release, section, project))
32
33 blankre = re.compile("^\s*$")
34 for page in man_pages:
35     outdirname = outdir + '/' + dirname(page[0])
36     if not isdir(outdirname):
37         makedirs(outdirname, 0o755)
38     filename = outdir + '/' + page[0] + '.rst'
39     outfile = open(filename, 'w')
40     infile = open(sourcedir + '/' + page[0] + '.rst', 'r')
41
42     # this is a crude hack. We look for the first blank line, and
43     # insert the rst2man header there.
44     #
45     # XXX consider really parsing input
46
47     count = 0
48     lines = infile.readlines()
49     for line in lines:
50         outfile.write(line)
51         if (blankre.match(line)):
52             break
53         count = count + 1
54
55     del lines[0:count + 1]
56
57     header(outfile, *page)
58
59     outfile.write("".join(lines))
60     outfile.close()
61
62     system('set -x; rst2man {0} {1}/{2}.{3}'
63            .format(filename, outdir, page[0], page[4]))