Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org
Cc: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Subject: [spp] [PATCH 08/12] spp: add completion for playback command
Date: Tue,  6 Mar 2018 19:39:25 +0900	[thread overview]
Message-ID: <20180306103929.64809-9-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20180306103929.64809-1-ogawa.yasufumi@lab.ntt.co.jp>

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 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

  parent reply	other threads:[~2018-03-06 10:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-06 10:39 [spp] [PATCH 00/12] Improve spp controller ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 01/12] spp: add basic commands ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 02/12] spp: add ls command ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 03/12] spp: add completion for " ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 04/12] spp: add common completion mehtod in Shell class ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 05/12] spp: fix bug of completion ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 06/12] spp: add file type support to compl_common ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 07/12] spp: fix bug for record command ogawa.yasufumi
2018-03-06 10:39 ` ogawa.yasufumi [this message]
2018-03-06 10:39 ` [spp] [PATCH 09/12] spp: add completion " ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 10/12] spp: add mkdir command and its completion ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 11/12] spp: refactor help messages in Shell class ogawa.yasufumi
2018-03-06 10:39 ` [spp] [PATCH 12/12] spp: refactor logger ogawa.yasufumi
2018-03-27 23:36 ` [spp] [PATCH 00/12] Improve spp controller 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=20180306103929.64809-9-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).