From patchwork Fri Aug 1 05:27:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Canet?= X-Patchwork-Id: 375561 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 82CC6140093 for ; Fri, 1 Aug 2014 15:42:10 +1000 (EST) Received: from localhost ([::1]:60002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XD5bU-00055i-Mq for incoming@patchwork.ozlabs.org; Fri, 01 Aug 2014 01:42:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XD5OD-0007sE-13 for qemu-devel@nongnu.org; Fri, 01 Aug 2014 01:28:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XD5O2-0003eo-NG for qemu-devel@nongnu.org; Fri, 01 Aug 2014 01:28:24 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:59401 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XD5O2-0003bz-9v for qemu-devel@nongnu.org; Fri, 01 Aug 2014 01:28:14 -0400 Received: from localhost.localdomain (laure.irqsave.net [192.168.77.2]) by paradis.irqsave.net (Postfix) with ESMTP id 83DE3C3154; Fri, 1 Aug 2014 07:28:12 +0200 (CEST) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Fri, 1 Aug 2014 07:27:21 +0200 Message-Id: <1406870842-17988-24-git-send-email-benoit.canet@irqsave.net> X-Mailer: git-send-email 2.0.1 In-Reply-To: <1406870842-17988-1-git-send-email-benoit.canet@irqsave.net> References: <1406870842-17988-1-git-send-email-benoit.canet@irqsave.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 80.12.84.125 Cc: kwolf@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , Benoit Canet , mreitz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v1 23/24] qapi: Add a script to filter qmp-commands-old.h to generate a subset of it. 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 Since qmp-command-olds.h is generated from qmp-commands.hx we will sometime want to include only a subset of it. For example when linking qapi block commands with qemu-nbd. Signed-off-by: Benoit 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 = block/qapi-generated/qmp-commands.h GENERATED_BLOCK_HEADERS += block/qapi-generated/qapi-types.h GENERATED_BLOCK_HEADERS += block/qapi-generated/qapi-visit.h +GENERATED_BLOCK_HEADERS += block/qapi-generated/qmp-commands-old.h GENERATED_BLOCK_SOURCES = block/qapi-generated/qmp-marshal.c GENERATED_BLOCK_SOURCES += block/qapi-generated/qapi-types.c GENERATED_BLOCK_SOURCES += 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 $@") +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=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h) $(qga-obj-y) qemu-ga.o: $(QGALIB_GEN) diff --git a/scripts/filter_qmp_commands_old.py b/scripts/filter_qmp_commands_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 = [] + lines = get_lines(filename) + for line in lines: + line = line.strip() + if not "(" in line: + continue + if not "input" in line: + continue + begining, _ = line.split('(') + component = begining.split(' ') + function = 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 stdout """ + result = [] + block = [] + in_block = False + line = to_filter.readline() + while line: + if (".mhandler.cmd_new" in line or + ".mhandler.cmd_async" in line) and in_block: + _, end = line.strip().split("=") + function_name = end[:-1].strip() + if function_name not in filter_list and \ + function_name != "do_qmp_capabilities" and \ + function_name != "qmp_marshal_input_query_commands": + in_block = False + if in_block or "}" in line: + block.append(line) + if "{" in line: + block = [line] + in_block = True + if "}" in line and in_block: + block.append("\n") + in_block = False + result += block + line = to_filter.readline() + print "".join(result) + +def main(): + """ Main function of the module """ + if len(sys.argv) != 2: + usage() + to_filter = sys.stdin + filename = sys.argv[1] + + filter_list = build_filter_list(filename) + filter_and_print(to_filter, filter_list) + +if __name__ == "__main__": + main()