Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, geminoa@juno.ocn.ne.jp
Cc: spp@dpdk.org, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 2/3] controller: add topo_resize command
Date: Mon, 23 Apr 2018 15:22:36 +0900	[thread overview]
Message-ID: <20180423054630.6789-3-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20180423054630.6789-1-ogawa.yasufumi@lab.ntt.co.jp>
In-Reply-To: <20180423054630.6789-1-ogawa.yasufumi@lab.ntt.co.jp>

From: ogawa.yasufumi@lab.ntt.co.jp

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

topo_resize command is for changing size of an image of topo term.

  # topo_resize without arg shows current ratio
  spp > topo_resize
  60%

  # resize with percentage
  spp > topo_resize 80%
  80%

  # resize with ratio
  spp > topo_resize 0.8
  80%

  # it is also able to use int
  spp > topo_resize 1
  100%

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/shell.py | 18 +++++++++++++++++-
 src/controller/topo.py  |  8 ++++----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/controller/shell.py b/src/controller/shell.py
index ea5e8a9..1cf712c 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -31,6 +31,7 @@ class Shell(cmd.Cmd, object):
 
     PLUGIN_DIR = 'command'
     subgraphs = {}
+    topo_size = '60%'
 
     def default(self, line):
         """Define defualt behaviour
@@ -646,6 +647,21 @@ class Shell(cmd.Cmd, object):
         else:
             pass
 
+    def do_topo_resize(self, args):
+        if args == '':
+            print(self.topo_size)
+        else:
+            if '%' in args:
+                self.topo_size = args
+                print(self.topo_size)
+            elif '.' in args:
+                ii = float(args) * 100
+                self.topo_size = str(ii) + '%'
+                print(self.topo_size)
+            else:  # TODO(yasufum) add check for no number
+                self.topo_size = str(float(args) * 100) + '%'
+                print(self.topo_size)
+
     def do_topo(self, args):
         """Output network topology
 
@@ -676,7 +692,7 @@ class Shell(cmd.Cmd, object):
                 print("Usage: topo dst [ftype]")
                 return False
             elif (args_ary[0] == "term") or (args_ary[0] == "http"):
-                res_ary = tp.show(args_ary[0])
+                res_ary = tp.show(args_ary[0], self.topo_size)
             elif len(args_ary) == 1:
                 ftype = args_ary[0].split(".")[-1]
                 res_ary = tp.output(args_ary[0], ftype)
diff --git a/src/controller/topo.py b/src/controller/topo.py
index aa81e03..ff1349c 100644
--- a/src/controller/topo.py
+++ b/src/controller/topo.py
@@ -28,7 +28,7 @@ class Topo(object):
         self.s2m_queues = s2m_queues
         self.sub_graphs = sub_graphs
 
-    def show(self, dtype):
+    def show(self, dtype, size):
         res_ary = []
         for sec_id in self.sec_ids:
             self.m2s_queues[sec_id].put("status")
@@ -38,7 +38,7 @@ class Topo(object):
         if dtype == "http":
             self.to_http(res_ary)
         elif dtype == "term":
-            self.to_term(res_ary)
+            self.to_term(res_ary, size)
         else:
             print("Invalid file type")
             return res_ary
@@ -259,7 +259,7 @@ class Topo(object):
         ws.send(msg)
         ws.close()
 
-    def to_term(self, sec_list):
+    def to_term(self, sec_list, size):
         tmpfile = "%s.jpg" % uuid.uuid4().hex
         self.to_img(sec_list, tmpfile)
         from distutils import spawn
@@ -272,7 +272,7 @@ class Topo(object):
             img_cmd = "%s/%s/imgcat.sh" % (
                 os.path.dirname(__file__), '3rd_party')
         # Resize image to fit the terminal
-        img_size = "60%"
+        img_size = size
         cmd = "convert -resize %s %s %s" % (img_size, tmpfile, tmpfile)
         subprocess.call(cmd, shell=True)
         subprocess.call("%s %s" % (img_cmd, tmpfile), shell=True)
-- 
2.13.1

  parent reply	other threads:[~2018-04-23  6:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-23  6:22 [spp] [PATCH 0/3] Misc improvements for spp controller ogawa.yasufumi
2018-04-23  6:22 ` [spp] [PATCH 1/3] controller: move import websocket ogawa.yasufumi
2018-04-23  6:22 ` ogawa.yasufumi [this message]
2018-04-23  6:22 ` [spp] [PATCH 3/3] docs: add description for topo_resize command ogawa.yasufumi
2018-05-03 15:58 ` [spp] [PATCH 0/3] Misc improvements for 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=20180423054630.6789-3-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=geminoa@juno.ocn.ne.jp \
    --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).