From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0131.ocn.ad.jp (mogw0131.ocn.ad.jp [118.23.109.105]) by dpdk.org (Postfix) with ESMTP id 7F7621B323 for ; Tue, 3 Oct 2017 12:42:37 +0200 (CEST) Received: from mf-smf-ucb016.ocn.ad.jp (mf-smf-ucb016.ocn.ad.jp [153.149.231.3]) by mogw0131.ocn.ad.jp (Postfix) with ESMTP id C976D60244; Tue, 3 Oct 2017 19:42:35 +0900 (JST) Received: from mf-smf-ucb016.ocn.ad.jp (mf-smf-ucb016 [153.149.231.3]) by mf-smf-ucb016.ocn.ad.jp (Postfix) with ESMTP id B21A6100621; Tue, 3 Oct 2017 19:42:35 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb030 (mv-mta-ucb030.ocn.ad.jp [153.149.230.164]) by mf-smf-ucb016.ocn.ad.jp (Switch-3.3.4/Switch-3.3.4) with ESMTP id v93AgI1q038398; Tue, 3 Oct 2017 19:42:35 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.166]) by ntt.pod01.mv-mta-ucb030 with id Gyia1w0063c2f7501yiaqT; Tue, 03 Oct 2017 10:42:35 +0000 Received: from localhost.localdomain (sp1-75-231-175.msb.spmode.ne.jp [1.75.231.175]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Tue, 3 Oct 2017 19:42:34 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org Cc: gerald.rogers@intel.com, sy.jong.choi@intel.com, Yasufumi Ogawa Date: Tue, 3 Oct 2017 19:42:13 +0900 Message-Id: <20171003104214.81003-2-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20171003104214.81003-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20171003104214.81003-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH 2/3] spp: add record file check 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: Tue, 03 Oct 2017 10:42:38 -0000 From: Yasufumi Ogawa 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 --- 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