From patchwork Wed Apr 22 16:21:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 463700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7BDDE14012C for ; Thu, 23 Apr 2015 02:22:30 +1000 (AEST) Received: from localhost ([::1]:36045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkxPw-0003nb-Fk for incoming@patchwork.ozlabs.org; Wed, 22 Apr 2015 12:22:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkxPT-0002tz-Js for qemu-devel@nongnu.org; Wed, 22 Apr 2015 12:22:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YkxPM-0000YK-V3 for qemu-devel@nongnu.org; Wed, 22 Apr 2015 12:21:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48135) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YkxPM-0000YA-QB for qemu-devel@nongnu.org; Wed, 22 Apr 2015 12:21:52 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 80C8D8EFE6 for ; Wed, 22 Apr 2015 16:21:52 +0000 (UTC) Received: from scv.usersys.redhat.com (vpn-48-170.rdu2.redhat.com [10.10.48.170]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3MGLoWm009433; Wed, 22 Apr 2015 12:21:51 -0400 From: John Snow To: qemu-devel@nongnu.org Date: Wed, 22 Apr 2015 12:21:46 -0400 Message-Id: <1429719709-880-2-git-send-email-jsnow@redhat.com> In-Reply-To: <1429719709-880-1-git-send-email-jsnow@redhat.com> References: <1429719709-880-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: John Snow , lcapitulino@redhat.com, kchamart@redhat.com Subject: [Qemu-devel] [PATCH v2 1/4] scripts: qmp-shell: refactor helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Eric Blake --- 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):