From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org
Cc: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Subject: [spp] [PATCH 04/13] controller: add load command
Date: Tue, 6 Mar 2018 19:50:46 +0900 [thread overview]
Message-ID: <20180306105055.65210-5-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20180306105055.65210-1-ogawa.yasufumi@lab.ntt.co.jp>
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Load command is for loading a command plugin. It enables users to
activate a command after SPP controller is launched. Plugin files
are included in 'src/controller/command/'.
This update also includes a sample command 'hello'. It says hello
message with given name.
spp > load hello
spp > hello alice
Hello, alice!
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/command/__init__.py | 0
src/controller/command/hello.py | 28 ++++++++++++++++++++++++++++
src/controller/shell.py | 21 +++++++++++++++++++++
3 files changed, 49 insertions(+)
create mode 100644 src/controller/command/__init__.py
create mode 100644 src/controller/command/hello.py
diff --git a/src/controller/command/__init__.py b/src/controller/command/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/src/controller/command/hello.py b/src/controller/command/hello.py
new file mode 100644
index 0000000..f898234
--- /dev/null
+++ b/src/controller/command/hello.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+
+class Hello(object):
+ def __init__(self, name):
+ self.name = name
+
+ def say(self):
+ print("Hello, %s!" % self.name)
+
+
+def do_hello(name):
+ """Say hello to given user
+
+ spp > hello alice
+ Hello, alice!
+ """
+
+ if name == '':
+ print('name is required!')
+ else:
+ hl = Hello(name)
+ hl.say()
+
+if __name__ == "__main__":
+ hello = Hello()
+ print(hello.say())
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 06b0012..7c7d94a 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -1,4 +1,5 @@
import cmd
+# import importlib
import json
import os
from Queue import Empty
@@ -563,3 +564,23 @@ class Shell(cmd.Cmd, object):
self.close()
print('Thank you for using Soft Patch Panel')
return True
+
+ def do_load(self, args):
+ """Load command plugin
+
+ Path of plugin file is 'spp/src/controller/command'.
+
+ spp > load hello
+ """
+
+ args = re.sub(',', ' ', args)
+ args = re.sub(r'\s+', ' ', args)
+ list_args = args.split(' ')
+
+ libdir = 'command'
+ loaded = '%s.%s' % (libdir, list_args[0])
+ # importlib.import_module(loaded)
+ exec('import %s' % loaded)
+ do_cmd = '%s.do_%s' % (loaded, list_args[0])
+ setattr(self, 'do_%s' % list_args[0], eval(do_cmd))
+ print("Module '%s' loaded." % loaded)
--
2.13.1
next prev parent reply other threads:[~2018-03-06 10:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 10:50 [spp] [PATCH 00/13] Change structure of SPP controller ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 01/13] spp: move controller to sub directory ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 02/13] controller: move connection threads ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 03/13] controller: aggregate logger to spp_common.py ogawa.yasufumi
2018-03-06 10:50 ` ogawa.yasufumi [this message]
2018-03-06 10:50 ` [spp] [PATCH 05/13] controller: move common methods to shell_lib ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 06/13] controller: add filter for py to compl_common ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 07/13] controller: refactor shell.py ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 08/13] controller: change logger output to logfile ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 09/13] controller: add do_topo to shell.py ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 10/13] controller: add topo.py ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 11/13] controller: add topo_subgraph command ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 12/13] controller: add cat and less command ogawa.yasufumi
2018-03-06 10:50 ` [spp] [PATCH 13/13] controller: create log directory ogawa.yasufumi
2018-03-27 23:41 ` [spp] [PATCH 00/13] Change structure of 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=20180306105055.65210-5-ogawa.yasufumi@lab.ntt.co.jp \
--to=ogawa.yasufumi@lab.ntt.co.jp \
--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).