[spp] [PATCH 2/3] controller: add topo_resize command

ogawa.yasufumi at lab.ntt.co.jp ogawa.yasufumi at lab.ntt.co.jp
Mon Apr 23 08:22:36 CEST 2018


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

From: Yasufumi Ogawa <ogawa.yasufumi at 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 at 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




More information about the spp mailing list