Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org
Cc: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Subject: [spp] [PATCH 2/2] spp_vf: update to improve usability
Date: Fri,  9 Feb 2018 00:18:11 +0900	[thread overview]
Message-ID: <1518103091-4624-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1518103091-4624-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

This update is same as previous patch for spp.py.

* 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 <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp_vf.py | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/spp_vf.py b/src/spp_vf.py
index 0d706ee..4325c28 100755
--- a/src/spp_vf.py
+++ b/src/spp_vf.py
@@ -301,7 +301,7 @@ def check_sec_cmds(cmds):
     return valid
 
 
-class Shell(cmd.Cmd):
+class Shell(cmd.Cmd, object):
     """SPP command prompt"""
 
     intro = 'Welcome to the spp.   Type help or ? to list commands.\n'
@@ -311,6 +311,36 @@ class Shell(cmd.Cmd):
     COMMANDS = ['status', 'add', 'patch', 'ring', 'vhost',
                 'reset', 'exit', 'forward', 'stop', 'clear']
 
+    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 complete_pri(self, text, line, begidx, endidx):
         """Completion for primary process commands"""
 
@@ -375,15 +405,14 @@ class Shell(cmd.Cmd):
             with open(arg) 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)
         except IOError:
             print("Error: File does not exist.")
 
     def precmd(self, line):
-        line = line.lower()
         if self.recorded_file and 'playback' not in line:
             print(line, file=self.recorded_file)
         return line
-- 
2.7.4

  reply	other threads:[~2018-02-08 15:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-08 15:18 [spp] [PATCH 1/2] spp: " ogawa.yasufumi
2018-02-08 15:18 ` ogawa.yasufumi [this message]
2018-02-22 11:50   ` [spp] [PATCH 2/2] spp_vf: " Ferruh Yigit
2018-02-28 10:27     ` Yasufumi Ogawa
2018-02-22 11:35 ` [spp] [PATCH 1/2] spp: " Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1518103091-4624-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).