From: Yu Watanabe Date: Thu, 19 Feb 2026 17:12:28 +0000 (+0900) Subject: update-man-rules: apply "ruff format" X-Git-Tag: v261-rc1~126^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fc2bde0db27d48838718320408606f35f237143;p=thirdparty%2Fsystemd.git update-man-rules: apply "ruff format" --- diff --git a/tools/update-man-rules.py b/tools/update-man-rules.py index 2ac8dae5604..bc233aba948 100755 --- a/tools/update-man-rules.py +++ b/tools/update-man-rules.py @@ -13,6 +13,7 @@ from xml_helper import xml_parse def man(page, number): return f'{page}.{number}' + def add_rules(rules, name): xml = xml_parse(name) # print('parsing {}'.format(name), file=sys.stderr) @@ -28,26 +29,28 @@ def add_rules(rules, name): if title != refnames[0].text: raise ValueError('refmeta and refnamediv disagree: ' + name) for refname in refnames: - assert all(refname not in group - for group in rules.values()), "duplicate page name" + assert all(refname not in group for group in rules.values()), 'duplicate page name' alias = man(refname.text, number) rulegroup[alias] = target # print('{} => {} [{}]'.format(alias, target, conditional), file=sys.stderr) + def create_rules(xml_files): - " {conditional => {alias-name => source-name}} " + "{conditional => {alias-name => source-name}}" rules = collections.defaultdict(dict) for name in xml_files: try: add_rules(rules, name) except Exception: - print("Failed to process", name, file=sys.stderr) + print('Failed to process', name, file=sys.stderr) raise return rules + def mjoin(files): return ' \\\n\t'.join(sorted(files) or '#') + MESON_HEADER = '''\ # Do not edit. Generated by update-man-rules.py. # Update with: @@ -59,6 +62,7 @@ MESON_FOOTER = '''\ # Really, do not edit. ''' + def make_mesonfile(rules, _dist_files): # reformat rules as # grouped = [ [name, section, [alias...], condition], ...] @@ -72,10 +76,13 @@ def make_mesonfile(rules, _dist_files): if name != alias: group.append(alias) - lines = [ [p[0][:-2], p[0][-1], sorted(a[:-2] for a in aliases), p[1]] - for p, aliases in sorted(grouped.items()) ] + lines = [ + [p[0][:-2], p[0][-1], sorted(a[:-2] for a in aliases), p[1]] + for p, aliases in sorted(grouped.items()) + ] return '\n'.join((MESON_HEADER, pprint.pformat(lines)[1:-1], MESON_FOOTER)) + def main(): source_glob = sys.argv[1] target = Path(sys.argv[2]) @@ -86,7 +93,7 @@ def main(): 'standard-conf.xml', 'systemd.directives.xml', 'systemd.index.xml', - 'directives-template.xml'}) + 'directives-template.xml'}) # fmt: skip rules = create_rules(pages) dist_files = (Path(p).name for p in pages) @@ -96,5 +103,6 @@ def main(): tmp.write_text(text) tmp.rename(target) + if __name__ == '__main__': main()