From nobody Tue Feb 10 13:16:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517589155174149.924067638064; Fri, 2 Feb 2018 08:32:35 -0800 (PST) Received: from localhost ([::1]:38964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eheGL-0002mP-Bm for importer@patchew.org; Fri, 02 Feb 2018 11:32:29 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Marc-Andr=C3=A9 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. =20 +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 =20 =20 +def parse_command_line(extra_options=3D'', extra_long_options=3D[]): + + try: + opts, args =3D getopt.gnu_getopt(sys.argv[1:], + 'chp:o:' + extra_options, + ['source', 'header', 'prefix=3D', + 'output-dir=3D'] + extra_long_opti= ons) + except getopt.GetoptError as err: + print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err)) + sys.exit(1) + + output_dir =3D '' + prefix =3D '' + do_c =3D False + do_h =3D False + extra_opts =3D [] + + for oa in opts: + o, a =3D oa + if o in ('-p', '--prefix'): + match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', a) + if match.end() !=3D len(a): + print >>sys.stderr, \ + "%s: 'funny character '%s' in argument of --prefix" \ + % (sys.argv[0], a[match.end()]) + sys.exit(1) + prefix =3D a + elif o in ('-o', '--output-dir'): + output_dir =3D a + '/' + elif o in ('-c', '--source'): + do_c =3D True + elif o in ('-h', '--header'): + do_h =3D True + else: + extra_opts.append(oa) + + if not do_c and not do_h: + do_c =3D True + do_h =3D True + + if len(args) !=3D 1: + print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0] + sys.exit(1) + fname =3D 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) =3D \ 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. =20 import errno -import getopt import os import re import string @@ -1917,59 +1916,6 @@ def build_params(arg_type, boxed, extra): =20 =20 # -# Common command line parsing -# - - -def parse_command_line(extra_options=3D'', extra_long_options=3D[]): - - try: - opts, args =3D getopt.gnu_getopt(sys.argv[1:], - 'chp:o:' + extra_options, - ['source', 'header', 'prefix=3D', - 'output-dir=3D'] + extra_long_opti= ons) - except getopt.GetoptError as err: - print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err)) - sys.exit(1) - - output_dir =3D '' - prefix =3D '' - do_c =3D False - do_h =3D False - extra_opts =3D [] - - for oa in opts: - o, a =3D oa - if o in ('-p', '--prefix'): - match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', a) - if match.end() !=3D len(a): - print >>sys.stderr, \ - "%s: 'funny character '%s' in argument of --prefix" \ - % (sys.argv[0], a[match.end()]) - sys.exit(1) - prefix =3D a - elif o in ('-o', '--output-dir'): - output_dir =3D a + '/' - elif o in ('-c', '--source'): - do_c =3D True - elif o in ('-h', '--header'): - do_h =3D True - else: - extra_opts.append(oa) - - if not do_c and not do_h: - do_c =3D True - do_h =3D True - - if len(args) !=3D 1: - print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0] - sys.exit(1) - fname =3D args[0] - - return (fname, output_dir, do_c, do_h, prefix, extra_opts) - - -# # Accumulate and write output # =20 --=20 2.13.6