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