]> git.ipfire.org Git - thirdparty/systemd.git/blame - make-man-index.py
update TODO
[thirdparty/systemd.git] / make-man-index.py
CommitLineData
9c4fa6ed 1#!/usr/bin/env python
6b91ae13
LP
2# -*- Mode: python; indent-tabs-mode: nil -*- */
3#
4# This file is part of systemd.
5#
6# Copyright 2012 Lennart Poettering
7#
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.
12#
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.
17#
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/>.
9c4fa6ed
LP
20
21from xml.etree.ElementTree import parse, Element, SubElement, tostring
88641113 22from sys import argv, stdout
9c4fa6ed
LP
23
24index = {}
25
7653b3c2
KS
26def 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
40
88641113 41for p in argv[1:]:
9c4fa6ed 42 t = parse(p)
88641113 43 section = t.find('./refmeta/manvolnum').text
7653b3c2 44 purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
9c4fa6ed 45 for f in t.findall('./refnamediv/refname'):
88641113 46 index[f.text] = (p, section, purpose)
9c4fa6ed
LP
47
48html = Element('html')
49
50head = SubElement(html, 'head')
51title = SubElement(head, 'title')
52title.text = 'Manual Page Index'
53
54body = SubElement(html, 'body')
55h1 = SubElement(body, 'h1')
56h1.text = 'Manual Page Index'
57
58letter = None
88641113
LP
59for n in sorted(index.keys(), key = str.lower):
60 path, section, purpose = index[n]
9c4fa6ed
LP
61
62 if path.endswith('.xml'):
63 path = path[:-4] + ".html"
64
65 c = path.rfind('/')
66 if c >= 0:
67 path = path[c+1:]
68
69 if letter is None or n[0].upper() != letter:
70 letter = n[0].upper()
71
a6c9b1c4 72 h2 = SubElement(body, 'h2')
9c4fa6ed
LP
73 h2.text = letter
74
75 ul = SubElement(body, 'ul')
76 ul.set('style', 'list-style-type:none')
77
92e1ecc6 78 li = SubElement(ul, 'li')
9c4fa6ed 79
92e1ecc6 80 a = SubElement(li, 'a')
9c4fa6ed
LP
81 a.set('href', path)
82 a.text = n + '(' + section + ')'
92e1ecc6
LP
83 a.tail = ' -- '
84
85 i = SubElement(li, 'i')
86 i.text = purpose
9c4fa6ed 87
051eaebb
LP
88hr = SubElement(body, 'hr')
89
90p = SubElement(body, 'p')
91p.text = "This index contains %s entries, referring to %i individual manual pages." % (len(index), len(argv)-1)
92
b56d18ee
MM
93if hasattr(stdout, "buffer"):
94 stdout = stdout.buffer
7653b3c2 95prettify(html)
88641113 96stdout.write(tostring(html))