aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi.py
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2015-04-02 13:12:21 +0200
committerMarkus Armbruster <armbru@redhat.com>2015-05-14 18:37:14 +0200
commit2114f5a98d0d80774306279e1694de074ca86aa0 (patch)
tree8d20953275cd846c3a04e49a1aa29ddb6f4e7d49 /scripts/qapi.py
parent72aaa73a4acef06bfaed750064c40a597f0cf745 (diff)
qapi: Factor parse_command_line() out of the generators
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi.py')
-rw-r--r--scripts/qapi.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 273afedc3d..b97dd0b14a 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -13,6 +13,7 @@
import re
from ordereddict import OrderedDict
+import getopt
import os
import sys
import string
@@ -978,3 +979,42 @@ def guardend(name):
''',
name=guardname(name))
+
+def parse_command_line(extra_options = "", extra_long_options = []):
+
+ try:
+ opts, args = getopt.gnu_getopt(sys.argv[1:],
+ "chp:i:o:" + extra_options,
+ ["source", "header", "prefix=",
+ "input-file=", "output-dir="]
+ + extra_long_options)
+ except getopt.GetoptError, err:
+ print str(err)
+ sys.exit(1)
+
+ output_dir = ""
+ prefix = ""
+ do_c = False
+ do_h = False
+ extra_opts = []
+
+ for oa in opts:
+ o, a = oa
+ if o in ("-p", "--prefix"):
+ prefix = a
+ elif o in ("-i", "--input-file"):
+ input_file = a
+ elif o in ("-o", "--output-dir"):
+ output_dir = a + "/"
+ elif o in ("-c", "--source"):
+ do_c = True
+ elif o in ("-h", "--header"):
+ do_h = True
+ else:
+ extra_opts.append(oa)
+
+ if not do_c and not do_h:
+ do_c = True
+ do_h = True
+
+ return (input_file, output_dir, do_c, do_h, prefix, extra_opts)