1 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # This file is part of systemd.
5 # Copyright 2012 Lennart Poettering
6 # Copyright 2013 Zbigniew Jędrzejewski-Szmek
8 # systemd is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
13 # systemd is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 import xml.etree.ElementTree as tree
26 <refentry id="systemd.index">
29 <title>systemd.index</title>
30 <productname>systemd</productname>
34 <contrib>Developer</contrib>
35 <firstname>Lennart</firstname>
36 <surname>Poettering</surname>
37 <email>lennart@poettering.net</email>
43 <refentrytitle>systemd.index</refentrytitle>
44 <manvolnum>7</manvolnum>
48 <refname>systemd.index</refname>
49 <refpurpose>List all manpages from the systemd project</refpurpose>
56 <title>See Also</title>
58 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
66 This index contains {count} entries, referring to {pages} individual manual pages.'
68 def make_index(pages):
69 index = collections.defaultdict(list)
72 section = t.find('./refmeta/manvolnum').text
73 refname = t.find('./refnamediv/refname').text
74 purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
75 for f in t.findall('./refnamediv/refname'):
76 infos = (f.text, section, purpose, refname)
77 index[f.text[0].upper()].append(infos)
80 def add_letter(template, letter, pages):
81 refsect1 = tree.SubElement(template, 'refsect1')
82 title = tree.SubElement(refsect1, 'title')
84 para = tree.SubElement(refsect1, 'para')
85 for info in sorted(pages, key=lambda info: str.lower(info[0])):
86 refname, section, purpose, realname = info
88 b = tree.SubElement(para, 'citerefentry')
89 c = tree.SubElement(b, 'refentrytitle')
91 d = tree.SubElement(b, 'manvolnum')
94 b.tail = ' — ' + purpose # + ' (' + p + ')'
96 tree.SubElement(para, 'sbr')
98 def add_summary(template, indexpages):
101 for group in indexpages:
104 refname, section, purpose, realname = info
105 pages.add((realname, section))
107 refsect1 = tree.fromstring(SUMMARY)
108 template.append(refsect1)
110 para = template.find(".//para[@id='counts']")
111 para.text = COUNTS.format(count=count, pages=len(pages))
113 def make_page(xml_files):
114 template = tree.fromstring(TEMPLATE)
115 index = make_index(xml_files)
117 for letter in sorted(index):
118 add_letter(template, letter, index[letter])
120 add_summary(template, index.values())
124 if __name__ == '__main__':
125 tree.dump(make_page(sys.argv[1:]))