From 0f5cea021252e1524776c992fb6a7bb1d55b1b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 27 Aug 2020 19:27:18 +0200 Subject: update-dbus-docs: use argparse --- tools/update-dbus-docs.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'tools') diff --git a/tools/update-dbus-docs.py b/tools/update-dbus-docs.py index 8aa3742f60..bfe55220c1 100755 --- a/tools/update-dbus-docs.py +++ b/tools/update-dbus-docs.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: LGPL-2.1+ +import argparse import collections import sys import os @@ -178,7 +179,7 @@ def subst_output(document, programlisting, stats): node = programlisting.get('node') interface = programlisting.get('interface') - argv = [f'{build_dir}/{executable}', f'--bus-introspect={interface}'] + argv = [f'{opts.build_dir}/{executable}', f'--bus-introspect={interface}'] print(f'COMMAND: {shlex.join(argv)}') try: @@ -275,19 +276,19 @@ def process(page): return stats -if __name__ == '__main__': - pages = sys.argv[1:] +def parse_args(): + p = argparse.ArgumentParser() + p.add_argument('--build-dir', default='build') + p.add_argument('pages', nargs='+') + return p.parse_args() - if pages[0].startswith('--build-dir='): - build_dir = pages[0].partition('=')[2] - pages = pages[1:] - else: - build_dir = 'build' +if __name__ == '__main__': + opts = parse_args() - if not os.path.exists(f'{build_dir}/systemd'): - exit(f"{build_dir}/systemd doesn't exist. Use --build-dir=.") + if not os.path.exists(f'{opts.build_dir}/systemd'): + exit(f"{opts.build_dir}/systemd doesn't exist. Use --build-dir=.") - stats = {page.split('/')[-1] : process(page) for page in pages} + stats = {page.split('/')[-1] : process(page) for page in opts.pages} # Let's print all statistics at the end mlen = max(len(page) for page in stats) -- cgit v1.2.1