From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org
Cc: gerald.rogers@intel.com, sy.jong.choi@intel.com,
Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Subject: [spp] [PATCH 2/3] spp: add record file check
Date: Tue, 3 Oct 2017 19:42:13 +0900 [thread overview]
Message-ID: <20171003104214.81003-2-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20171003104214.81003-1-ogawa.yasufumi@lab.ntt.co.jp>
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
record and playback command should be given a record file name
but there are no checking if it is given.
This change adds checking for record file in do_record and
do_playback methods.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/spp.py | 42 ++++++++++++++++++++++++------------------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/src/spp.py b/src/spp.py
index 4aa0c62..4bbbb44 100755
--- a/src/spp.py
+++ b/src/spp.py
@@ -477,29 +477,35 @@ class Shell(cmd.Cmd):
print ("first %s" % cmds[1])
self.response(CMD_ERROR, "invalid format")
- def do_record(self, arg):
+ def do_record(self, fname):
"""Save future commands to filename: RECORD filename.cmd"""
- self.recorded_file = open(arg, 'w')
- self.response(CMD_OK, "record")
+ if fname == '':
+ print("Record file is required!")
+ else:
+ self.recorded_file = open(fname, 'w')
+ self.response(CMD_OK, "record")
- def do_playback(self, arg):
+ def do_playback(self, fname):
"""Playback commands from a file: PLAYBACK filename.cmd"""
- self.close()
- try:
- with open(arg) as recorded_file:
- lines = []
- for line in recorded_file:
- if line.strip().startswith("#"):
- continue
- lines.append(line)
- self.cmdqueue.extend(lines)
- self.response(CMD_OK, "playback")
- except IOError:
- message = "Error: File does not exist."
- print(message)
- self.response(CMD_NG, message)
+ if fname == '':
+ print("Record file is required!")
+ else:
+ self.close()
+ try:
+ with open(fname) as recorded_file:
+ lines = []
+ for line in recorded_file:
+ if line.strip().startswith("#"):
+ continue
+ lines.append(line)
+ self.cmdqueue.extend(lines)
+ self.response(CMD_OK, "playback")
+ except IOError:
+ message = "Error: File does not exist."
+ print(message)
+ self.response(CMD_NG, message)
def precmd(self, line):
line = line.lower()
--
2.13.1
next prev parent reply other threads:[~2017-10-03 10:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-03 10:42 [spp] [PATCH 1/3] spp: fix bug of precmd ogawa.yasufumi
2017-10-03 10:42 ` ogawa.yasufumi [this message]
2017-10-03 10:42 ` [spp] [PATCH 3/3] spp: change logger to optional ogawa.yasufumi
2017-11-29 1:35 ` [spp] [PATCH 1/3] spp: fix bug of precmd 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=20171003104214.81003-2-ogawa.yasufumi@lab.ntt.co.jp \
--to=ogawa.yasufumi@lab.ntt.co.jp \
--cc=gerald.rogers@intel.com \
--cc=spp@dpdk.org \
--cc=sy.jong.choi@intel.com \
/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).