From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0317.ocn.ad.jp (mogw0317.ocn.ad.jp [114.147.58.87]) by dpdk.org (Postfix) with ESMTP id 712DC4C77 for ; Tue, 6 Mar 2018 11:39:53 +0100 (CET) Received: from mf-smf-ucb036c3 (mf-smf-ucb036c3.ocn.ad.jp [153.153.66.235]) by mogw0317.ocn.ad.jp (Postfix) with ESMTP id E716135C2BE; Tue, 6 Mar 2018 19:39:51 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb025 ([153.149.142.99]) by mf-smf-ucb036c3 with ESMTP id tA0UeeWdvwXtUtA0deb9nZ; Tue, 06 Mar 2018 19:39:51 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.133]) by ntt.pod01.mv-mta-ucb025 with id Jafr1x00A2tKTyH01afrk0; Tue, 06 Mar 2018 10:39:51 +0000 Received: from localhost.localdomain (sp1-66-103-93.msc.spmode.ne.jp [1.66.103.93]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Tue, 6 Mar 2018 19:39:51 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: ferruh.yigit@intel.com, spp@dpdk.org Cc: Yasufumi Ogawa Date: Tue, 6 Mar 2018 19:39:25 +0900 Message-Id: <20180306103929.64809-9-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20180306103929.64809-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20180306103929.64809-1-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH 08/12] spp: add completion for playback command 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, 06 Mar 2018 10:39:54 -0000 From: Yasufumi Ogawa Signed-off-by: Yasufumi Ogawa --- src/spp.py | 107 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/src/spp.py b/src/spp.py index db43ad5..552e921 100755 --- a/src/spp.py +++ b/src/spp.py @@ -368,6 +368,58 @@ class Shell(cmd.Cmd, object): SEC_SUBCMDS = ['vhost', 'ring', 'pcap', 'nullpmd'] BYE_CMDS = ['sec', 'all'] + def decorate_dir(self, curdir, filelist): + res = [] + for f in filelist: + if os.path.isdir('%s/%s' % (curdir, f)): + res.append('%s/' % f) + else: + res.append(f) + return res + + def compl_common(self, text, line, ftype=None): + if text == '': + tokens = line.split(' ') + target_dir = tokens[-1] + if target_dir == '': + res = self.decorate_dir( + '.', os.listdir(os.getcwd())) + else: + res = self.decorate_dir( + target_dir, os.listdir(target_dir)) + else: + tokens = line.split(' ') + target = tokens[-1] + + if '/' in target: + seg = target.split('/')[-1] + target_dir = '/'.join(target.split('/')[0:-1]) + else: + seg = text + target_dir = os.getcwd() + + matched = [] + for t in os.listdir(target_dir): + if t.find(seg) == 0: + matched.append(t) + res = self.decorate_dir(target_dir, matched) + + if ftype is not None: + completions = [] + if ftype == 'directory': + for fn in res: + if fn[-1] == '/': + completions.append(fn) + elif ftype == 'file': + for fn in res: + if fn[-1] != '/': + completions.append(fn) + else: + completions = res + else: + completions = res + return completions + def is_comment_line(self, line): input_line = line.strip() if len(input_line) > 0: @@ -648,6 +700,9 @@ class Shell(cmd.Cmd, object): self.recorded_file = open(fname, 'w') self.response(self.CMD_OK, "record") + def complete_playback(self, text, line, begidx, endidx): + return self.compl_common(text, line) + def do_playback(self, fname): """Playback commands from a file: PLAYBACK filename.cmd""" @@ -689,58 +744,6 @@ class Shell(cmd.Cmd, object): def do_pwd(self, args): print(os.getcwd()) - def decorate_dir(self, curdir, filelist): - res = [] - for f in filelist: - if os.path.isdir('%s/%s' % (curdir, f)): - res.append('%s/' % f) - else: - res.append(f) - return res - - def compl_common(self, text, line, ftype=None): - if text == '': - tokens = line.split(' ') - target_dir = tokens[-1] - if target_dir == '': - res = self.decorate_dir( - '.', os.listdir(os.getcwd())) - else: - res = self.decorate_dir( - target_dir, os.listdir(target_dir)) - else: - tokens = line.split(' ') - target = tokens[-1] - - if '/' in target: - seg = target.split('/')[-1] - target_dir = '/'.join(target.split('/')[0:-1]) - else: - seg = text - target_dir = os.getcwd() - - matched = [] - for t in os.listdir(target_dir): - if t.find(seg) == 0: - matched.append(t) - res = self.decorate_dir(target_dir, matched) - - if ftype is not None: - if ftype == 'directory': - completions = [] - for fn in res: - if fn[-1] == '/': - completions.append(fn) - elif ftype == 'file': - for fn in res: - if fn[-1] != '/': - completions.append(fn) - else: - completions = res - else: - completions = res - return completions - def complete_ls(self, text, line, begidx, endidx): return self.compl_common(text, line) -- 2.13.1