]>
git.ipfire.org Git - thirdparty/systemd.git/blob - make-man-index.py
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/>.
23 from lxml
import etree
as tree
24 PRETTY
= dict(pretty_print
=True)
26 import xml
.etree
.ElementTree
as tree
30 MDASH
= ' — ' if sys
.version_info
.major
>= 3 else ' -- '
33 <refentry id="systemd.index" conditional="HAVE_PYTHON">
36 <title>systemd.index</title>
37 <productname>systemd</productname>
41 <contrib>Developer</contrib>
42 <firstname>Lennart</firstname>
43 <surname>Poettering</surname>
44 <email>lennart@poettering.net</email>
50 <refentrytitle>systemd.index</refentrytitle>
51 <manvolnum>7</manvolnum>
55 <refname>systemd.index</refname>
56 <refpurpose>List all manpages from the systemd project</refpurpose>
63 <title>See Also</title>
65 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
73 This index contains {count} entries, referring to {pages} individual manual pages.'
75 def check_id(page
, t
):
76 id = t
.getroot().get('id')
77 if not re
.search('/' + id + '[.]', page
):
78 raise ValueError("id='{}' is not the same as page name '{}'".format(id, page
))
80 def make_index(pages
):
81 index
= collections
.defaultdict(list)
85 section
= t
.find('./refmeta/manvolnum').text
86 refname
= t
.find('./refnamediv/refname').text
87 purpose
= ' '.join(t
.find('./refnamediv/refpurpose').text
.split())
88 for f
in t
.findall('./refnamediv/refname'):
89 infos
= (f
.text
, section
, purpose
, refname
)
90 index
[f
.text
[0].upper()].append(infos
)
93 def add_letter(template
, letter
, pages
):
94 refsect1
= tree
.SubElement(template
, 'refsect1')
95 title
= tree
.SubElement(refsect1
, 'title')
97 para
= tree
.SubElement(refsect1
, 'para')
98 for info
in sorted(pages
, key
=lambda info
: str.lower(info
[0])):
99 refname
, section
, purpose
, realname
= info
101 b
= tree
.SubElement(para
, 'citerefentry')
102 c
= tree
.SubElement(b
, 'refentrytitle')
104 d
= tree
.SubElement(b
, 'manvolnum')
107 b
.tail
= MDASH
+ purpose
# + ' (' + p + ')'
109 tree
.SubElement(para
, 'sbr')
111 def add_summary(template
, indexpages
):
114 for group
in indexpages
:
117 refname
, section
, purpose
, realname
= info
118 pages
.add((realname
, section
))
120 refsect1
= tree
.fromstring(SUMMARY
)
121 template
.append(refsect1
)
123 para
= template
.find(".//para[@id='counts']")
124 para
.text
= COUNTS
.format(count
=count
, pages
=len(pages
))
126 def make_page(xml_files
):
127 template
= tree
.fromstring(TEMPLATE
)
128 index
= make_index(xml_files
)
130 for letter
in sorted(index
):
131 add_letter(template
, letter
, index
[letter
])
133 add_summary(template
, index
.values())
137 if __name__
== '__main__':
138 tree
.dump(make_page(sys
.argv
[1:]), **PRETTY
)