[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 25/26] qapi: Add a script to filter qmp-commands-
From: |
Benoît Canet |
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 |
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 <address@hidden>
---
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 <address@hidden>
+#
+# 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
- [Qemu-devel] [PATCH v2 20/26] monitor: Move qmp_rtc_reset_reinjection from monitor.c to monitor-system.c, (continued)
- [Qemu-devel] [PATCH v2 20/26] monitor: Move qmp_rtc_reset_reinjection from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 10/26] monitor: Extract a couple of function to monitor-system.c, Benoît Canet, 2014/08/15
- [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
- [Qemu-devel] [PATCH v2 09/26] monitor: Make some function to extract public, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 19/26] monitor: Move two net functions from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 15/26] monitor: Move do_loadvm from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 26/26] qemu-nbd: Add --qmp option to qemu-nbd., Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 18/26] monitor: Move more functions from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 23/26] monitor: Cleanup monitor.c includes after extracting monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 14/26] monitor: Make do_loadvm public before moving it to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 25/26] qapi: Add a script to filter qmp-commands-old.h to generate a subset of it.,
Benoît Canet <=
- [Qemu-devel] [PATCH v2 16/26] monitor: Make commands public before moving them to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 17/26] monitor: Move MonitorCommand arrays and some function from monitor.c to monitor-system.c, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 21/26] monitor-system: Switch back functions to static, Benoît Canet, 2014/08/15
- [Qemu-devel] [PATCH v2 13/26] monitor: Make some monitor functions public before moving them in monitor-system.c, Benoît Canet, 2014/08/15