From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIHgu-0001vQ-Ce for qemu-devel@nongnu.org; Fri, 15 Aug 2014 09:37:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIHgg-00067H-M3 for qemu-devel@nongnu.org; Fri, 15 Aug 2014 09:37:12 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:42493 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIHgg-00066J-C7 for qemu-devel@nongnu.org; Fri, 15 Aug 2014 09:36:58 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Fri, 15 Aug 2014 15:35:57 +0200 Message-Id: <1408109759-1100-26-git-send-email-benoit.canet@nodalink.com> In-Reply-To: <1408109759-1100-1-git-send-email-benoit.canet@nodalink.com> References: <1408109759-1100-1-git-send-email-benoit.canet@nodalink.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 25/26] qapi: Add a script to filter qmp-commands-old.h to generate a subset of it. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Since qmp-command-olds.h is generated from qmp-commands.hx we will someti= me want to include only a subset of it. For example when linking qapi block comma= nds with qemu-nbd. Signed-off-by: Beno=C3=AEt Canet --- Makefile | 7 +++ scripts/filter_qmp_commands_old.py | 93 ++++++++++++++++++++++++++++++++= ++++++ 2 files changed, 100 insertions(+) create mode 100755 scripts/filter_qmp_commands_old.py diff --git a/Makefile b/Makefile index f56dcaa..209a859 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ endif GENERATED_BLOCK_HEADERS =3D block/qapi-generated/qmp-commands.h GENERATED_BLOCK_HEADERS +=3D block/qapi-generated/qapi-types.h GENERATED_BLOCK_HEADERS +=3D block/qapi-generated/qapi-visit.h +GENERATED_BLOCK_HEADERS +=3D block/qapi-generated/qmp-commands-old.h GENERATED_BLOCK_SOURCES =3D block/qapi-generated/qmp-marshal.c GENERATED_BLOCK_SOURCES +=3D block/qapi-generated/qapi-types.c GENERATED_BLOCK_SOURCES +=3D block/qapi-generated/qapi-visit.c @@ -296,6 +297,12 @@ $(SRC_PATH)/qapi/block-core.json $(SRC_PATH)/scripts= /qapi-commands.py $(qapi-py) $(gen-out-type) -o block/qapi-generated -m -i $<, \ " GEN $@") =20 +block/qapi-generated/qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx \ +block/qapi-generated/qmp-commands.h + $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< |\ +./scripts/filter_qmp_commands_old.py \ +$(SRC_PATH)/block/qapi-generated/qmp-commands.h > $@," GEN $@") + QGALIB_GEN=3D$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-= visit.h qga-qmp-commands.h) $(qga-obj-y) qemu-ga.o: $(QGALIB_GEN) =20 diff --git a/scripts/filter_qmp_commands_old.py b/scripts/filter_qmp_comm= ands_old.py new file mode 100755 index 0000000..d7e02d9 --- /dev/null +++ b/scripts/filter_qmp_commands_old.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# +# qmp-commands-old.h filtering +# +# Copyright (C) 2014 Nodalink, EURL. +# +# Authors: +# Benoit Canet +# +# This work is licensed under the terms of the GNU GPL, version 2. +# See the COPYING file in the top-level directory. + +""" The purpose of this script is to get a subset of qmp-command-old.h + suitable for use in one of the block commands. (qemu-nbd, qemu-io). + The result is printed on stdout. +""" + +import sys +import os + +def usage(): + """ Print usage """ + print "Usage:" + print "\tcat /path/to/qmp-commands-old.h|%s /path/to/qmp-command.h" = %\ + sys.argv[0] + sys.exit(1) + +def get_lines(filename): + """ Get the lines composing a file into a list """ + if not os.path.exists(filename): + print "%s does not exists" % filename + sys.exit(1) + if not os.access(filename, os.R_OK): + print "%s is not readable" % filename + sys.exit(1) + with open(filename) as file_object: + return file_object.readlines() + +def build_filter_list(filename): + """ Build a list of qmp function that will be used as a filter """ + result =3D [] + lines =3D get_lines(filename) + for line in lines: + line =3D line.strip() + if not "(" in line: + continue + if not "input" in line: + continue + begining, _ =3D line.split('(') + component =3D begining.split(' ') + function =3D component[len(component) -1] + result.append(function) + return result + +def filter_and_print(to_filter, filter_list): + """ Filter the lines from to_filter with filter_list and print on st= dout """ + result =3D [] + block =3D [] + in_block =3D False + line =3D to_filter.readline() + while line: + if (".mhandler.cmd_new" in line or + ".mhandler.cmd_async" in line) and in_block: + _, end =3D line.strip().split("=3D") + function_name =3D end[:-1].strip() + if function_name not in filter_list and \ + function_name !=3D "do_qmp_capabilities" and \ + function_name !=3D "qmp_marshal_input_query_commands": + in_block =3D False + if in_block or "}" in line: + block.append(line) + if "{" in line: + block =3D [line] + in_block =3D True + if "}" in line and in_block: + block.append("\n") + in_block =3D False + result +=3D block + line =3D to_filter.readline() + print "".join(result) + +def main(): + """ Main function of the module """ + if len(sys.argv) !=3D 2: + usage() + to_filter =3D sys.stdin + filename =3D sys.argv[1] + + filter_list =3D build_filter_list(filename) + filter_and_print(to_filter, filter_list) + +if __name__ =3D=3D "__main__": + main() --=20 2.1.0.rc1