From patchwork Fri Feb 2 13:03:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 868667 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3zY2Y43yLKz9t20 for ; Sat, 3 Feb 2018 03:31:04 +1100 (AEDT) Received: from localhost ([::1]:38951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eheEw-0001YE-H4 for incoming@patchwork.ozlabs.org; Fri, 02 Feb 2018 11:31:02 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehdMa-0002hf-Sm for qemu-devel@nongnu.org; Fri, 02 Feb 2018 10:35:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ehdLV-0004e8-OH for qemu-devel@nongnu.org; Fri, 02 Feb 2018 10:34:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58930) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ehdLU-0004cE-Uv for qemu-devel@nongnu.org; Fri, 02 Feb 2018 10:33:45 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2CB6D70D73; Fri, 2 Feb 2018 13:04:57 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-148.ams2.redhat.com [10.36.116.148]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7B327CD9F; Fri, 2 Feb 2018 13:04:19 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B6C591138651; Fri, 2 Feb 2018 14:03:36 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 2 Feb 2018 14:03:22 +0100 Message-Id: <20180202130336.24719-8-armbru@redhat.com> In-Reply-To: <20180202130336.24719-1-armbru@redhat.com> References: <20180202130336.24719-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 02 Feb 2018 13:04:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 07/21] qapi: Move parse_command_line() next to its only use X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Marc-André Lureau --- scripts/qapi-gen.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++- scripts/qapi/common.py | 54 -------------------------------------------------- 2 files changed, 51 insertions(+), 55 deletions(-) diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py index 575c938a1b..6302fd0d55 100755 --- a/scripts/qapi-gen.py +++ b/scripts/qapi-gen.py @@ -4,8 +4,10 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. +import getopt +import re import sys -from qapi.common import parse_command_line, QAPISchema +from qapi.common import QAPISchema from qapi.types import gen_types from qapi.visit import gen_visit from qapi.commands import gen_commands @@ -14,6 +16,54 @@ from qapi.introspect import gen_introspect from qapi.doc import gen_doc +def parse_command_line(extra_options='', extra_long_options=[]): + + try: + opts, args = getopt.gnu_getopt(sys.argv[1:], + 'chp:o:' + extra_options, + ['source', 'header', 'prefix=', + 'output-dir='] + extra_long_options) + except getopt.GetoptError as err: + print >>sys.stderr, "%s: %s" % (sys.argv[0], 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'): + match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', a) + if match.end() != len(a): + print >>sys.stderr, \ + "%s: 'funny character '%s' in argument of --prefix" \ + % (sys.argv[0], a[match.end()]) + sys.exit(1) + prefix = 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 + + if len(args) != 1: + print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0] + sys.exit(1) + fname = args[0] + + return (fname, output_dir, do_c, do_h, prefix, extra_opts) + + def main(argv): (input_file, output_dir, do_c, do_h, prefix, opts) = \ parse_command_line('bu', ['builtins', 'unmask-non-abi-names']) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index d73ef618e2..cfa2671ca3 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -12,7 +12,6 @@ # See the COPYING file in the top-level directory. import errno -import getopt import os import re import string @@ -1917,59 +1916,6 @@ def build_params(arg_type, boxed, extra): # -# Common command line parsing -# - - -def parse_command_line(extra_options='', extra_long_options=[]): - - try: - opts, args = getopt.gnu_getopt(sys.argv[1:], - 'chp:o:' + extra_options, - ['source', 'header', 'prefix=', - 'output-dir='] + extra_long_options) - except getopt.GetoptError as err: - print >>sys.stderr, "%s: %s" % (sys.argv[0], 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'): - match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', a) - if match.end() != len(a): - print >>sys.stderr, \ - "%s: 'funny character '%s' in argument of --prefix" \ - % (sys.argv[0], a[match.end()]) - sys.exit(1) - prefix = 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 - - if len(args) != 1: - print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0] - sys.exit(1) - fname = args[0] - - return (fname, output_dir, do_c, do_h, prefix, extra_opts) - - -# # Accumulate and write output #