QMP patches patches for 2020-10-27
-----BEGIN PGP SIGNATURE----- iQJGBAABCAAwFiEENUvIs9frKmtoZ05fOHC0AOuRhlMFAl+X8qwSHGFybWJydUBy ZWRoYXQuY29tAAoJEDhwtADrkYZT8k0P/0AXcoP/clFP0x+TBlcPpk2YPFSS6BnA yIngvKMIKoIxekHtW3ukNANKIynWy2d3u7aD/c8aCLJtioWIZqzmBCW5zC/oYFyO DvOCnXzAK1T/9wy4sswaOjSVeqfI5dsMJKNvYVouXGs0+kYy74k7vtWx5OdjrV4D w4KVyGc5tos9RAafcYl7jYKFDfkYy2+5rZWorIuEG1P6GAjdXMl4r6ako+pbpzW2 g1gbG/Kau9L4MfZR2wvtzblm5Ve+Mf/XivxKdUiHG/MdI9NWrRA033xCQWmrEoQw teeBzVlHHvw9xF5vaqFlYySs+WK9Ou6Q4h0Nc4WNYw6eWPMNog8T/vi2y9Ra+at/ 3gAR0GRrfpd/RXqhFh9xwbEe9n0KzodAA+eGAnT/f2+9CoQHLm436cgzk+Vtasn1 6yFmBwxFnBQeaApAb3oARmXAQrI2hdQBNmxLB1BZuUDKNHrpyZp3Xeh/uTW6PthH 3COdYpzNBeBYaLfcF46wvIIfbQJTrI9WrSuJBN/1oLsm0oxtDnBmgIv0Vij4QLl6 uymPd+RXK3GCj51+6DnccUW6+5YManwdSHMcepOtlXsnXdVVt1t2VkhfyiECOWpA Gd2wBRLCiq810Laf2ywx8OKt7/6ujAE8ksUpAE8fY1MsUBQlzNA/Z/HKsTpXa6ZW nkwPtrz9YHu3 =yTrz -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/armbru/tags/pull-qmp-2020-10-27' into staging QMP patches patches for 2020-10-27 # gpg: Signature made Tue 27 Oct 2020 10:13:00 GMT # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qmp-2020-10-27: scripts/qmp: delete 'qmp' script qmp-shell: Sort by key when pretty-printing Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
c044400914
131
scripts/qmp/qmp
131
scripts/qmp/qmp
@ -1,128 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# QMP command line tool
|
||||
#
|
||||
# Copyright IBM, Corp. 2011
|
||||
#
|
||||
# Authors:
|
||||
# Anthony Liguori <aliguori@us.ibm.com>
|
||||
#
|
||||
# This work is licensed under the terms of the GNU GPLv2 or later.
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
import sys, os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
|
||||
from qemu.qmp import QEMUMonitorProtocol
|
||||
print('''This unmaintained and undocumented script was removed in preference
|
||||
for qmp-shell. The assumption is that most users are using either
|
||||
qmp-shell, socat, or pasting/piping JSON into stdio. The duplication of
|
||||
facilities here is unwanted, and the divergence of syntax harmful.''',
|
||||
file=sys.stderr)
|
||||
|
||||
def print_response(rsp, prefix=[]):
|
||||
if type(rsp) == list:
|
||||
i = 0
|
||||
for item in rsp:
|
||||
if prefix == []:
|
||||
prefix = ['item']
|
||||
print_response(item, prefix[:-1] + ['%s[%d]' % (prefix[-1], i)])
|
||||
i += 1
|
||||
elif type(rsp) == dict:
|
||||
for key in rsp.keys():
|
||||
print_response(rsp[key], prefix + [key])
|
||||
else:
|
||||
if len(prefix):
|
||||
print('%s: %s' % ('.'.join(prefix), rsp))
|
||||
else:
|
||||
print('%s' % (rsp))
|
||||
|
||||
def main(args):
|
||||
path = None
|
||||
|
||||
# Use QMP_PATH if it's set
|
||||
if 'QMP_PATH' in os.environ:
|
||||
path = os.environ['QMP_PATH']
|
||||
|
||||
while len(args):
|
||||
arg = args[0]
|
||||
|
||||
if arg.startswith('--'):
|
||||
arg = arg[2:]
|
||||
if arg.find('=') == -1:
|
||||
value = True
|
||||
else:
|
||||
arg, value = arg.split('=', 1)
|
||||
|
||||
if arg in ['path']:
|
||||
if type(value) == str:
|
||||
path = value
|
||||
elif arg in ['help']:
|
||||
os.execlp('man', 'man', 'qmp')
|
||||
else:
|
||||
print('Unknown argument "%s"' % arg)
|
||||
|
||||
args = args[1:]
|
||||
else:
|
||||
break
|
||||
|
||||
if not path:
|
||||
print("QMP path isn't set, use --path=qmp-monitor-address or set QMP_PATH")
|
||||
return 1
|
||||
|
||||
if len(args):
|
||||
command, args = args[0], args[1:]
|
||||
else:
|
||||
print('No command found')
|
||||
print('Usage: "qmp [--path=qmp-monitor-address] qmp-cmd arguments"')
|
||||
return 1
|
||||
|
||||
if command in ['help']:
|
||||
os.execlp('man', 'man', 'qmp')
|
||||
|
||||
srv = QEMUMonitorProtocol(path)
|
||||
srv.connect()
|
||||
|
||||
def do_command(srv, cmd, **kwds):
|
||||
rsp = srv.cmd(cmd, kwds)
|
||||
if 'error' in rsp:
|
||||
raise Exception(rsp['error']['desc'])
|
||||
return rsp['return']
|
||||
|
||||
commands = map(lambda x: x['name'], do_command(srv, 'query-commands'))
|
||||
|
||||
srv.close()
|
||||
|
||||
if command not in commands:
|
||||
fullcmd = 'qmp-%s' % command
|
||||
try:
|
||||
os.environ['QMP_PATH'] = path
|
||||
os.execvp(fullcmd, [fullcmd] + args)
|
||||
except OSError as exc:
|
||||
if exc.errno == 2:
|
||||
print('Command "%s" not found.' % (fullcmd))
|
||||
return 1
|
||||
raise
|
||||
return 0
|
||||
|
||||
srv = QEMUMonitorProtocol(path)
|
||||
srv.connect()
|
||||
|
||||
arguments = {}
|
||||
for arg in args:
|
||||
if not arg.startswith('--'):
|
||||
print('Unknown argument "%s"' % arg)
|
||||
return 1
|
||||
|
||||
arg = arg[2:]
|
||||
if arg.find('=') == -1:
|
||||
value = True
|
||||
else:
|
||||
arg, value = arg.split('=', 1)
|
||||
|
||||
if arg in ['help']:
|
||||
os.execlp('man', 'man', 'qmp-%s' % command)
|
||||
return 1
|
||||
|
||||
arguments[arg] = value
|
||||
|
||||
rsp = do_command(srv, command, **arguments)
|
||||
print_response(rsp)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
sys.exit(1)
|
||||
|
@ -260,7 +260,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):
|
||||
indent = None
|
||||
if self._pretty:
|
||||
indent = 4
|
||||
jsobj = json.dumps(qmp, indent=indent)
|
||||
jsobj = json.dumps(qmp, indent=indent, sort_keys=self._pretty)
|
||||
print(str(jsobj))
|
||||
|
||||
def _execute_cmd(self, cmdline):
|
||||
|
Loading…
Reference in New Issue
Block a user