2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # SPDX-License-Identifier: LGPL-2.1+
5 # Copyright © 2013 Zbigniew Jędrzejewski-Szmek
10 from xml_helper import xml_parse, xml_print, tree
12 MDASH = ' — ' if sys.version_info.major >= 3 else ' -- '
15 <refentry id="elogind.index" conditional="HAVE_PYTHON">
18 <title>elogind.index</title>
19 <productname>elogind</productname>
23 <contrib>Developer</contrib>
24 <firstname>Lennart</firstname>
25 <surname>Poettering</surname>
26 <email>lennart@poettering.net</email>
28 <!-- 1 /// Must add elogind authors for the additions and changes -->
30 <contrib>Developer</contrib>
31 <firstname>Sven</firstname>
32 <surname>Eden</surname>
33 <email>sven.eden@gmx.de</email>
40 <refentrytitle>elogind.index</refentrytitle>
41 <manvolnum>7</manvolnum>
45 <refname>elogind.index</refname>
46 <refpurpose>List all manpages from the elogind project</refpurpose>
53 <title>See Also</title>
55 <citerefentry><refentrytitle>elogind.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
63 This index contains {count} entries, referring to {pages} individual manual pages.'
66 def check_id(page, t):
67 id = t.getroot().get('id')
68 if not re.search('/' + id + '[.]', page):
69 raise ValueError("id='{}' is not the same as page name '{}'".format(id, page))
71 def make_index(pages):
72 index = collections.defaultdict(list)
76 section = t.find('./refmeta/manvolnum').text
77 refname = t.find('./refnamediv/refname').text
78 purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
79 for f in t.findall('./refnamediv/refname'):
80 infos = (f.text, section, purpose, refname)
81 index[f.text[0].upper()].append(infos)
84 def add_letter(template, letter, pages):
85 refsect1 = tree.SubElement(template, 'refsect1')
86 title = tree.SubElement(refsect1, 'title')
88 para = tree.SubElement(refsect1, 'para')
89 for info in sorted(pages, key=lambda info: str.lower(info[0])):
90 refname, section, purpose, realname = info
92 b = tree.SubElement(para, 'citerefentry')
93 c = tree.SubElement(b, 'refentrytitle')
95 d = tree.SubElement(b, 'manvolnum')
98 b.tail = MDASH + purpose # + ' (' + p + ')'
100 tree.SubElement(para, 'sbr')
102 def add_summary(template, indexpages):
105 for group in indexpages:
108 refname, section, purpose, realname = info
109 pages.add((realname, section))
111 refsect1 = tree.fromstring(SUMMARY)
112 template.append(refsect1)
114 para = template.find(".//para[@id='counts']")
115 para.text = COUNTS.format(count=count, pages=len(pages))
117 def make_page(*xml_files):
118 template = tree.fromstring(TEMPLATE)
119 index = make_index(xml_files)
121 for letter in sorted(index):
122 add_letter(template, letter, index[letter])
124 add_summary(template, index.values())
128 if __name__ == '__main__':
129 with open(sys.argv[1], 'wb') as f:
130 f.write(xml_print(make_page(*sys.argv[2:])))