X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=make-man-index.py;h=2dbc2da995bf9d5ece4f1ff234be5ff189dc42eb;hb=ba70211e0fe05d2e89e222e6eb7dd3766655cb44;hp=36440902542f03fff3e22501e18b0f7100d20704;hpb=92e1ecc62b8ad38d8dcd60baa996fc47feb04bc5;p=elogind.git
diff --git a/make-man-index.py b/make-man-index.py
index 364409025..2dbc2da99 100755
--- a/make-man-index.py
+++ b/make-man-index.py
@@ -1,55 +1,126 @@
-#!/usr/bin/env python
-
-from xml.etree.ElementTree import parse, Element, SubElement, tostring
-from sys import argv, stdout
-
-index = {}
-
-for p in argv[1:]:
- t = parse(p)
+# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
+#
+# This file is part of systemd.
+#
+# Copyright 2012 Lennart Poettering
+# Copyright 2013 Zbigniew JÄdrzejewski-Szmek
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# systemd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with systemd; If not, see .
+
+import collections
+import xml.etree.ElementTree as tree
+import sys
+MDASH = ' â ' if sys.version_info.major >= 3 else ' -- '
+
+TEMPLATE = '''\
+
+
+
+ systemd.index
+ systemd
+
+
+
+ Developer
+ Lennart
+ Poettering
+ lennart@poettering.net
+
+
+
+
+
+ systemd.index
+ 7
+
+
+
+ systemd.index
+ List all manpages from the systemd project
+
+
+'''
+
+SUMMARY = '''\
+
+ See Also
+
+ systemd.directives7
+
+
+
+
+'''
+
+COUNTS = '\
+This index contains {count} entries, referring to {pages} individual manual pages.'
+
+def make_index(pages):
+ index = collections.defaultdict(list)
+ for p in pages:
+ t = tree.parse(p)
section = t.find('./refmeta/manvolnum').text
- purpose = t.find('./refnamediv/refpurpose').text
+ refname = t.find('./refnamediv/refname').text
+ purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
for f in t.findall('./refnamediv/refname'):
- index[f.text] = (p, section, purpose)
-
-html = Element('html')
+ infos = (f.text, section, purpose, refname)
+ index[f.text[0].upper()].append(infos)
+ return index
-head = SubElement(html, 'head')
-title = SubElement(head, 'title')
-title.text = 'Manual Page Index'
+def add_letter(template, letter, pages):
+ refsect1 = tree.SubElement(template, 'refsect1')
+ title = tree.SubElement(refsect1, 'title')
+ title.text = letter
+ para = tree.SubElement(refsect1, 'para')
+ for info in sorted(pages, key=lambda info: str.lower(info[0])):
+ refname, section, purpose, realname = info
-body = SubElement(html, 'body')
-h1 = SubElement(body, 'h1')
-h1.text = 'Manual Page Index'
+ b = tree.SubElement(para, 'citerefentry')
+ c = tree.SubElement(b, 'refentrytitle')
+ c.text = refname
+ d = tree.SubElement(b, 'manvolnum')
+ d.text = section
-letter = None
-for n in sorted(index.keys(), key = str.lower):
- path, section, purpose = index[n]
+ b.tail = MDASH + purpose # + ' (' + p + ')'
- if path.endswith('.xml'):
- path = path[:-4] + ".html"
+ tree.SubElement(para, 'sbr')
- c = path.rfind('/')
- if c >= 0:
- path = path[c+1:]
+def add_summary(template, indexpages):
+ count = 0
+ pages = set()
+ for group in indexpages:
+ count += len(group)
+ for info in group:
+ refname, section, purpose, realname = info
+ pages.add((realname, section))
- if letter is None or n[0].upper() != letter:
- letter = n[0].upper()
+ refsect1 = tree.fromstring(SUMMARY)
+ template.append(refsect1)
- h2 = SubElement(body, 'h1')
- h2.text = letter
+ para = template.find(".//para[@id='counts']")
+ para.text = COUNTS.format(count=count, pages=len(pages))
- ul = SubElement(body, 'ul')
- ul.set('style', 'list-style-type:none')
+def make_page(xml_files):
+ template = tree.fromstring(TEMPLATE)
+ index = make_index(xml_files)
- li = SubElement(ul, 'li')
+ for letter in sorted(index):
+ add_letter(template, letter, index[letter])
- a = SubElement(li, 'a')
- a.set('href', path)
- a.text = n + '(' + section + ')'
- a.tail = ' -- '
+ add_summary(template, index.values())
- i = SubElement(li, 'i')
- i.text = purpose
+ return template
-stdout.write(tostring(html))
+if __name__ == '__main__':
+ tree.dump(make_page(sys.argv[1:]))