From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ykjzw-0005Wk-OQ for qemu-devel@nongnu.org; Tue, 21 Apr 2015 22:02:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ykjzu-0005KP-20 for qemu-devel@nongnu.org; Tue, 21 Apr 2015 22:02:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55143) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ykjzt-0005KF-PV for qemu-devel@nongnu.org; Tue, 21 Apr 2015 22:02:41 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3M22f8U017468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 21 Apr 2015 22:02:41 -0400 From: John Snow Date: Tue, 21 Apr 2015 22:02:31 -0400 Message-Id: <1429668155-1606-2-git-send-email-jsnow@redhat.com> In-Reply-To: <1429668155-1606-1-git-send-email-jsnow@redhat.com> References: <1429668155-1606-1-git-send-email-jsnow@redhat.com> Subject: [Qemu-devel] [PATCH 1/5] scripts: qmp-shell: refactor helpers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lcapitulino@redhat.com, John Snow , kchamart@redhat.com 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 --- scripts/qmp/qmp-shell | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index e0e848b..a9632ec 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -88,16 +88,8 @@ class QMPShell(qmp.QEMUMonitorProtocol): # clearing everything as it doesn't seem to matter readline.set_completer_delims('') - 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': {} } - for arg in cmdargs[1:]: + def __cli_expr(self, tokens, parent): + for arg in tokens: opt = arg.split('=') try: if(len(opt) > 2): @@ -113,7 +105,6 @@ class QMPShell(qmp.QEMUMonitorProtocol): else: value = opt[1] optpath = opt[0].split('.') - parent = qmpcmd['arguments'] curpath = [] for p in optpath[:-1]: curpath.append(p) @@ -128,6 +119,17 @@ class QMPShell(qmp.QEMUMonitorProtocol): else: raise QMPShellError('Cannot set "%s" multiple times' % opt[0]) 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 def _execute_cmd(self, cmdline): -- 2.1.0