[Mesa-dev] [RFC 01/13] glapi/gen: gl_marshal_h.py: Use argparse instead of getopt

Dylan Baker dylan at pnwbakers.com
Fri Nov 23 22:27:50 UTC 2018


It's more modern and has more useful features, like automatic usage
generation, which means less code.
---
 src/mapi/glapi/gen/gl_marshal_h.py | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/src/mapi/glapi/gen/gl_marshal_h.py b/src/mapi/glapi/gen/gl_marshal_h.py
index a7a9eda5731..d870bba5ed6 100644
--- a/src/mapi/glapi/gen/gl_marshal_h.py
+++ b/src/mapi/glapi/gen/gl_marshal_h.py
@@ -1,5 +1,6 @@
-
+# encoding=utf-8
 # Copyright (C) 2012 Intel Corporation
+# Copyright © 2018 Intel Corporation
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
@@ -21,8 +22,8 @@
 # IN THE SOFTWARE.
 
 from __future__ import print_function
+import argparse
 
-import getopt
 import gl_XML
 import license
 import marshal_XML
@@ -64,24 +65,13 @@ class PrintCode(gl_XML.gl_print_base):
         print('};')
 
 
-def show_usage():
-    print('Usage: %s [-f input_file_name]' % sys.argv[0])
-    sys.exit(1)
-
 
 if __name__ == '__main__':
-    file_name = 'gl_API.xml'
-
-    try:
-        (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:')
-    except Exception:
-        show_usage()
-
-    for (arg,val) in args:
-        if arg == '-f':
-            file_name = val
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-f', '--filename', metavar='input_file_name', default='gl_API.xml')
+    args = parser.parse_args()
 
     printer = PrintCode()
 
-    api = gl_XML.parse_GL_API(file_name, marshal_XML.marshal_item_factory())
+    api = gl_XML.parse_GL_API(args.filename, marshal_XML.marshal_item_factory())
     printer.Print(api)
-- 
2.19.2



More information about the mesa-dev mailing list