]>
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 # This file is part of systemd.
7 # Copyright 2013, 2017 Zbigniew Jędrzejewski-Szmek
9 # systemd is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published by
11 # the Free Software Foundation; either version 2.1 of the License, or
12 # (at your option) any later version.
14 # systemd is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 from __future__
import print_function
27 from xml_helper
import xml_parse
29 def man(page
, number
):
30 return '{}.{}'.format(page
, number
)
33 return os
.path
.basename(file)
35 def add_rules(rules
, name
):
37 # print('parsing {}'.format(name), file=sys.stderr)
38 if xml
.getroot().tag
!= 'refentry':
40 conditional
= xml
.getroot().get('conditional') or ''
41 rulegroup
= rules
[conditional
]
42 refmeta
= xml
.find('./refmeta')
43 title
= refmeta
.find('./refentrytitle').text
44 number
= refmeta
.find('./manvolnum').text
45 refnames
= xml
.findall('./refnamediv/refname')
46 target
= man(refnames
[0].text
, number
)
47 if title
!= refnames
[0].text
:
48 raise ValueError('refmeta and refnamediv disagree: ' + name
)
49 for refname
in refnames
:
50 assert all(refname
not in group
51 for group
in rules
.values()), "duplicate page name"
52 alias
= man(refname
.text
, number
)
53 rulegroup
[alias
] = target
54 # print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr)
56 def create_rules(xml_files
):
57 " {conditional => {alias-name => source-name}} "
58 rules
= collections
.defaultdict(dict)
59 for name
in xml_files
:
61 add_rules(rules
, name
)
63 print("Failed to process", name
, file=sys
.stderr
)
68 return ' \\\n\t'.join(sorted(files
) or '#')
71 # Do not edit. Generated by make-man-rules.py.
76 # Really, do not edit.'''
78 def make_mesonfile(rules
, dist_files
):
80 # grouped = [ [name, section, [alias...], condition], ...]
82 # but first create a dictionary like
83 # lists = { (name, condition) => [alias...]
84 grouped
= collections
.defaultdict(list)
85 for condition
, items
in rules
.items():
86 for alias
, name
in items
.items():
87 group
= grouped
[(name
, condition
)]
91 lines
= [ [p
[0][:-2], p
[0][-1], sorted(a
[:-2] for a
in aliases
), p
[1]]
92 for p
, aliases
in sorted(grouped
.items()) ]
93 return '\n'.join((MESON_HEADER
, pprint
.pformat(lines
)[1:-1], MESON_FOOTER
))
95 if __name__
== '__main__':
98 rules
= create_rules(pages
)
99 dist_files
= (xml(file) for file in pages
100 if not file.endswith(".directives.xml") and
101 not file.endswith(".index.xml"))
102 print(make_mesonfile(rules
, dist_files
))