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
25 MDASH = ' — ' if sys.version_info.major >= 3 else ' -- '
28 <refentry id="systemd.index" conditional="HAVE_PYTHON">
31 <title>systemd.index</title>
32 <productname>systemd</productname>
36 <contrib>Developer</contrib>
37 <firstname>Lennart</firstname>
38 <surname>Poettering</surname>
39 <email>lennart@poettering.net</email>
45 <refentrytitle>systemd.index</refentrytitle>
46 <manvolnum>7</manvolnum>
50 <refname>systemd.index</refname>
51 <refpurpose>List all manpages from the systemd project</refpurpose>
58 <title>See Also</title>
60 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
68 This index contains {count} entries, referring to {pages} individual manual pages.'
70 def check_id(page, t):
71 id = t.getroot().get('id')
72 if not re.search('/' + id + '[.]', page):
73 raise ValueError("id='{}' is not the same as page name '{}'".format(id, page))
75 def make_index(pages):
76 index = collections.defaultdict(list)
80 section = t.find('./refmeta/manvolnum').text
81 refname = t.find('./refnamediv/refname').text
82 purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
83 for f in t.findall('./refnamediv/refname'):
84 infos = (f.text, section, purpose, refname)
85 index[f.text[0].upper()].append(infos)
88 def add_letter(template, letter, pages):
89 refsect1 = tree.SubElement(template, 'refsect1')
90 title = tree.SubElement(refsect1, 'title')
92 para = tree.SubElement(refsect1, 'para')
93 for info in sorted(pages, key=lambda info: str.lower(info[0])):
94 refname, section, purpose, realname = info
96 b = tree.SubElement(para, 'citerefentry')
97 c = tree.SubElement(b, 'refentrytitle')
99 d = tree.SubElement(b, 'manvolnum')
102 b.tail = MDASH + purpose # + ' (' + p + ')'
104 tree.SubElement(para, 'sbr')
106 def add_summary(template, indexpages):
109 for group in indexpages:
112 refname, section, purpose, realname = info
113 pages.add((realname, section))
115 refsect1 = tree.fromstring(SUMMARY)
116 template.append(refsect1)
118 para = template.find(".//para[@id='counts']")
119 para.text = COUNTS.format(count=count, pages=len(pages))
121 def make_page(xml_files):
122 template = tree.fromstring(TEMPLATE)
123 index = make_index(xml_files)
125 for letter in sorted(index):
126 add_letter(template, letter, index[letter])
128 add_summary(template, index.values())
132 if __name__ == '__main__':
133 tree.dump(make_page(sys.argv[1:]))