scripts: qmp-shell: refactor helpers

Refactor the qmp-shell command line processing function
into two components. This will be used to allow sub-expressions,
which will assist us in adding transactional support to qmp-shell.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Tested-by: Kashyap Chamarthy <kchamart@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
John Snow 2015-04-29 15:14:01 -04:00 committed by Luiz Capitulino
parent 9740618cd2
commit a7430a0bad

View File

@ -88,16 +88,8 @@ class QMPShell(qmp.QEMUMonitorProtocol):
# clearing everything as it doesn't seem to matter # clearing everything as it doesn't seem to matter
readline.set_completer_delims('') readline.set_completer_delims('')
def __build_cmd(self, cmdline): def __cli_expr(self, tokens, parent):
""" for arg in tokens:
Build a QMP input object from a user provided command-line in the
following format:
< command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ]
"""
cmdargs = cmdline.split()
qmpcmd = { 'execute': cmdargs[0], 'arguments': {} }
for arg in cmdargs[1:]:
opt = arg.split('=') opt = arg.split('=')
try: try:
if(len(opt) > 2): if(len(opt) > 2):
@ -113,7 +105,6 @@ class QMPShell(qmp.QEMUMonitorProtocol):
else: else:
value = opt[1] value = opt[1]
optpath = opt[0].split('.') optpath = opt[0].split('.')
parent = qmpcmd['arguments']
curpath = [] curpath = []
for p in optpath[:-1]: for p in optpath[:-1]:
curpath.append(p) curpath.append(p)
@ -128,6 +119,17 @@ class QMPShell(qmp.QEMUMonitorProtocol):
else: else:
raise QMPShellError('Cannot set "%s" multiple times' % opt[0]) raise QMPShellError('Cannot set "%s" multiple times' % opt[0])
parent[optpath[-1]] = value parent[optpath[-1]] = value
def __build_cmd(self, cmdline):
"""
Build a QMP input object from a user provided command-line in the
following format:
< command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ]
"""
cmdargs = cmdline.split()
qmpcmd = { 'execute': cmdargs[0], 'arguments': {} }
self.__cli_expr(cmdargs[1:], qmpcmd['arguments'])
return qmpcmd return qmpcmd
def _execute_cmd(self, cmdline): def _execute_cmd(self, cmdline):