man: generate xml not html for index
This way we also get a man page. The output is not as polished. I hope that it doesn't matter too much. index.html is not generated now, the page is called systemd.index.html. If necessary, an install hook should be added.
This commit is contained in:
parent
9cc2c8b763
commit
f6b6728d1d
19
Makefile.am
19
Makefile.am
|
@ -682,22 +682,10 @@ CLEANFILES += \
|
||||||
${XML_FILES:.xml=.html}
|
${XML_FILES:.xml=.html}
|
||||||
|
|
||||||
if HAVE_PYTHON
|
if HAVE_PYTHON
|
||||||
noinst_DATA += \
|
|
||||||
man/index.html
|
|
||||||
|
|
||||||
CLEANFILES += \
|
|
||||||
man/index.html
|
|
||||||
|
|
||||||
man/index.html: make-man-index.py $(XML_FILES)
|
|
||||||
$(AM_V_at)$(MKDIR_P) $(dir $@)
|
|
||||||
$(AM_V_GEN)$(PYTHON) $^ > $@
|
|
||||||
|
|
||||||
MANPAGES += \
|
MANPAGES += \
|
||||||
|
man/systemd.index.7 \
|
||||||
man/systemd.directives.7
|
man/systemd.directives.7
|
||||||
|
|
||||||
EXTRA_DIST += \
|
|
||||||
man/index.html
|
|
||||||
|
|
||||||
XML_DIRECTIVE_FILES = \
|
XML_DIRECTIVE_FILES = \
|
||||||
man/systemd.xml \
|
man/systemd.xml \
|
||||||
man/systemd.unit.xml \
|
man/systemd.unit.xml \
|
||||||
|
@ -718,11 +706,16 @@ XML_DIRECTIVE_FILES = \
|
||||||
man/systemd.time.xml \
|
man/systemd.time.xml \
|
||||||
man/bootchart.conf.xml
|
man/bootchart.conf.xml
|
||||||
|
|
||||||
|
man/systemd.index.xml: make-man-index.py $(filter-out man/systemd.index.xml,$(XML_FILES))
|
||||||
|
$(AM_V_at)$(MKDIR_P) $(dir $@)
|
||||||
|
$(AM_V_GEN)$(PYTHON) $^ > $@
|
||||||
|
|
||||||
man/systemd.directives.xml: make-directive-index.py $(XML_DIRECTIVE_FILES)
|
man/systemd.directives.xml: make-directive-index.py $(XML_DIRECTIVE_FILES)
|
||||||
$(AM_V_at)$(MKDIR_P) $(dir $@)
|
$(AM_V_at)$(MKDIR_P) $(dir $@)
|
||||||
$(AM_V_GEN)$(PYTHON) $^ > $@
|
$(AM_V_GEN)$(PYTHON) $^ > $@
|
||||||
|
|
||||||
EXTRA_DIST += \
|
EXTRA_DIST += \
|
||||||
|
man/systemd.index.xml \
|
||||||
man/systemd.directives.xml
|
man/systemd.directives.xml
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
2
TODO
2
TODO
|
@ -32,8 +32,6 @@ Features:
|
||||||
|
|
||||||
* support high-level cgroup setting syntax in systemctl. Example: "systemctl set-cgroup-attr MemoryLimit 5K"
|
* support high-level cgroup setting syntax in systemctl. Example: "systemctl set-cgroup-attr MemoryLimit 5K"
|
||||||
|
|
||||||
* add a man page "systemdall" that lists all of systemd's man pages, inspired by zsh's "zshall" page
|
|
||||||
|
|
||||||
* print a nicer explanation if people use variable/specifier expansion in ExecStart= for the first word
|
* print a nicer explanation if people use variable/specifier expansion in ExecStart= for the first word
|
||||||
|
|
||||||
* kernel cmdline switch to turn off predictable network interface names
|
* kernel cmdline switch to turn off predictable network interface names
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
# -*- Mode: python; indent-tabs-mode: nil -*- */
|
# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
|
||||||
#
|
#
|
||||||
# This file is part of systemd.
|
# This file is part of systemd.
|
||||||
#
|
#
|
||||||
# Copyright 2012 Lennart Poettering
|
# Copyright 2012 Lennart Poettering
|
||||||
|
# Copyright 2013 Zbigniew Jędrzejewski-Szmek
|
||||||
#
|
#
|
||||||
# systemd is free software; you can redistribute it and/or modify it
|
# 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
|
# under the terms of the GNU Lesser General Public License as published by
|
||||||
|
@ -17,79 +18,108 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from xml.etree.ElementTree import parse, Element, SubElement, tostring
|
import collections
|
||||||
from sys import argv, stdout
|
import xml.etree.ElementTree as tree
|
||||||
|
import sys
|
||||||
|
|
||||||
index = {}
|
TEMPLATE = '''\
|
||||||
|
<refentry id="systemd.index">
|
||||||
|
|
||||||
def prettify(elem, indent = 0):
|
<refentryinfo>
|
||||||
s = "\n" + indent * " "
|
<title>systemd.index</title>
|
||||||
if len(elem):
|
<productname>systemd</productname>
|
||||||
if not elem.text or not elem.text.strip():
|
|
||||||
elem.text = s + " "
|
|
||||||
for e in elem:
|
|
||||||
prettify(e, indent + 1)
|
|
||||||
if not e.tail or not e.tail.strip():
|
|
||||||
e.tail = s + " "
|
|
||||||
if not e.tail or not e.tail.strip():
|
|
||||||
e.tail = s
|
|
||||||
else:
|
|
||||||
if indent and (not elem.tail or not elem.tail.strip()):
|
|
||||||
elem.tail = s
|
|
||||||
|
|
||||||
for p in argv[1:]:
|
<authorgroup>
|
||||||
t = parse(p)
|
<author>
|
||||||
|
<contrib>Developer</contrib>
|
||||||
|
<firstname>Lennart</firstname>
|
||||||
|
<surname>Poettering</surname>
|
||||||
|
<email>lennart@poettering.net</email>
|
||||||
|
</author>
|
||||||
|
</authorgroup>
|
||||||
|
</refentryinfo>
|
||||||
|
|
||||||
|
<refmeta>
|
||||||
|
<refentrytitle>systemd.index</refentrytitle>
|
||||||
|
<manvolnum>7</manvolnum>
|
||||||
|
</refmeta>
|
||||||
|
|
||||||
|
<refnamediv>
|
||||||
|
<refname>systemd.index</refname>
|
||||||
|
<refpurpose>List all manpages from the systemd project</refpurpose>
|
||||||
|
</refnamediv>
|
||||||
|
</refentry>
|
||||||
|
'''
|
||||||
|
|
||||||
|
SUMMARY = '''\
|
||||||
|
<refsect1>
|
||||||
|
<title>See Also</title>
|
||||||
|
<para>
|
||||||
|
<citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para id='counts' />
|
||||||
|
</refsect1>
|
||||||
|
'''
|
||||||
|
|
||||||
|
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
|
section = t.find('./refmeta/manvolnum').text
|
||||||
|
refname = t.find('./refnamediv/refname').text
|
||||||
purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
|
purpose = ' '.join(t.find('./refnamediv/refpurpose').text.split())
|
||||||
for f in t.findall('./refnamediv/refname'):
|
for f in t.findall('./refnamediv/refname'):
|
||||||
index[f.text] = (p, section, purpose)
|
infos = (f.text, section, purpose, refname)
|
||||||
|
index[f.text[0].upper()].append(infos)
|
||||||
|
return index
|
||||||
|
|
||||||
html = Element('html')
|
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
|
||||||
|
|
||||||
head = SubElement(html, 'head')
|
b = tree.SubElement(para, 'citerefentry')
|
||||||
title = SubElement(head, 'title')
|
c = tree.SubElement(b, 'refentrytitle')
|
||||||
title.text = 'Manual Page Index'
|
c.text = refname
|
||||||
|
d = tree.SubElement(b, 'manvolnum')
|
||||||
|
d.text = section
|
||||||
|
|
||||||
body = SubElement(html, 'body')
|
b.tail = ' — ' + purpose # + ' (' + p + ')'
|
||||||
h1 = SubElement(body, 'h1')
|
|
||||||
h1.text = 'Manual Page Index'
|
|
||||||
|
|
||||||
letter = None
|
tree.SubElement(para, 'sbr')
|
||||||
for n in sorted(index.keys(), key = str.lower):
|
|
||||||
path, section, purpose = index[n]
|
|
||||||
|
|
||||||
if path.endswith('.xml'):
|
def add_summary(template, indexpages):
|
||||||
path = path[:-4] + ".html"
|
count = 0
|
||||||
|
pages = set()
|
||||||
|
for group in indexpages:
|
||||||
|
count += len(group)
|
||||||
|
for info in group:
|
||||||
|
refname, section, purpose, realname = info
|
||||||
|
pages.add((realname, section))
|
||||||
|
|
||||||
c = path.rfind('/')
|
refsect1 = tree.fromstring(SUMMARY)
|
||||||
if c >= 0:
|
template.append(refsect1)
|
||||||
path = path[c+1:]
|
|
||||||
|
|
||||||
if letter is None or n[0].upper() != letter:
|
para = template.find(".//para[@id='counts']")
|
||||||
letter = n[0].upper()
|
para.text = COUNTS.format(count=count, pages=len(pages))
|
||||||
|
|
||||||
h2 = SubElement(body, 'h2')
|
def make_page(xml_files):
|
||||||
h2.text = letter
|
template = tree.fromstring(TEMPLATE)
|
||||||
|
index = make_index(xml_files)
|
||||||
|
|
||||||
ul = SubElement(body, 'ul')
|
for letter in sorted(index):
|
||||||
ul.set('style', 'list-style-type:none')
|
add_letter(template, letter, index[letter])
|
||||||
|
|
||||||
li = SubElement(ul, 'li')
|
add_summary(template, index.values())
|
||||||
|
|
||||||
a = SubElement(li, 'a')
|
return template
|
||||||
a.set('href', path)
|
|
||||||
a.text = n + '(' + section + ')'
|
|
||||||
a.tail = ' -- '
|
|
||||||
|
|
||||||
i = SubElement(li, 'i')
|
if __name__ == '__main__':
|
||||||
i.text = purpose
|
tree.dump(make_page(sys.argv[1:]))
|
||||||
|
|
||||||
hr = SubElement(body, 'hr')
|
|
||||||
|
|
||||||
p = SubElement(body, 'p')
|
|
||||||
p.text = "This index contains %s entries, referring to %i individual manual pages." % (len(index), len(argv)-1)
|
|
||||||
|
|
||||||
if hasattr(stdout, "buffer"):
|
|
||||||
stdout = stdout.buffer
|
|
||||||
prettify(html)
|
|
||||||
stdout.write(tostring(html))
|
|
||||||
|
|
1
man/.gitignore
vendored
1
man/.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
/systemd.directives.xml
|
/systemd.directives.xml
|
||||||
|
/systemd.index.xml
|
||||||
/*.[13578]
|
/*.[13578]
|
||||||
|
|
Loading…
Reference in a new issue