journal: also use new VA_FORMAT_ADVANCE() macro in sd_journal_send()
[systemd_ALT/systemd_imz.git] / make-man-index.py
blob56f38ce413e5e7fc6057e2cd1ffa3ac324adc1fd
1 #!/usr/bin/env python
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
24 index = {}
26 def prettify(elem, indent = 0):
27 s = "\n" + indent * " "
28 if len(elem):
29 if not elem.text or not elem.text.strip():
30 elem.text = s + " "
31 for e in elem:
32 prettify(e, indent + 1)
33 if not e.tail or not e.tail.strip():
34 e.tail = s + " "
35 if not e.tail or not e.tail.strip():
36 e.tail = s
37 else:
38 if indent and (not elem.tail or not elem.tail.strip()):
39 elem.tail = s
41 for p in argv[1:]:
42 t = parse(p)
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'
58 letter = None
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"
65 c = path.rfind('/')
66 if c >= 0:
67 path = path[c+1:]
69 if letter is None or n[0].upper() != letter:
70 letter = n[0].upper()
72 h2 = SubElement(body, 'h2')
73 h2.text = letter
75 ul = SubElement(body, 'ul')
76 ul.set('style', 'list-style-type:none')
78 li = SubElement(ul, 'li')
80 a = SubElement(li, 'a')
81 a.set('href', path)
82 a.text = n + '(' + section + ')'
83 a.tail = ' -- '
85 i = SubElement(li, 'i')
86 i.text = purpose
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
95 prettify(html)
96 stdout.write(tostring(html))