From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw0937.ocn.ad.jp (mogw0937.ocn.ad.jp [153.149.227.43]) by dpdk.org (Postfix) with ESMTP id C8ED74C74 for ; Tue, 6 Mar 2018 11:39:46 +0100 (CET) Received: from mf-smf-ucb033c2 (mf-smf-ucb033c2.ocn.ad.jp [153.153.66.225]) by mogw0937.ocn.ad.jp (Postfix) with ESMTP id 348D41200473; Tue, 6 Mar 2018 19:39:45 +0900 (JST) Received: from ntt.pod01.mv-mta-ucb025 ([153.149.142.99]) by mf-smf-ucb033c2 with ESMTP id tA0We5tHMGatctA0XeAU01; Tue, 06 Mar 2018 19:39:45 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.133]) by ntt.pod01.mv-mta-ucb025 with id Jafk1x00F2tKTyH01afkih; Tue, 06 Mar 2018 10:39:45 +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:44 +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:21 +0900 Message-Id: <20180306103929.64809-5-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 04/12] spp: add common completion mehtod in Shell class 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:47 -0000 From: Yasufumi Ogawa Completion is required to implementation in methods inspecting parents or children directories. Therefor, it is better to be an common method and call from others. This update for adding common completion and change 'complete_cd' and 'complete_ls' methods to use this common method. Signed-off-by: Yasufumi Ogawa --- src/spp.py | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/spp.py b/src/spp.py index 06f5032..e230b93 100755 --- a/src/spp.py +++ b/src/spp.py @@ -20,6 +20,7 @@ import traceback # Turn true if activate logger to debug remote command. logger = None +logger = True # Maximum num of sock queues for secondaries MAX_SECONDARY = 16 @@ -685,32 +686,25 @@ class Shell(cmd.Cmd, object): def do_pwd(self, args): print(os.getcwd()) - def do_cd(self, args): - if os.path.isdir(args): - os.chdir(args) - print(os.getcwd()) - else: - print("No such a directory.") - - def ls_decorate_dir(self, filelist): + def decorate_dir(self, curdir, filelist): res = [] for f in filelist: - if os.path.isdir(f): + if os.path.isdir('%s/%s' % (curdir, f)): res.append('%s/' % f) else: res.append(f) return res - def complete_ls(self, text, line, begidx, endidx): + def compl_common(self, text, line, ftype=None): if text == '': tokens = line.split(' ') - target = tokens[-1] - if target == '': - completions = self.ls_decorate_dir( - os.listdir(os.getcwd())) + target_dir = tokens[-1] + if target_dir == '': + res = self.decorate_dir( + '.', os.listdir(os.getcwd())) else: - completions = self.ls_decorate_dir( - os.listdir(target)) + res = self.decorate_dir( + target_dir, os.listdir(target_dir)) else: tokens = line.split(' ') target = tokens[-1] @@ -726,9 +720,21 @@ class Shell(cmd.Cmd, object): for t in os.listdir(target_dir): if seg in t: matched.append(t) - completions = self.ls_decorate_dir(matched) + 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) + else: + completions = res return completions + def complete_ls(self, text, line, begidx, endidx): + return self.compl_common(text, line) + def do_ls(self, args): if args == '' or os.path.isdir(args): c = 'ls -F %s' % args @@ -736,6 +742,16 @@ class Shell(cmd.Cmd, object): else: print("No such a directory.") + def complete_cd(self, text, line, begidx, endidx): + return self.compl_common(text, line, 'directory') + + def do_cd(self, args): + if os.path.isdir(args): + os.chdir(args) + print(os.getcwd()) + else: + print("No such a directory.") + def do_bye(self, arg): """Stop recording, close SPP, and exit: BYE""" -- 2.13.1