glapi: glX_proto_recv.py: use argparse instead of getopt
authorDylan Baker <baker.dylan.c@gmail.com>
Wed, 20 May 2015 22:19:28 +0000 (15:19 -0700)
committerMatt Turner <mattst88@gmail.com>
Fri, 22 May 2015 18:31:28 +0000 (11:31 -0700)
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
Acked-by: Matt Turner <mattst88@gmail.com>
src/mapi/glapi/gen/glX_proto_recv.py

index d076409c2faccd8083bff9131b10f1d3d31ce19b..dbc26a8eb03aca6ecaedf18c486cc4952280cf12 100644 (file)
 # Authors:
 #    Ian Romanick <idr@us.ibm.com>
 
+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)