]>
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/>.
24 from xml_helper
import *
26 MDASH
= ' — ' if sys
.version_info
.major
>= 3 else ' -- '
29 <refentry id="systemd.index" conditional="HAVE_PYTHON">
32 <title>systemd.index</title>
33 <productname>systemd</productname>
37 <contrib>Developer</contrib>
38 <firstname>Lennart</firstname>
39 <surname>Poettering</surname>
40 <email>lennart@poettering.net</email>
46 <refentrytitle>systemd.index</refentrytitle>
47 <manvolnum>7</manvolnum>
51 <refname>systemd.index</refname>
52 <refpurpose>List all manpages from the systemd project</refpurpose>
59 <title>See Also</title>
61 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
69 This index contains {count} entries, referring to {pages} individual manual pages.'
72 def check_id(page
, t
):
73 id = t
.getroot().get('id')
74 if not re
.search('/' + id + '[.]', page
):
75 raise ValueError("id='{}' is not the same as page name '{}'".format(id, page
))
77 def make_index(pages
):
78 index
= collections
.defaultdict(list)
82 section
= t
.find('./refmeta/manvolnum').text
83 refname
= t
.find('./refnamediv/refname').text
84 purpose
= ' '.join(t
.find('./refnamediv/refpurpose').text
.split())
85 for f
in t
.findall('./refnamediv/refname'):
86 infos
= (f
.text
, section
, purpose
, refname
)
87 index
[f
.text
[0].upper()].append(infos
)
90 def add_letter(template
, letter
, pages
):
91 refsect1
= tree
.SubElement(template
, 'refsect1')
92 title
= tree
.SubElement(refsect1
, 'title')
94 para
= tree
.SubElement(refsect1
, 'para')
95 for info
in sorted(pages
, key
=lambda info
: str.lower(info
[0])):
96 refname
, section
, purpose
, realname
= info
98 b
= tree
.SubElement(para
, 'citerefentry')
99 c
= tree
.SubElement(b
, 'refentrytitle')
101 d
= tree
.SubElement(b
, 'manvolnum')
104 b
.tail
= MDASH
+ purpose
# + ' (' + p + ')'
106 tree
.SubElement(para
, 'sbr')
108 def add_summary(template
, indexpages
):
111 for group
in indexpages
:
114 refname
, section
, purpose
, realname
= info
115 pages
.add((realname
, section
))
117 refsect1
= tree
.fromstring(SUMMARY
)
118 template
.append(refsect1
)
120 para
= template
.find(".//para[@id='counts']")
121 para
.text
= COUNTS
.format(count
=count
, pages
=len(pages
))
123 def make_page(*xml_files
):
124 template
= tree
.fromstring(TEMPLATE
)
125 index
= make_index(xml_files
)
127 for letter
in sorted(index
):
128 add_letter(template
, letter
, index
[letter
])
130 add_summary(template
, index
.values())
134 if __name__
== '__main__':
135 with
open(sys
.argv
[1], 'wb') as f
:
136 f
.write(xml_print(make_page(*sys
.argv
[2:])))