]>
git.ipfire.org Git - thirdparty/systemd.git/blob - make-man-rules.py
1 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # This file is part of systemd.
5 # Copyright 2013 Zbigniew Jędrzejewski-Szmek
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.
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.
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/>.
20 from __future__
import print_function
23 from xml_helper
import *
43 # Do not edit. Generated by make-man-rules.py.
44 # Regenerate with 'make all update-man-list'.
48 HTML_ALIAS_RULE
= '''\
53 def man(page
, number
):
54 return 'man/{}.{}'.format(page
, number
)
56 def add_rules(rules
, name
):
58 # print('parsing {}'.format(name), file=sys.stderr)
59 conditional
= xml
.getroot().get('conditional') or ''
60 rulegroup
= rules
[conditional
]
61 refmeta
= xml
.find('./refmeta')
62 title
= refmeta
.find('./refentrytitle').text
63 number
= refmeta
.find('./manvolnum').text
64 refnames
= xml
.findall('./refnamediv/refname')
65 target
= man(refnames
[0].text
, number
)
66 if title
!= refnames
[0].text
:
67 raise ValueError('refmeta and refnamediv disagree: ' + name
)
68 for refname
in refnames
:
69 assert all(refname
not in group
70 for group
in rules
.values()), "duplicate page name"
71 alias
= man(refname
.text
, number
)
72 rulegroup
[alias
] = target
73 # print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr)
75 def create_rules(*xml_files
):
76 " {conditional => {alias-name => source-name}} "
77 rules
= collections
.defaultdict(dict)
78 for name
in xml_files
:
79 add_rules(rules
, name
)
83 return ' \\\n\t'.join(sorted(files
) or '#')
85 def make_makefile(rules
):
86 return HEADER
+ '\n'.join(
87 (CONDITIONAL
if conditional
else SECTION
).format(
88 manpages
=mjoin(set(rulegroup
.values())),
89 aliases
=mjoin(k
for k
,v
in rulegroup
.items() if k
!= v
),
90 rules
='\n'.join('{}: {}'.format(k
,v
)
91 for k
,v
in sorted(rulegroup
.items())
93 htmlrules
='\n'.join(HTML_ALIAS_RULE
.format(k
[:-2],v
[:-2])
94 for k
,v
in sorted(rulegroup
.items())
96 conditional
=conditional
)
97 for conditional
,rulegroup
in sorted(rules
.items()))
99 if __name__
== '__main__':
100 rules
= create_rules(*sys
.argv
[1:])
101 print(make_makefile(rules
), end
='')