]>
git.ipfire.org Git - thirdparty/systemd.git/blob - tools/make-man-index.py
2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # SPDX-License-Identifier: LGPL-2.1+
5 # This file is part of systemd.
7 # Copyright 2012 Lennart Poettering
8 # Copyright 2013 Zbigniew Jędrzejewski-Szmek
10 # systemd is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU Lesser General Public License as published by
12 # the Free Software Foundation; either version 2.1 of the License, or
13 # (at your option) any later version.
15 # systemd is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public License
21 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 from xml_helper
import xml_parse
, xml_print
, tree
28 MDASH
= ' — ' if sys
.version_info
.major
>= 3 else ' -- '
31 <refentry id="systemd.index" conditional="HAVE_PYTHON">
34 <title>systemd.index</title>
35 <productname>systemd</productname>
39 <contrib>Developer</contrib>
40 <firstname>Lennart</firstname>
41 <surname>Poettering</surname>
42 <email>lennart@poettering.net</email>
48 <refentrytitle>systemd.index</refentrytitle>
49 <manvolnum>7</manvolnum>
53 <refname>systemd.index</refname>
54 <refpurpose>List all manpages from the systemd project</refpurpose>
61 <title>See Also</title>
63 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
71 This index contains {count} entries, referring to {pages} individual manual pages.'
74 def check_id(page
, t
):
75 id = t
.getroot().get('id')
76 if not re
.search('/' + id + '[.]', page
):
77 raise ValueError("id='{}' is not the same as page name '{}'".format(id, page
))
79 def make_index(pages
):
80 index
= collections
.defaultdict(list)
84 section
= t
.find('./refmeta/manvolnum').text
85 refname
= t
.find('./refnamediv/refname').text
86 purpose
= ' '.join(t
.find('./refnamediv/refpurpose').text
.split())
87 for f
in t
.findall('./refnamediv/refname'):
88 infos
= (f
.text
, section
, purpose
, refname
)
89 index
[f
.text
[0].upper()].append(infos
)
92 def add_letter(template
, letter
, pages
):
93 refsect1
= tree
.SubElement(template
, 'refsect1')
94 title
= tree
.SubElement(refsect1
, 'title')
96 para
= tree
.SubElement(refsect1
, 'para')
97 for info
in sorted(pages
, key
=lambda info
: str.lower(info
[0])):
98 refname
, section
, purpose
, realname
= info
100 b
= tree
.SubElement(para
, 'citerefentry')
101 c
= tree
.SubElement(b
, 'refentrytitle')
103 d
= tree
.SubElement(b
, 'manvolnum')
106 b
.tail
= MDASH
+ purpose
# + ' (' + p + ')'
108 tree
.SubElement(para
, 'sbr')
110 def add_summary(template
, indexpages
):
113 for group
in indexpages
:
116 refname
, section
, purpose
, realname
= info
117 pages
.add((realname
, section
))
119 refsect1
= tree
.fromstring(SUMMARY
)
120 template
.append(refsect1
)
122 para
= template
.find(".//para[@id='counts']")
123 para
.text
= COUNTS
.format(count
=count
, pages
=len(pages
))
125 def make_page(*xml_files
):
126 template
= tree
.fromstring(TEMPLATE
)
127 index
= make_index(xml_files
)
129 for letter
in sorted(index
):
130 add_letter(template
, letter
, index
[letter
])
132 add_summary(template
, index
.values())
136 if __name__
== '__main__':
137 with
open(sys
.argv
[1], 'wb') as f
:
138 f
.write(xml_print(make_page(*sys
.argv
[2:])))