From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id E72EAA046B for ; Mon, 24 Jun 2019 09:11:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DE7181BED2; Mon, 24 Jun 2019 09:11:45 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id 0CE051BF49 for ; Mon, 24 Jun 2019 09:11:44 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id f21so6615830pgi.3 for ; Mon, 24 Jun 2019 00:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=L7fezTqpIxtSTMbXcqk0Cuh1yKDesSRnhp7iRui20fo=; b=eVdqf54H61caahgzIF3f4qTMEJmM3ZTOjTPD24RwNhBGMB5oHvXB6V8bflZtYMhVv5 WLSkRx1Krwl0oQES6AeLTho97zDVPEbaGOX9BIQ1voFE1YwnR0oCu74fU0w/JtsPcjeQ 3/XleeClPiw0YSQYTKqpI/tyHp3J0LLos+z202W7HfEhGcdyRzaIKaQ5EIih8tB4jaho JQp0Nc/cplBbod3d9/gxmPWrMnUJXtFjbyGdh4sxgW5snGlVVshApRYamwKzMb77opsL BP3Q/wR+2Hzpg4Q8QCSKAJXItYVtA1zUi1z1LL+POB8V/8GOL0p1EtkO7bgX511QrfIx Ky8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=L7fezTqpIxtSTMbXcqk0Cuh1yKDesSRnhp7iRui20fo=; b=tZ0NktRlT/qxG6k0QyzcR8GDAykyepBc4pV+aV0bnzcHB8mH7UBw2mxNxp4JlSLmyL v24S8LdAc/CRz9yE9EgoNrtcIaUl8tlHzGkw1MaFpV5rUfsIohJo+okTkxZwQn6rQUJi QodaxvG0wB14prW/qf5KfyN0kEtdPV5NPNvipG8RYEosXdmsYcUH5eSU4pyHTyVJaYo4 tNeDYnoKfvQ4JzUNphfIQvhsehQDgdDTKReneY/wv0U1F6dosnDoSCjyBkYv2/wKAtTr xQMmnK4aZXOzFRCEyOkJnRj/HxeKUe6Zb9WbbAduT3kHdcQ6eN/UJXeM8jMLyg0DDYoK EY1g== X-Gm-Message-State: APjAAAXBaaXIR7JRNa2k2gpRvN2GQw2YJFzBZ8YOZarSLxxENB6VZ3DR E61LSvpN/I/anNZPHXujMYifR/oO X-Google-Smtp-Source: APXvYqyXqXT690/Zz33H/ToMHjPdGBo0px8B1J0Ojknb7ekvRBPkdRa2F4YaGVesbSnwklIqeKFuoA== X-Received: by 2002:a17:90a:8984:: with SMTP id v4mr22959277pjn.133.1561360303048; Mon, 24 Jun 2019 00:11:43 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id y17sm6357948pfe.148.2019.06.24.00.11.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jun 2019 00:11:42 -0700 (PDT) From: yasufum.o@gmail.com To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Mon, 24 Jun 2019 16:11:24 +0900 Message-Id: <20190624071124.23451-11-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190624071124.23451-1-yasufum.o@gmail.com> References: <20190624071124.23451-1-yasufum.o@gmail.com> Subject: [spp] [PATCH 10/10] controller: move rest of help msg to help_msg X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: spp-bounces@dpdk.org Sender: "spp" From: Yasufumi Ogawa This update is to move help message of rest of commands to `help_msg`. Signed-off-by: Yasufumi Ogawa --- src/controller/commands/help_msg.py | 125 ++++++++++++++++++++- src/controller/shell.py | 165 ++++++++++++---------------- 2 files changed, 194 insertions(+), 96 deletions(-) diff --git a/src/controller/commands/help_msg.py b/src/controller/commands/help_msg.py index 9e15123..f303547 100644 --- a/src/controller/commands/help_msg.py +++ b/src/controller/commands/help_msg.py @@ -1,10 +1,131 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2019 Nippon Telegraph and Telephone Corporation -commands = { +cmds = { 'status': """Display status info of SPP processes. spp > status - """ + """, + + 'record': + """Save commands as a recipe file. + + Save all of commands to a specified file as a recipe. This file + is reloaded with 'playback' command later. You can also edit + the recipe by hand to customize. + + spp > record path/to/recipe_file + """, + + 'playback': + """Setup a network configuration from recipe file. + + Recipe is a file describing a series of SPP command to setup + a network configuration. + + spp > playback path/to/recipe_file + """, + + 'config': + """Show or update config. + + # show list of config + spp > config + + # set prompt to "$ spp " + spp > config prompt "$ spp " + """, + + 'pwd': + """Show corrent directory. + + It behaves as UNIX's pwd command. + + spp > pwd + """, + + 'ls': + """Show a list of specified directory. + + It behaves as UNIX's ls command. + + spp > ls path/to/dir + """, + + 'cd': + """Change current directory. + + spp > cd path/to/dir + """, + + 'mkdir': + """Create a new directory. + + It behaves as 'mkdir -p' which means that you can create sub + directories at once. + + spp > mkdir path/to/dir + """, + + 'cat': + """View contents of a file. + + spp > cat file + """, + + 'redo': + """Execute command of index of history. + + spp > redo 5 # exec 5th command in the history + """, + + 'history': + """Show command history. + + spp > history + 1 ls + 2 cat file.txt + ... + + Command history is recorded in a file named '.spp_history'. + It does not add some command which are no meaning for history. + 'bye', 'exit', 'history', 'redo' + """, + + 'less': + """View contents of a file. + + spp > less file + """, + + 'exit': + """Terminate SPP controller process. + + It is an alias of bye command to terminate controller. + + spp > exit + Thank you for using Soft Patch Panel + """, + + 'inspect': + """Print attributes of Shell for debugging. + + This command is intended to be used by developers to show the + inside of the object of Shell class. + + spp > inspect + {'cmdqueue': [], + 'completekey': 'tab', + 'completion_matches': ['inspect'], + ... + """, + + 'load_cmd': + """Load command plugin. + + Path of plugin file is 'spp/src/controller/plugins'. + + spp > load_cmd hello + """, } diff --git a/src/controller/shell.py b/src/controller/shell.py index 065fb07..3f4d95b 100644 --- a/src/controller/shell.py +++ b/src/controller/shell.py @@ -276,7 +276,7 @@ class Shell(cmd.Cmd, object): def help_status(self): """Print help message of status command.""" - print(help_msg.commads['status']) + print(help_msg.cmds['status']) def do_pri(self, command): """Send a command to primary process.""" @@ -533,31 +533,22 @@ class Shell(cmd.Cmd, object): self.get_sec_ids('pcap'), text, line, begidx, endidx) def do_record(self, fname): - """Save commands as a recipe file. - - Save all of commands to a specified file as a recipe. This file - is reloaded with 'playback' command later. You can also edit - the recipe by hand to customize. - - spp > record path/to/recipe_file - """ + """Save commands as a recipe file.""" if fname == '': print("Record file is required!") else: self.recorded_file = open(fname, 'w') + def help_record(self): + """Print help message of record command.""" + print(help_msg.cmds['record']) + def complete_record(self, text, line, begidx, endidx): return common.compl_common(text, line) def do_playback(self, fname): - """Setup a network configuration from recipe file. - - Recipe is a file describing a series of SPP command to setup - a network configuration. - - spp > playback path/to/recipe_file - """ + """Setup a network configuration from recipe file.""" if fname == '': print("Record file is required!") @@ -575,18 +566,15 @@ class Shell(cmd.Cmd, object): message = "Error: File does not exist." print(message) + def help_playback(self): + """Print help message of playback command.""" + print(help_msg.cmds['playback']) + def complete_playback(self, text, line, begidx, endidx): return common.compl_common(text, line) def do_config(self, args): - """Show or update config. - - # show list of config - spp > config - - # set prompt to "$ spp " - spp > config prompt "$ spp " - """ + """Show or update config.""" tokens = args.strip().split(' ') if len(tokens) == 1: @@ -620,6 +608,10 @@ class Shell(cmd.Cmd, object): if key == 'prompt': self.prompt = self.cli_config['prompt']['val'] + def help_config(self): + """Print help message of config command.""" + print(help_msg.cmds['config']) + def complete_config(self, text, line, begidx, endidx): candidates = [] tokens = line.strip().split(' ') @@ -640,22 +632,15 @@ class Shell(cmd.Cmd, object): return completions def do_pwd(self, args): - """Show corrent directory. - - It behaves as UNIX's pwd command. - - spp > pwd - """ - + """Show corrent directory.""" print(os.getcwd()) - def do_ls(self, args): - """Show a list of specified directory. + def help_pwd(self): + """Print help message of pwd command.""" + print(help_msg.cmds['pwd']) - It behaves as UNIX's ls command. - - spp > ls path/to/dir - """ + def do_ls(self, args): + """Show a list of specified directory.""" if args == '' or os.path.isdir(args): c = 'ls -F %s' % args @@ -663,14 +648,15 @@ class Shell(cmd.Cmd, object): else: print("No such a directory.") + def help_ls(self): + """Print help message of ls command.""" + print(help_msg.cmds['ls']) + def complete_ls(self, text, line, begidx, endidx): return common.compl_common(text, line) def do_cd(self, args): - """Change current directory. - - spp > cd path/to/dir - """ + """Change current directory.""" if os.path.isdir(args): os.chdir(args) @@ -678,21 +664,23 @@ class Shell(cmd.Cmd, object): else: print("No such a directory.") + def help_cd(self): + """Print help message of cd command.""" + print(help_msg.cmds['cd']) + def complete_cd(self, text, line, begidx, endidx): return common.compl_common(text, line, 'directory') def do_mkdir(self, args): - """Create a new directory. - - It behaves as 'mkdir -p' which means that you can create sub - directories at once. - - spp > mkdir path/to/dir - """ + """Create a new directory.""" c = 'mkdir -p %s' % args subprocess.call(c, shell=True) + def help_mkdir(self): + """Print help message of mkdir command.""" + print(help_msg.cmds['mkdir']) + def complete_mkdir(self, text, line, begidx, endidx): return common.compl_common(text, line) @@ -718,21 +706,19 @@ class Shell(cmd.Cmd, object): return spp_bye.complete(text, line, begidx, endidx) def do_cat(self, arg): - """View contents of a file. - - spp > cat file - """ + """View contents of a file.""" if os.path.isfile(arg): c = 'cat %s' % arg subprocess.call(c, shell=True) else: print("No such a directory.") - def do_redo(self, args): - """Execute command of index of history. + def help_cat(self): + """Print help message of cat command.""" + print(help_msg.cmds['cat']) - spp > redo 5 # exec 5th command in the history - """ + def do_redo(self, args): + """Execute command of index of history.""" idx = int(args) cmdline = None @@ -754,18 +740,12 @@ class Shell(cmd.Cmd, object): except IOError: print('Error: Cannot open history file "%s"' % self.hist_file) - def do_history(self, arg): - """Show command history. - - spp > history - 1 ls - 2 cat file.txt - ... + def help_redo(self): + """Print help message of redo command.""" + print(help_msg.cmds['redo']) - Command history is recorded in a file named '.spp_history'. - It does not add some command which are no meaning for history. - 'bye', 'exit', 'history', 'redo' - """ + def do_history(self, arg): + """Show command history.""" try: f = open(self.hist_file) @@ -785,53 +765,51 @@ class Shell(cmd.Cmd, object): except IOError: print('Error: Cannot open history file "%s"' % self.hist_file) + def help_history(self): + """Print help message of history command.""" + print(help_msg.cmds['history']) + def complete_cat(self, text, line, begidx, endidx): return common.compl_common(text, line) def do_less(self, arg): - """View contents of a file. + """View contents of a file.""" - spp > less file - """ if os.path.isfile(arg): c = 'less %s' % arg subprocess.call(c, shell=True) else: print("No such a directory.") + def help_less(self): + """Print help message of less command.""" + print(help_msg.cmds['less']) + def complete_less(self, text, line, begidx, endidx): return common.compl_common(text, line) def do_exit(self, args): - """Terminate SPP controller process. - - It is an alias of bye command to terminate controller. - - spp > exit - Thank you for using Soft Patch Panel - """ + """Terminate SPP controller process.""" self.close() print('Thank you for using Soft Patch Panel') return True - def do_inspect(self, args): - """Print attributes of Shell for debugging. - - This command is intended to be used by developers to show the - inside of the object of Shell class. + def help_exit(self): + """Print help message of exit command.""" + print(help_msg.cmds['exit']) - spp > inspect - {'cmdqueue': [], - 'completekey': 'tab', - 'completion_matches': ['inspect'], - ... - """ + def do_inspect(self, args): + """Print attributes of Shell for debugging.""" from pprint import pprint if args == '': pprint(vars(self)) + def help_inspect(self): + """Print help message of inspect command.""" + print(help_msg.cmds['inspect']) + def terms_topo_subgraph(self): """Define terms of topo_subgraph command.""" @@ -927,12 +905,7 @@ class Shell(cmd.Cmd, object): return self.spp_topo.complete(text, line, begidx, endidx) def do_load_cmd(self, args): - """Load command plugin. - - Path of plugin file is 'spp/src/controller/plugins'. - - spp > load_cmd hello - """ + """Load command plugin.""" args = re.sub(',', ' ', args) args = re.sub(r'\s+', ' ', args) @@ -947,6 +920,10 @@ class Shell(cmd.Cmd, object): print("Module '%s' loaded." % mod_name) + def help_load_cmd(self): + """Print help message of load_cmd command.""" + print(help_msg.cmds['load_cmd']) + def complete_load_cmd(self, text, line, begidx, endidx): """Complete command plugins -- 2.17.1