From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 3/5] controller: fix bug of history command
Date: Mon, 4 Feb 2019 12:11:17 +0900 [thread overview]
Message-ID: <1549249879-31580-4-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1549249879-31580-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
In SPP CLI, command is not added to history without running `history`
because setting a hook for flushing from `readline` is inappropriate.
It should be set to when after command is done. This update is to fix
the issue by using `postcmd()` of Cmd class.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/shell.py | 39 +++++++++++++--------------------------
1 file changed, 13 insertions(+), 26 deletions(-)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 40bafc2..c2a31c6 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -25,9 +25,11 @@ class Shell(cmd.Cmd, object):
recorded_file = None
hist_file = os.path.expanduser('~/.spp_history')
+
+ # Commands not included in history
HIST_EXCEPT = ['bye', 'exit', 'history', 'redo']
- intro = 'Welcome to the spp. Type help or ? to list commands.\n'
+ intro = 'Welcome to the SPP CLI. Type `help` or `?` to list commands.\n'
prompt = 'spp > '
PLUGIN_DIR = 'plugins'
@@ -76,10 +78,19 @@ class Shell(cmd.Cmd, object):
self.secondaries['mirror'][sec_id] = mirror.SppMirror(
self.spp_ctl_cli, sec_id)
+ # Called everytime after running command. `stop` is returned from `do_*`
+ # method and SPP CLI is terminated if it is True. It means that only
+ # `do_bye` and `do_exit` return True.
+ def postcmd(self, stop, line):
+ # TODO(yasufum) do not add to history if command is failed.
+ if line.strip().split(' ')[0] not in self.HIST_EXCEPT:
+ readline.write_history_file(self.hist_file)
+ return stop
+
def default(self, line):
"""Define defualt behaviour.
- If user input is commend styled, controller simply echo
+ If user input is comment styled, controller simply echo
as a comment.
"""
@@ -112,24 +123,6 @@ class Shell(cmd.Cmd, object):
ids.append(ent['client-id'])
return ids
- def clean_hist_file(self):
- """Remove useless entries in history file."""
-
- entries = []
-
- try:
- for line in open(self.hist_file):
- line_s = line.strip()
- if not (line_s.split(' ')[0] in self.HIST_EXCEPT):
- entries.append(line_s)
- f = open(self.hist_file, "w+")
- contents = '\n'.join(entries)
- contents += '\n'
- f.write(contents)
- f.close()
- except IOError:
- print('Error: Cannot open history file "%s"' % self.hist_file)
-
def print_status(self):
"""Display information about connected clients."""
@@ -761,12 +754,6 @@ class Shell(cmd.Cmd, object):
'bye', 'exit', 'history', 'redo'
"""
- # flush all of history to the hist_file.
- readline.write_history_file(self.hist_file)
-
- # remove commands defined in `self.HIST_EXCEPT`
- self.clean_hist_file()
-
try:
f = open(self.hist_file)
--
2.7.4
next prev parent reply other threads:[~2019-02-04 3:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-04 3:11 [spp] [PATCH 0/5] Fix bugs of SPP CLI ogawa.yasufumi
2019-02-04 3:11 ` [spp] [PATCH 1/5] controller: fix bug to add vf comps on same core ogawa.yasufumi
2019-02-04 3:11 ` [spp] [PATCH 2/5] controller: add checking syntax for vf port cmd ogawa.yasufumi
2019-02-04 3:11 ` ogawa.yasufumi [this message]
2019-02-04 3:11 ` [spp] [PATCH 4/5] controller: fix bug of completion of pri ogawa.yasufumi
2019-02-04 3:11 ` [spp] [PATCH 5/5] controller: refactor configuration of logfile ogawa.yasufumi
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=1549249879-31580-4-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).