1 # -*- Mode: python; indent-tabs-mode: nil -*- */
3 # This file is part of systemd.
5 # Copyright 2012 Lennart Poettering
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 from xml.etree.ElementTree import parse, Element, SubElement, tostring
21 from sys import argv, stdout
25 def prettify(elem, indent = 0):
26 s = "\n" + indent * " "
28 if not elem.text or not elem.text.strip():
31 prettify(e, indent + 1)
32 if not e.tail or not e.tail.strip():
34 if not e.tail or not e.tail.strip():
37 if indent and (not elem.tail or not elem.tail.strip()):
42 section = t.find('./refmeta/manvolnum').text
43 purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
44 for f in t.findall('./refnamediv/refname'):
45 index[f.text] = (p, section, purpose)
47 html = Element('html')
49 head = SubElement(html, 'head')
50 title = SubElement(head, 'title')
51 title.text = 'Manual Page Index'
53 body = SubElement(html, 'body')
54 h1 = SubElement(body, 'h1')
55 h1.text = 'Manual Page Index'
58 for n in sorted(index.keys(), key = str.lower):
59 path, section, purpose = index[n]
61 if path.endswith('.xml'):
62 path = path[:-4] + ".html"
68 if letter is None or n[0].upper() != letter:
71 h2 = SubElement(body, 'h2')
74 ul = SubElement(body, 'ul')
75 ul.set('style', 'list-style-type:none')
77 li = SubElement(ul, 'li')
79 a = SubElement(li, 'a')
81 a.text = n + '(' + section + ')'
84 i = SubElement(li, 'i')
87 hr = SubElement(body, 'hr')
89 p = SubElement(body, 'p')
90 p.text = "This index contains %s entries, referring to %i individual manual pages." % (len(index), len(argv)-1)
92 if hasattr(stdout, "buffer"):
93 stdout = stdout.buffer
95 stdout.write(tostring(html))