]>
Commit | Line | Data |
---|---|---|
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 | |
21 | from xml.etree.ElementTree import parse, Element, SubElement, tostring | |
88641113 | 22 | from sys import argv, stdout |
9c4fa6ed LP |
23 | |
24 | index = {} | |
25 | ||
7653b3c2 KS |
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 | |
40 | ||
88641113 | 41 | for 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 | |
48 | html = Element('html') | |
49 | ||
50 | head = SubElement(html, 'head') | |
51 | title = SubElement(head, 'title') | |
52 | title.text = 'Manual Page Index' | |
53 | ||
54 | body = SubElement(html, 'body') | |
55 | h1 = SubElement(body, 'h1') | |
56 | h1.text = 'Manual Page Index' | |
57 | ||
58 | letter = None | |
88641113 LP |
59 | for 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 |
88 | hr = SubElement(body, 'hr') |
89 | ||
90 | p = SubElement(body, 'p') | |
91 | p.text = "This index contains %s entries, referring to %i individual manual pages." % (len(index), len(argv)-1) | |
92 | ||
b56d18ee MM |
93 | if hasattr(stdout, "buffer"): |
94 | stdout = stdout.buffer | |
7653b3c2 | 95 | prettify(html) |
88641113 | 96 | stdout.write(tostring(html)) |