2 # -*- Mode: python; indent-tabs-mode: nil -*- */
4 # This file is part of systemd.
6 # Copyright 2012 Lennart Poettering
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/>.
21 from xml
.etree
.ElementTree
import parse
, Element
, SubElement
, tostring
22 from sys
import argv
, stdout
26 def prettify(elem
, indent
= 0):
27 s
= "\n" + indent
* " "
29 if not elem
.text
or not elem
.text
.strip():
32 prettify(e
, indent
+ 1)
33 if not e
.tail
or not e
.tail
.strip():
35 if not e
.tail
or not e
.tail
.strip():
38 if indent
and (not elem
.tail
or not elem
.tail
.strip()):
43 section
= t
.find('./refmeta/manvolnum').text
44 purpose
= ' '.join(t
.find('./refnamediv/refpurpose').text
.split())
45 for f
in t
.findall('./refnamediv/refname'):
46 index
[f
.text
] = (p
, section
, purpose
)
48 html
= Element('html')
50 head
= SubElement(html
, 'head')
51 title
= SubElement(head
, 'title')
52 title
.text
= 'Manual Page Index'
54 body
= SubElement(html
, 'body')
55 h1
= SubElement(body
, 'h1')
56 h1
.text
= 'Manual Page Index'
59 for n
in sorted(index
.keys(), key
= str.lower
):
60 path
, section
, purpose
= index
[n
]
62 if path
.endswith('.xml'):
63 path
= path
[:-4] + ".html"
69 if letter
is None or n
[0].upper() != letter
:
72 h2
= SubElement(body
, 'h2')
75 ul
= SubElement(body
, 'ul')
76 ul
.set('style', 'list-style-type:none')
78 li
= SubElement(ul
, 'li')
80 a
= SubElement(li
, 'a')
82 a
.text
= n
+ '(' + section
+ ')'
85 i
= SubElement(li
, 'i')
88 hr
= SubElement(body
, 'hr')
90 p
= SubElement(body
, 'p')
91 p
.text
= "This index contains %s entries, referring to %i individual manual pages." % (len(index
), len(argv
)-1)
93 if hasattr(stdout
, "buffer"):
94 stdout
= stdout
.buffer
96 stdout
.write(tostring(html
))