summaryrefslogtreecommitdiffstats
path: root/src/mapi/glapi
diff options
context:
space:
mode:
authorDylan Baker <[email protected]>2014-11-19 13:36:35 -0800
committerMatt Turner <[email protected]>2015-05-22 11:31:27 -0700
commitcf718cc964f86dc49c1fc9ed5e39aa5bd87ad931 (patch)
tree1b2614533557918c8a3ccaa22264539eff7c13b8 /src/mapi/glapi
parentb6298c7a7143eafea3c1be6e98af1d0239fdf5b7 (diff)
glapi: gl_table.py: replace getopt with argparse.
This results in slightly less code, but code that is much more readable. It has the advantage of putting everything together in one place, all of the code is self documenting, help messages are auto-generated, choices are automatically enforced, and the syntax is much less C like, taking advantage of python features and idioms. Signed-off-by: Dylan Baker <[email protected]> Acked-by: Matt Turner <[email protected]>
Diffstat (limited to 'src/mapi/glapi')
-rw-r--r--src/mapi/glapi/gen/gl_table.py70
1 files changed, 33 insertions, 37 deletions
diff --git a/src/mapi/glapi/gen/gl_table.py b/src/mapi/glapi/gen/gl_table.py
index 32456250dc4..30903fd8f60 100644
--- a/src/mapi/glapi/gen/gl_table.py
+++ b/src/mapi/glapi/gen/gl_table.py
@@ -26,8 +26,7 @@
# Authors:
# Ian Romanick <[email protected]>
-import sys
-import getopt
+import argparse
import gl_XML
import license
@@ -203,45 +202,42 @@ class PrintRemapTable(gl_XML.gl_print_base):
return
-def show_usage():
- print "Usage: %s [-f input_file_name] [-m mode] [-c ver]" % sys.argv[0]
- print " -m mode Mode can be 'table' or 'remap_table'."
- print " -c ver Version can be 'es1' or 'es2'."
- sys.exit(1)
+def _parser():
+ """Parse arguments and return a namespace."""
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-f', '--filename',
+ type=gl_XML.parse_GL_API,
+ default='gl_API.xml',
+ metavar="input_file_name",
+ dest='api',
+ help="Path to an XML description of OpenGL API.")
+ parser.add_argument('-m', '--mode',
+ choices=['table', 'remap_table'],
+ default='table',
+ metavar="mode",
+ help="Generate either a table or a remap_table")
+ parser.add_argument('-c', '--es-version',
+ choices=[None, 'es1', 'es2'],
+ default=None,
+ metavar="ver",
+ dest='es',
+ help="filter functions for es")
+ return parser.parse_args()
def main():
"""Main function."""
- file_name = "gl_API.xml"
-
- try:
- args, _ = getopt.getopt(sys.argv[1:], "f:m:c:")
- except Exception:
- show_usage()
-
- mode = "table"
- es = None
- for (arg, val) in args:
- if arg == "-f":
- file_name = val
- elif arg == "-m":
- mode = val
- elif arg == "-c":
- es = val
-
- if mode == "table":
- printer = PrintGlTable(es)
- elif mode == "remap_table":
- printer = PrintRemapTable(es)
- else:
- show_usage()
-
- api = gl_XML.parse_GL_API(file_name)
-
- if es is not None:
- api.filter_functions_by_api(es)
-
- printer.Print(api)
+ args = _parser()
+
+ if args.mode == "table":
+ printer = PrintGlTable(args.es)
+ elif args.mode == "remap_table":
+ printer = PrintRemapTable(args.es)
+
+ if args.es is not None:
+ args.api.filter_functions_by_api(args.es)
+
+ printer.Print(args.api)
if __name__ == '__main__':