From patchwork Mon May 11 07:24:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 470651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 93EB514010F for ; Mon, 11 May 2015 17:25:34 +1000 (AEST) Received: from localhost ([::1]:35868 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yri5k-0000My-IR for incoming@patchwork.ozlabs.org; Mon, 11 May 2015 03:25:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yri56-0007gp-PI for qemu-devel@nongnu.org; Mon, 11 May 2015 03:24:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yri52-0003bT-75 for qemu-devel@nongnu.org; Mon, 11 May 2015 03:24:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40632) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yri51-0003b7-St for qemu-devel@nongnu.org; Mon, 11 May 2015 03:24:48 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 7C351BDD98; Mon, 11 May 2015 07:24:47 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4B7OiFF024243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 11 May 2015 03:24:45 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D5F733008ABE; Mon, 11 May 2015 09:24:43 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 11 May 2015 09:24:38 +0200 Message-Id: <1431329083-32543-5-git-send-email-armbru@redhat.com> In-Reply-To: <1431329083-32543-1-git-send-email-armbru@redhat.com> References: <1431329083-32543-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 4/9] qapi: Factor parse_command_line() out of the generators X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi-commands.py | 34 +++------------------------------- scripts/qapi-event.py | 32 +------------------------------- scripts/qapi-types.py | 36 ++++-------------------------------- scripts/qapi-visit.py | 35 ++++------------------------------- scripts/qapi.py | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 125 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index c94a19b..2889877 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -15,9 +15,7 @@ from ordereddict import OrderedDict from qapi import * import re -import sys import os -import getopt import errno def generate_command_decl(name, args, ret_type): @@ -376,42 +374,16 @@ def gen_command_def_prologue(prefix="", proxy=False): ret += '#include "%sqmp-commands.h"' % prefix return ret + "\n\n" - -try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m", - ["source", "header", "prefix=", - "input-file=", "output-dir=", - "middle"]) -except getopt.GetoptError, err: - print str(err) - sys.exit(1) - -output_dir = "" -prefix = "" c_file = 'qmp-marshal.c' h_file = 'qmp-commands.h' middle_mode = False -do_c = False -do_h = False +(input_file, output_dir, do_c, do_h, prefix, opts) = \ + parse_command_line("m", ["middle"]) for o, a in opts: - 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 ("-m", "--middle"): + if o in ("-m", "--middle"): middle_mode = True - elif o in ("-c", "--source"): - do_c = True - elif o in ("-h", "--header"): - do_h = True - -if not do_c and not do_h: - do_c = True - do_h = True c_file = output_dir + prefix + c_file h_file = output_dir + prefix + h_file diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index 3e1f4cf..bc5ca4a 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -11,9 +11,7 @@ from ordereddict import OrderedDict from qapi import * -import sys import os -import getopt import errno def _generate_event_api_name(event_name, params): @@ -219,38 +217,10 @@ const char *%(event_enum_name)s_lookup[] = { # Start the real job -try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:", - ["source", "header", "prefix=", - "input-file=", "output-dir="]) -except getopt.GetoptError, err: - print str(err) - sys.exit(1) - -input_file = "" -output_dir = "" -prefix = "" c_file = 'qapi-event.c' h_file = 'qapi-event.h' -do_c = False -do_h = False - -for o, a in opts: - 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 - -if not do_c and not do_h: - do_c = True - do_h = True +(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line() c_file = output_dir + prefix + c_file h_file = output_dir + prefix + h_file diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 5665145..62044c1 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -11,9 +11,7 @@ from ordereddict import OrderedDict from qapi import * -import sys import os -import getopt import errno def generate_fwd_struct(name, members, builtin_type=False): @@ -275,43 +273,17 @@ void qapi_free_%(name)s(%(c_type)s obj) c_type=c_type(name), name=c_name(name)) return ret - -try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:", - ["source", "header", "builtins", - "prefix=", "input-file=", "output-dir="]) -except getopt.GetoptError, err: - print str(err) - sys.exit(1) - -output_dir = "" -input_file = "" -prefix = "" c_file = 'qapi-types.c' h_file = 'qapi-types.h' - -do_c = False -do_h = False do_builtins = False +(input_file, output_dir, do_c, do_h, prefix, opts) = \ + parse_command_line("b", ["builtins"]) + for o, a in opts: - 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 - elif o in ("-b", "--builtins"): + if o in ("-b", "--builtins"): do_builtins = True -if not do_c and not do_h: - do_c = True - do_h = True - c_file = output_dir + prefix + c_file h_file = output_dir + prefix + h_file diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index a16cc54..f3e31cc 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -15,9 +15,7 @@ from ordereddict import OrderedDict from qapi import * import re -import sys import os -import getopt import errno implicit_structs = [] @@ -377,42 +375,17 @@ void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error **er ''', name=c_name(name)) -try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:", - ["source", "header", "builtins", "prefix=", - "input-file=", "output-dir="]) -except getopt.GetoptError, err: - print str(err) - sys.exit(1) - -input_file = "" -output_dir = "" -prefix = "" c_file = 'qapi-visit.c' h_file = 'qapi-visit.h' - -do_c = False -do_h = False do_builtins = False +(input_file, output_dir, do_c, do_h, prefix, opts) = \ + parse_command_line("b", ["builtins"]) + for o, a in opts: - 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 - elif o in ("-b", "--builtins"): + if o in ("-b", "--builtins"): do_builtins = True -if not do_c and not do_h: - do_c = True - do_h = True - c_file = output_dir + prefix + c_file h_file = output_dir + prefix + h_file diff --git a/scripts/qapi.py b/scripts/qapi.py index b69600b..d90a538 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 @@ -960,3 +961,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)