]>
git.ipfire.org Git - thirdparty/systemd.git/blob - tools/make-man-rules.py
2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # SPDX-License-Identifier: LGPL-2.1+
5 from __future__
import print_function
10 from xml_helper
import xml_parse
12 def man(page
, number
):
13 return '{}.{}'.format(page
, number
)
16 return os
.path
.basename(file)
18 def add_rules(rules
, name
):
20 # print('parsing {}'.format(name), file=sys.stderr)
21 if xml
.getroot().tag
!= 'refentry':
23 conditional
= xml
.getroot().get('conditional') or ''
24 rulegroup
= rules
[conditional
]
25 refmeta
= xml
.find('./refmeta')
26 title
= refmeta
.find('./refentrytitle').text
27 number
= refmeta
.find('./manvolnum').text
28 refnames
= xml
.findall('./refnamediv/refname')
29 target
= man(refnames
[0].text
, number
)
30 if title
!= refnames
[0].text
:
31 raise ValueError('refmeta and refnamediv disagree: ' + name
)
32 for refname
in refnames
:
33 assert all(refname
not in group
34 for group
in rules
.values()), "duplicate page name"
35 alias
= man(refname
.text
, number
)
36 rulegroup
[alias
] = target
37 # print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr)
39 def create_rules(xml_files
):
40 " {conditional => {alias-name => source-name}} "
41 rules
= collections
.defaultdict(dict)
42 for name
in xml_files
:
44 add_rules(rules
, name
)
46 print("Failed to process", name
, file=sys
.stderr
)
51 return ' \\\n\t'.join(sorted(files
) or '#')
54 # Do not edit. Generated by make-man-rules.py.
59 # Really, do not edit.'''
61 def make_mesonfile(rules
, dist_files
):
63 # grouped = [ [name, section, [alias...], condition], ...]
65 # but first create a dictionary like
66 # lists = { (name, condition) => [alias...]
67 grouped
= collections
.defaultdict(list)
68 for condition
, items
in rules
.items():
69 for alias
, name
in items
.items():
70 group
= grouped
[(name
, condition
)]
74 lines
= [ [p
[0][:-2], p
[0][-1], sorted(a
[:-2] for a
in aliases
), p
[1]]
75 for p
, aliases
in sorted(grouped
.items()) ]
76 return '\n'.join((MESON_HEADER
, pprint
.pformat(lines
)[1:-1], MESON_FOOTER
))
78 if __name__
== '__main__':
81 rules
= create_rules(pages
)
82 dist_files
= (xml(file) for file in pages
83 if not file.endswith(".directives.xml") and
84 not file.endswith(".index.xml"))
85 print(make_mesonfile(rules
, dist_files
))