2021-07-24 10:30:42 +03:00
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
from argparse import ArgumentParser
from pathlib import Path
2023-07-17 19:38:54 +03:00
from subprocess import PIPE , run
2021-07-24 10:30:42 +03:00
def extract_interfaces_xml ( output_dir , executable ) :
2022-03-22 12:10:39 +03:00
proc = run (
2021-07-24 10:30:42 +03:00
args = [ executable . absolute ( ) , ' --bus-introspect ' , ' list ' ] ,
stdout = PIPE ,
check = True ,
2022-03-22 12:10:39 +03:00
universal_newlines = True )
2021-07-24 10:30:42 +03:00
2022-03-22 12:10:39 +03:00
interface_names = ( x . split ( ) [ 1 ] for x in proc . stdout . splitlines ( ) )
2021-07-24 10:30:42 +03:00
for interface_name in interface_names :
2022-03-22 12:10:39 +03:00
proc = run (
2021-07-24 10:30:42 +03:00
args = [ executable . absolute ( ) , ' --bus-introspect ' , interface_name ] ,
stdout = PIPE ,
check = True ,
2022-03-22 12:10:39 +03:00
universal_newlines = True )
2021-07-24 10:30:42 +03:00
interface_file_name = output_dir / ( interface_name + ' .xml ' )
2022-03-22 12:10:39 +03:00
interface_file_name . write_text ( proc . stdout )
2021-07-24 10:30:42 +03:00
interface_file_name . chmod ( 0o644 )
def main ( ) :
parser = ArgumentParser ( )
2022-03-22 12:10:39 +03:00
parser . add_argument ( ' output ' ,
type = Path )
parser . add_argument ( ' executables ' ,
nargs = ' + ' ,
type = Path )
2021-07-24 10:30:42 +03:00
args = parser . parse_args ( )
2022-03-22 12:10:39 +03:00
args . output . mkdir ( exist_ok = True )
2024-03-21 21:14:56 +03:00
# Make sure we don't inherit any setgid/setuid bit or such.
args . output . chmod ( mode = 0o755 )
2022-03-22 12:10:39 +03:00
for exe in args . executables :
extract_interfaces_xml ( args . output , exe )
2021-07-24 10:30:42 +03:00
if __name__ == ' __main__ ' :
main ( )