1#!/usr/bin/env python3 2# SPDX-License-Identifier: LGPL-2.1-or-later 3from argparse import ArgumentParser 4from pathlib import Path 5from subprocess import run, PIPE 6 7def extract_interfaces_xml(output_dir, executable): 8 proc = run( 9 args=[executable.absolute(), '--bus-introspect', 'list'], 10 stdout=PIPE, 11 check=True, 12 universal_newlines=True) 13 14 interface_names = (x.split()[1] for x in proc.stdout.splitlines()) 15 16 for interface_name in interface_names: 17 proc = run( 18 args=[executable.absolute(), '--bus-introspect', interface_name], 19 stdout=PIPE, 20 check=True, 21 universal_newlines=True) 22 23 interface_file_name = output_dir / (interface_name + '.xml') 24 interface_file_name.write_text(proc.stdout) 25 interface_file_name.chmod(0o644) 26 27def main(): 28 parser = ArgumentParser() 29 parser.add_argument('output', 30 type=Path) 31 parser.add_argument('executables', 32 nargs='+', 33 type=Path) 34 35 args = parser.parse_args() 36 37 args.output.mkdir(exist_ok=True) 38 for exe in args.executables: 39 extract_interfaces_xml(args.output, exe) 40 41if __name__ == '__main__': 42 main() 43