-
Notifications
You must be signed in to change notification settings - Fork 71
/
labels.py
48 lines (36 loc) · 1.73 KB
/
labels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from os import path
from itertools import groupby
try:
from sphinx.builders import Builder
except ImportError:
from sphinx.builder import Builder
class CollectLabelsBuilder(Builder):
"""
Collects all present explicit labels into a table.
"""
name = 'labels'
def init(self):
pass
def get_outdated_docs(self):
return "table with all labels"
def write(self, *ignored):
labels = self.env.labels.items()
labels.sort(key=lambda x: x[0])
outfile = open(path.join(self.outdir, 'labels.txt'), 'w')
outfile.write('.. table:: \:ref\: reference labels\n\n')
outfile.write('\t============================ =============================================================================================\n')
outfile.write('\t%s %s\n' % ('Label'.ljust(30), 'Title'))
outfile.write('\t============================ =============================================================================================\n')
unlabeled = ['genindex','search','modindex']
for docname, items in groupby(labels, key=lambda x: x[1][0]):
for label in items:
if label[0] in unlabeled:
outfile.write("""\t%s :ref:`%s`\n""" % ((label[0].ljust(30)).encode("utf-8"), label[0].encode("utf-8")))
else:
outfile.write("""\t%s :ref:`%s <%s>`\n""" %((label[0].ljust(30)).encode("utf-8"),(label[1][2]).encode("utf-8"),(label[0]).encode("utf-8")))
outfile.write('\t============================ =============================================================================================\n')
outfile.close()
def finish(self):
return
def setup(app):
app.add_builder(CollectLabelsBuilder)