[spp] [PATCH 08/10] controller: move topo help msg to SppBye

yasufum.o at gmail.com yasufum.o at gmail.com
Mon Jun 24 09:11:22 CEST 2019


From: Yasufumi Ogawa <yasufum.o at gmail.com>

This patch is to move comment of `do_topo`, `do_topo_subgraph` and
`do_topo_resize` to `SppTopo.help` to reduce the number of lines.

Signed-off-by: Yasufumi Ogawa <yasufum.o at gmail.com>
---
 src/controller/commands/topo.py | 52 ++++++++++++++++++++++++++++
 src/controller/shell.py         | 61 +++++++++------------------------
 2 files changed, 68 insertions(+), 45 deletions(-)

diff --git a/src/controller/commands/topo.py b/src/controller/commands/topo.py
index 3b24c1a..21ef1ec 100644
--- a/src/controller/commands/topo.py
+++ b/src/controller/commands/topo.py
@@ -459,3 +459,55 @@ class SppTopo(object):
             return True
         else:
             return False
+
+    @classmethod
+    def help(cls):
+        msg = """Output network topology.
+
+        Support four types of output.
+        * terminal (but very few terminals supporting to display images)
+        * browser (websocket server is required)
+        * image file (jpg, png, bmp)
+        * text (dot, js or json, yml or yaml)
+
+        spp > topo term  # terminal
+        spp > topo http  # browser
+        spp > topo network_conf.jpg  # image
+        spp > topo network_conf.dot  # text
+        spp > topo network_conf.js# text
+        """
+
+        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.
+
+        Subgraph is a group of object defined in dot language. For topo
+        command, it is used for grouping resources of each of VM or
+        container to topology be more understandable.
+
+        (1) Add subgraph labeled 'vm1'.
+            spp > topo_subgraph add vm1 vhost:1;vhost:2
+
+        (2) Delete subgraph 'vm1'.
+            spp > topo_subgraph del vm1
+
+        (3) Show subgraphs by running topo_subgraph without args.
+            spp > topo_subgraph
+            label: vm1	subgraph: "vhost:1;vhost:2"
+        """
+
+        print(msg)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 8cb74a0..54376c9 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -824,11 +824,7 @@ class Shell(cmd.Cmd, object):
         {'cmdqueue': [],
          'completekey': 'tab',
          'completion_matches': ['inspect'],
-         'lastcmd': 'inspect',
-         'old_completer': None,
-         'stdin': <open file '<stdin>', mode 'r' at 0x7fe96bddf0c0>,
-         'stdout': <open file '<stdout>', mode 'w' at 0x7fe96bddf150>}
-
+         ...
         """
 
         from pprint import pprint
@@ -841,22 +837,7 @@ class Shell(cmd.Cmd, object):
         return ['add', 'del']
 
     def do_topo_subgraph(self, args):
-        """Edit subgarph for topo command.
-
-        Subgraph is a group of object defined in dot language. For topo
-        command, it is used for grouping resources of each of VM or
-        container to topology be more understandable.
-
-        (1) Add subgraph labeled 'vm1'.
-        spp > topo_subgraph add vm1 vhost:1;vhost:2
-
-        (2) Delete subgraph 'vm1'.
-        spp > topo_subgraph del vm1
-
-        (3) Show subgraphs by running topo_subgraph without args.
-        spp > topo_subgraph
-        label: vm1	subgraph: "vhost:1;vhost:2"
-        """
+        """Edit subgarph for topo command."""
 
         # logger.info("Topo initialized with sec IDs %s" % sec_ids)
 
@@ -897,6 +878,10 @@ class Shell(cmd.Cmd, object):
             else:
                 print("Ivalid subcommand '%s'!" % tokens[0])
 
+    def help_topo_subgraph(self):
+        """Print help message of topo_subgraph command."""
+        topo.SppTopo.help_subgraph()
+
     def complete_topo_subgraph(self, text, line, begidx, endidx):
         terms = self.terms_topo_subgraph()
 
@@ -921,35 +906,21 @@ class Shell(cmd.Cmd, object):
             pass
 
     def do_topo_resize(self, args):
-        """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
-
-        """
-
+        """Change the size of the image of topo_resize command."""
         self.spp_topo.resize_graph(args)
 
-    def do_topo(self, args):
-        """Output network topology.
-
-        Support four types of output.
-        * terminal (but very few terminals supporting to display images)
-        * browser (websocket server is required)
-        * image file (jpg, png, bmp)
-        * text (dot, js or json, yml or yaml)
-
-        spp > topo term  # terminal
-        spp > topo http  # browser
-        spp > topo network_conf.jpg  # image
-        spp > topo network_conf.dot  # text
-        spp > topo network_conf.js# text
-        """
+    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'))
 
+    def help_topo(self):
+        """Print help message of topo command."""
+        topo.SppTopo.help()
+
     def complete_topo(self, text, line, begidx, endidx):
 
         return self.spp_topo.complete(text, line, begidx, endidx)
-- 
2.17.1



More information about the spp mailing list