diff options
author | Federico Mena Quintero <federico@gnome.org> | 2022-07-04 12:03:24 -0500 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2022-07-04 13:56:07 -0500 |
commit | 3244b4827b34b1cdae74351919fd079300aab687 (patch) | |
tree | 84a35f189307ca5a88ccc67845b789a7a3b94d12 /xml/generate-introspection.py | |
parent | fc9141e58893afd9101525df308c5d8fc5a067f1 (diff) | |
download | at-spi2-core-3244b4827b34b1cdae74351919fd079300aab687.tar.gz |
generate-introspection.py: Use an ArgumentParser to take multiple input filenames easily
Diffstat (limited to 'xml/generate-introspection.py')
-rw-r--r-- | xml/generate-introspection.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/xml/generate-introspection.py b/xml/generate-introspection.py index 3ba0b300..08f1900c 100644 --- a/xml/generate-introspection.py +++ b/xml/generate-introspection.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 # -# Takes a DBus XML file and writes out introspection.[ch] files for inclusion +# Takes DBus XML files and writes out a pair of introspection.[ch] files for inclusion # in C code. +import argparse import os import sys from xml.etree import ElementTree @@ -45,7 +46,7 @@ extern const char *%s; """ DEFTEMPLATE = """ -const char *%s = +const char *%s = %s; """ @@ -86,17 +87,17 @@ def generate_introspection (input_filename, c_output_filename, h_output_filename hfile.write (HTEMPLATE % (hcontents)) cfile.close () - hfile.close () - -if __name__ == "__main__": - argv = sys.argv + hfile.close () - if len (argv) != 4: - print("usage: generate-introspection.py INPUT.XML OUTPUT.C, OUTPUT.H", file=sys.stderr) - sys.exit(1) +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Create a C source file and header file from DBus XML files") + parser.add_argument('sources', metavar='FILE.XML', nargs='+', help='DBus XML interface file') + parser.add_argument('--c-output', metavar='OUT.C', required=True, help='Name out output C file') + parser.add_argument('--h-output', metavar='OUT.H', required=True, help='Name out output H file') + args = parser.parse_args() input_filename = sys.argv[1] c_output_filename = sys.argv[2] h_output_filename = sys.argv[3] - generate_introspection (input_filename, c_output_filename, h_output_filename) + generate_introspection (args.sources[0], args.c_output, args.h_output) |