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