From: "Benoît Canet" <benoit.canet@nodalink.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com,
"Benoît Canet" <benoit.canet@nodalink.com>,
stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v2 25/26] qapi: Add a script to filter qmp-commands-old.h to generate a subset of it.
Date: Fri, 15 Aug 2014 15:35:57 +0200 [thread overview]
Message-ID: <1408109759-1100-26-git-send-email-benoit.canet@nodalink.com> (raw)
In-Reply-To: <1408109759-1100-1-git-send-email-benoit.canet@nodalink.com>
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: Benoît Canet <benoit.canet@nodalink.com>
---
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 <benoit.canet@irqsave.net>
+#
+# 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()
--
2.1.0.rc1
next prev parent reply other threads:[~2014-08-15 13:37 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-15 13:35 [Qemu-devel] [PATCH v2 00/26] Extract qmp.c and monitor.c core and wire QMP into qemu-nbd Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 01/26] qmp: Extract system emulation related code from qmp.c into qmp-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 02/26] monitor: Make some function public Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 03/26] monitor: Convert Monitor reset_seen field too boolean Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 04/26] monitor: Convert mon_cmd_t to MonitorCommand Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 05/26] monitor: Extract monitor-system.h header Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 06/26] monitor: Make monitor_fprintf public before extracting it Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 07/26] monitor: Extract monitor_fprintf to monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 08/26] monitor: Extract qmp_human_monitor_command into monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 09/26] monitor: Make some function to extract public Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 10/26] monitor: Extract a couple of function to monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 11/26] monitor: Make do_info_help public Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 12/26] monitor: Extract do_info_help in monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 13/26] monitor: Make some monitor functions public before moving them " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 14/26] monitor: Make do_loadvm public before moving it to monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 15/26] monitor: Move do_loadvm from monitor.c " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 16/26] monitor: Make commands public before moving them " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 17/26] monitor: Move MonitorCommand arrays and some function from monitor.c " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 18/26] monitor: Move more functions " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 19/26] monitor: Move two net " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 20/26] monitor: Move qmp_rtc_reset_reinjection " Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 21/26] monitor-system: Switch back functions to static Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 22/26] monitor: Extract hardware dependent completion function from monitor.c to monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 23/26] monitor: Cleanup monitor.c includes after extracting monitor-system.c Benoît Canet
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 24/26] qemu-nbd: build QAPI block core into qemu-nbd Benoît Canet
2014-08-15 13:35 ` Benoît Canet [this message]
2014-08-15 13:35 ` [Qemu-devel] [PATCH v2 26/26] qemu-nbd: Add --qmp option to qemu-nbd Benoît Canet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1408109759-1100-26-git-send-email-benoit.canet@nodalink.com \
--to=benoit.canet@nodalink.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).