2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
4 # This file is part of systemd.
6 # Copyright 2012 Lennart Poettering
7 # Copyright 2013 Zbigniew Jędrzejewski-Szmek
9 # systemd is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published by
11 # the Free Software Foundation; either version 2.1 of the License, or
12 # (at your option) any later version.
14 # systemd is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 from xml_helper import *
27 MDASH = ' — ' if sys.version_info.major >= 3 else ' -- '
30 <refentry id="elogind.index" conditional="HAVE_PYTHON">
33 <title>elogind.index</title>
34 <productname>elogind</productname>
38 <contrib>Developer</contrib>
39 <firstname>Lennart</firstname>
40 <surname>Poettering</surname>
41 <email>lennart@poettering.net</email>
47 <refentrytitle>elogind.index</refentrytitle>
48 <manvolnum>7</manvolnum>
52 <refname>elogind.index</refname>
53 <refpurpose>List all manpages from the elogind project</refpurpose>
60 <title>See Also</title>
62 <citerefentry><refentrytitle>elogind.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
70 This index contains {count} entries, referring to {pages} individual manual pages.'
73 def check_id(page, t):
74 id = t.getroot().get('id')
75 if not re.search('/' + id + '[.]', page):
76 raise ValueError("id='{}' is not the same as page name '{}'".format(id, page))
78 def make_index(pages):
79 index = collections.defaultdict(list)
83 section = t.find('./refmeta/manvolnum').text
84 refname = t.find('./refnamediv/refname').text
85 purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
86 for f in t.findall('./refnamediv/refname'):
87 infos = (f.text, section, purpose, refname)
88 index[f.text[0].upper()].append(infos)
91 def add_letter(template, letter, pages):
92 refsect1 = tree.SubElement(template, 'refsect1')
93 title = tree.SubElement(refsect1, 'title')
95 para = tree.SubElement(refsect1, 'para')
96 for info in sorted(pages, key=lambda info: str.lower(info[0])):
97 refname, section, purpose, realname = info
99 b = tree.SubElement(para, 'citerefentry')
100 c = tree.SubElement(b, 'refentrytitle')
102 d = tree.SubElement(b, 'manvolnum')
105 b.tail = MDASH + purpose # + ' (' + p + ')'
107 tree.SubElement(para, 'sbr')
109 def add_summary(template, indexpages):
112 for group in indexpages:
115 refname, section, purpose, realname = info
116 pages.add((realname, section))
118 refsect1 = tree.fromstring(SUMMARY)
119 template.append(refsect1)
121 para = template.find(".//para[@id='counts']")
122 para.text = COUNTS.format(count=count, pages=len(pages))
124 def make_page(*xml_files):
125 template = tree.fromstring(TEMPLATE)
126 index = make_index(xml_files)
128 for letter in sorted(index):
129 add_letter(template, letter, index[letter])
131 add_summary(template, index.values())
135 if __name__ == '__main__':
136 with open(sys.argv[1], 'wb') as f:
137 f.write(xml_print(make_page(*sys.argv[2:])))