From 77d45f1f8302ebe4cb9be680c3f395db839fc864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 22 Mar 2022 21:51:33 +0100 Subject: meson: replace sh+find with an internal glob in the python helper As suggested in https://github.com/systemd/systemd/pull/22810#discussion_r831708052 This makes the whole thing simpler. A glob is passed to helper which then resolves it on its own. This way it's trivial to call the helper with a different set of files for testing. --- tools/update-man-rules.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/update-man-rules.py b/tools/update-man-rules.py index 31ed91c432..3a8c31dc35 100755 --- a/tools/update-man-rules.py +++ b/tools/update-man-rules.py @@ -3,9 +3,10 @@ from __future__ import print_function import collections +import glob import sys +from pathlib import Path import pprint -from os.path import basename from xml_helper import xml_parse def man(page, number): @@ -56,7 +57,8 @@ manpages = [''' MESON_FOOTER = '''\ ] -# Really, do not edit.''' +# Really, do not edit. +''' def make_mesonfile(rules, dist_files): # reformat rules as @@ -76,13 +78,20 @@ def make_mesonfile(rules, dist_files): return '\n'.join((MESON_HEADER, pprint.pformat(lines)[1:-1], MESON_FOOTER)) if __name__ == '__main__': - pages = sys.argv[1:] + source_glob = sys.argv[1] + target = Path(sys.argv[2]) + + pages = glob.glob(source_glob) pages = (p for p in pages - if basename(p) not in { + if Path(p).name not in { 'systemd.directives.xml', 'systemd.index.xml', 'directives-template.xml'}) rules = create_rules(pages) - dist_files = (basename(p) for p in pages) - print(make_mesonfile(rules, dist_files)) + dist_files = (Path(p).name for p in pages) + text = make_mesonfile(rules, dist_files) + + tmp = target.with_suffix('.tmp') + tmp.write_text(text) + tmp.rename(target) -- cgit v1.2.1