diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-03-22 10:10:39 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-03-22 14:07:53 +0100 |
commit | 3b9d38f5c8711f138456e65aec3b69c55ed1ea19 (patch) | |
tree | a82d34daa4d799c7fa6273b2ed6d852839d92275 | |
parent | 94f7ee9770161604c60dd0949c65173ca34d774f (diff) | |
download | systemd-3b9d38f5c8711f138456e65aec3b69c55ed1ea19.tar.gz |
tools/dbus_exporter: deblackify and shorten code a bit
When we do mkdir, we should just use 0o777 and let the umask take care of the
rest. Specifying an explicit mode is inappropriate. And when touching the code,
let's replace black madness with normal python style.
-rwxr-xr-x | tools/dbus_exporter.py | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/tools/dbus_exporter.py b/tools/dbus_exporter.py index 4da8b82af4..f94f261e07 100755 --- a/tools/dbus_exporter.py +++ b/tools/dbus_exporter.py @@ -4,58 +4,39 @@ from argparse import ArgumentParser from pathlib import Path from subprocess import run, PIPE - def extract_interfaces_xml(output_dir, executable): - list_interfaces_process = run( + proc = run( args=[executable.absolute(), '--bus-introspect', 'list'], stdout=PIPE, check=True, - universal_newlines=True, - ) - - interfaces_lines = list_interfaces_process.stdout.splitlines() + universal_newlines=True) - interface_names = [x.split()[1] for x in interfaces_lines] + interface_names = (x.split()[1] for x in proc.stdout.splitlines()) for interface_name in interface_names: - interface_introspection_run = run( + proc = run( args=[executable.absolute(), '--bus-introspect', interface_name], stdout=PIPE, check=True, - universal_newlines=True, - ) + universal_newlines=True) interface_file_name = output_dir / (interface_name + '.xml') - with open(interface_file_name, mode='w') as f: - f.write(interface_introspection_run.stdout) + interface_file_name.write_text(proc.stdout) interface_file_name.chmod(0o644) - -def iterate_executables(output_dir, executables): - output_dir.mkdir(mode=0o755, exist_ok=True) - - for exe in executables: - extract_interfaces_xml(output_dir, exe) - - def main(): parser = ArgumentParser() - - parser.add_argument( - 'output', - type=Path, - ) - - parser.add_argument( - 'executables', - type=Path, - nargs='+', - ) + parser.add_argument('output', + type=Path) + parser.add_argument('executables', + nargs='+', + type=Path) args = parser.parse_args() - iterate_executables(args.output, args.executables) - + args.output.mkdir(exist_ok=True) + for exe in args.executables: + extract_interfaces_xml(args.output, exe) if __name__ == '__main__': main() |