Soft Patch Panel
 help / color / mirror / Atom feed
From: Yasufumi Ogawa <yasufum.o@gmail.com>
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 1/8] cli: remove topo_resize command
Date: Mon, 12 Aug 2019 16:12:35 +0900	[thread overview]
Message-ID: <20190812071242.18934-2-yasufum.o@gmail.com> (raw)
In-Reply-To: <20190812071242.18934-1-yasufum.o@gmail.com>

As `topo_size` is introduced in config and `topo_resize` command is not
required anymore, remove this command.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/cli/commands/topo.py | 59 +++++++++++++++++++++-------------------
 src/cli/shell.py         | 10 ++-----
 2 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/src/cli/commands/topo.py b/src/cli/commands/topo.py
index 21ef1ec..58c59d1 100644
--- a/src/cli/commands/topo.py
+++ b/src/cli/commands/topo.py
@@ -25,7 +25,11 @@ class SppTopo(object):
     def __init__(self, spp_ctl_cli, subgraphs, size):
         self.spp_ctl_cli = spp_ctl_cli
         self.subgraphs = subgraphs
-        self.graph_size = size
+        self.graph_size = None
+
+        if self.resize(size) is not True:
+            print('Config "topo_size" is invalid value.')
+            exit()
 
     def run(self, args, sec_ids):
         args_ary = args.split()
@@ -42,6 +46,32 @@ class SppTopo(object):
         else:
             print("Usage: topo dst [ftype]")
 
+    def resize(self, size):
+        """Parse given size and set to self.graph_size.
+
+        The format of `size` is percentage or ratio. Return True if succeeded
+        to parse, or False if invalid format.
+        """
+
+        size = str(size)
+        matched = re.match(r'(\d+)%$', size)
+        if matched:  # percentage
+            i = int(matched.group(1))
+            if i > 0 and  i <= 100:
+                self.graph_size = size
+                return True
+            else:
+                return False
+        elif re.match(r'0\.\d+$',size):  # ratio
+            i = float(size) * 100
+            self.graph_size = str(i) + '%'
+            return True
+        elif size == '1':
+            self.graph_size = '100%'
+            return True
+        else:
+            return False
+
     def show(self, dtype, sec_ids, size):
         res_ary = []
         error_codes = self.spp_ctl_cli.rest_common_error_codes
@@ -319,21 +349,6 @@ class SppTopo(object):
             topo_doc += "commands/experimental.html"
             print("See '%s' for required packages." % topo_doc)
 
-    def resize_graph(self, args):
-        if args == '':
-            print(self.graph_size)
-        else:
-            if '%' in args:
-                self.graph_size = args
-                print(self.graph_size)
-            elif '.' in args:
-                ii = float(args) * 100
-                self.graph_size = str(ii) + '%'
-                print(self.graph_size)
-            else:  # TODO(yasufum) add check for no number
-                self.graph_size = str(float(args) * 100) + '%'
-                print(self.graph_size)
-
     def format_sec_status(self, sec_id, stat):
         """Return formatted secondary status as a hash
 
@@ -479,18 +494,6 @@ class SppTopo(object):
 
         print(msg)
 
-    @classmethod
-    def help_resize(cls):
-        msg = """Change the size of the image of topo command.
-
-        You can specify the size by percentage or ratio.
-
-        spp > topo resize 60%  # percentage
-        spp > topo resize 0.6  # ratio
-        """
-
-        print(msg)
-
     @classmethod
     def help_subgraph(cls):
         msg = """Edit subgarph for topo command.
diff --git a/src/cli/shell.py b/src/cli/shell.py
index 34c12a1..d98cc8b 100644
--- a/src/cli/shell.py
+++ b/src/cli/shell.py
@@ -627,6 +627,8 @@ class Shell(cmd.Cmd, object):
                 # Command prompt should be updated immediately
                 if key == 'prompt':
                     self.prompt = self.cli_config['prompt']['val']
+                elif key == 'topo_size':
+                    self.spp_topo.resize(self.cli_config['topo_size']['val'])
 
     def help_config(self):
         """Print help message of config command."""
@@ -904,14 +906,6 @@ class Shell(cmd.Cmd, object):
         else:
             pass
 
-    def do_topo_resize(self, args):
-        """Change the size of the image of topo_resize command."""
-        self.spp_topo.resize_graph(args)
-
-    def help_topo_resize(self):
-        """Print help message of topo command."""
-        topo.SppTopo.help_resize()
-
     def do_topo(self, args):
         """Output network topology."""
         self.spp_topo.run(args, self.get_sec_ids('nfv'))
-- 
2.17.1


  reply	other threads:[~2019-08-12  7:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-12  7:12 [spp] [PATCH 0/8] Update topo to support other than spp_nfv Yasufumi Ogawa
2019-08-12  7:12 ` Yasufumi Ogawa [this message]
2019-08-12  7:12 ` [spp] [PATCH 2/8] cli: revise composing dot script Yasufumi Ogawa
2019-08-12  7:12 ` [spp] [PATCH 3/8] cli: move style params for dot to config Yasufumi Ogawa
2019-08-12  7:12 ` [spp] [PATCH 4/8] cli: add to get sec ID and procs to SppCtlClient Yasufumi Ogawa
2019-08-12  7:12 ` [spp] [PATCH 5/8] cli: support other than spp_nfv in topo command Yasufumi Ogawa
2019-08-12  7:12 ` [spp] [PATCH 6/8] cli: add port types for " Yasufumi Ogawa
2019-08-12  7:12 ` [spp] [PATCH 7/8] cli: add checking JSON objs in topo Yasufumi Ogawa
2019-08-12  7:12 ` [spp] [PATCH 8/8] cli: revise description for imgcat Yasufumi Ogawa

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=20190812071242.18934-2-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --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).