From d986cb7c70db3b512f6ee0bbc95ba2565606c222 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 20 May 2015 15:19:28 -0700 Subject: [PATCH] glapi: glX_proto_recv.py: use argparse instead of getopt Signed-off-by: Dylan Baker Acked-by: Matt Turner --- src/mapi/glapi/gen/glX_proto_recv.py | 55 +++++++++++++++------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/mapi/glapi/gen/glX_proto_recv.py b/src/mapi/glapi/gen/glX_proto_recv.py index d076409c2fa..dbc26a8eb03 100644 --- a/src/mapi/glapi/gen/glX_proto_recv.py +++ b/src/mapi/glapi/gen/glX_proto_recv.py @@ -25,8 +25,10 @@ # Authors: # Ian Romanick +import argparse +import string + import gl_XML, glX_XML, glX_proto_common, license -import sys, getopt, string class PrintGlxDispatch_h(gl_XML.gl_print_base): @@ -524,31 +526,34 @@ class PrintGlxDispatchFunctions(glX_proto_common.glx_print_proto): return +def _parser(): + """Parse any arguments passed and return a namespace.""" + parser = argparse.ArgumentParser() + parser.add_argument('-f', + dest='filename', + default='gl_API.xml', + help='an xml file describing an OpenGL API') + parser.add_argument('-m', + dest='mode', + default='dispatch_c', + choices=['dispatch_c', 'dispatch_h'], + help='what file to generate') + parser.add_argument('-s', + dest='swap', + action='store_true', + help='emit swap in GlXDispatchFunctions') + return parser.parse_args() + + if __name__ == '__main__': - file_name = "gl_API.xml" - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m:s") - except Exception,e: - show_usage() - - mode = "dispatch_c" - do_swap = 0 - for (arg,val) in args: - if arg == "-f": - file_name = val - elif arg == "-m": - mode = val - elif arg == "-s": - do_swap = 1 - - if mode == "dispatch_c": - printer = PrintGlxDispatchFunctions(do_swap) - elif mode == "dispatch_h": + args = _parser() + + if args._mode == "dispatch_c": + printer = PrintGlxDispatchFunctions(args.swap) + elif args._mode == "dispatch_h": printer = PrintGlxDispatch_h() - else: - show_usage() - api = gl_XML.parse_GL_API( file_name, glX_proto_common.glx_proto_item_factory() ) + api = gl_XML.parse_GL_API( + args.filename, glX_proto_common.glx_proto_item_factory()) - printer.Print( api ) + printer.Print(api) -- 2.30.2