From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0833.ocn.ad.jp (mogw0833.ocn.ad.jp [153.149.234.34]) by dpdk.org (Postfix) with ESMTP id 5470E1B7EF for ; Thu, 8 Feb 2018 16:18:16 +0100 (CET) Received: from mf-smf-ucb034c1 (mf-smf-ucb034c1.ocn.ad.jp [153.153.66.227]) by mogw0833.ocn.ad.jp (Postfix) with ESMTP id B995C58022D; Fri, 9 Feb 2018 00:18:14 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb021 ([153.149.142.84]) by mf-smf-ucb034c1 with ESMTP id jnxietmNaIyo5jnxmeFfFE; Fri, 09 Feb 2018 00:18:14 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.134]) by ntt.pod01.mv-mta-ucb021 with id 8FJE1x0062ud8JZ01FJE4Y; Thu, 08 Feb 2018 15:18:14 +0000 Received: from localhost.localdomain (p6533091-ipngn12202marunouchi.tokyo.ocn.ne.jp [118.22.120.91]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Fri, 9 Feb 2018 00:18:14 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org Cc: Yasufumi Ogawa Date: Fri, 9 Feb 2018 00:18:10 +0900 Message-Id: <1518103091-4624-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.7.4 Subject: [spp] [PATCH 1/2] spp: update to improve usability X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Feb 2018 15:18:16 -0000 From: Yasufumi Ogawa SPP controller executes previous command if user just types enter in command line. It decreases usability and might cause a wrong operation. In addition, users cannot use empty lines in config files loaded from `playback` command. It also decreases maintainability. For maintainability, it is another problem for SPP controller does not accept comment line from CLI (only able to use only in config file). User cannot record comment in 'record' command for the reason. This patch includes following updates. * Override emptyline() of Shell class to not repeat previous command. * Override default() to accept comment line. To find the comment, add is_comment_line() which support python and C style comment. * Remove lower() for user's input to avoid unexpected behaviour. Signed-off-by: Yasufumi Ogawa --- src/spp.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/spp.py b/src/spp.py index 3796670..84f1fa7 100755 --- a/src/spp.py +++ b/src/spp.py @@ -346,7 +346,7 @@ def clean_sec_cmd(cmdstr): return res -class Shell(cmd.Cmd): +class Shell(cmd.Cmd, object): """SPP command prompt""" intro = 'Welcome to the spp. Type help or ? to list commands.\n' @@ -365,6 +365,36 @@ class Shell(cmd.Cmd): SEC_SUBCMDS = ['vhost', 'ring', 'pcap', 'nullpmd'] BYE_CMDS = ['sec', 'all'] + def is_comment_line(self, line): + input_line = line.strip() + if len(input_line) > 0: + if (input_line[0] == '#') or (input_line[0:2] == '//'): + return True + else: + return False + + def default(self, line): + """Define defualt behaviour + + If user input is commend styled, controller simply echo as a comment. + Supported styles are + - python ('#') + - C ('//') + """ + + if self.is_comment_line(line): + print("%s" % line.strip()) + else: + super(Shell, self).default(line) + + def emptyline(self): + """Do nothin for empty input + + It override Cmd.emptyline() which runs previous input as default + to do nothing. + """ + pass + def close_all_secondary(self): """Exit all secondary processes""" @@ -626,8 +656,8 @@ class Shell(cmd.Cmd): with open(fname) as recorded_file: lines = [] for line in recorded_file: - if line.strip().startswith("#"): - continue + if not self.is_comment_line(line): + lines.append("# %s" % line) lines.append(line) self.cmdqueue.extend(lines) self.response(self.CMD_OK, "playback") @@ -637,7 +667,6 @@ class Shell(cmd.Cmd): self.response(self.CMD_NG, message) def precmd(self, line): - line = line.lower() if self.recorded_file: if not (('playback' in line) or ('bye' in line)): print(line, file=self.recorded_file) -- 2.7.4