Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 1/3] spp: fix bug of precmd
@ 2017-10-03 10:42 ogawa.yasufumi
  2017-10-03 10:42 ` [spp] [PATCH 2/3] spp: add record file check ogawa.yasufumi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ogawa.yasufumi @ 2017-10-03 10:42 UTC (permalink / raw)
  To: spp; +Cc: gerald.rogers, sy.jong.choi, Yasufumi Ogawa

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

In precmd function, command log is not recorded if it is
'playback' to avoid illegal action when the log is loaded.
However, 'bye' should be also excluded from the log because
spp.py is terminated immediately if the log is loaded.
This change for adding a condition for command logging.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/spp.py b/src/spp.py
index 68b3a3f..4aa0c62 100755
--- a/src/spp.py
+++ b/src/spp.py
@@ -503,8 +503,9 @@ class Shell(cmd.Cmd):
 
     def precmd(self, line):
         line = line.lower()
-        if self.recorded_file and 'playback' not in line:
-            print(line, file=self.recorded_file)
+        if self.recorded_file:
+            if not (('playback' in line) or ('bye' in line)):
+                print(line, file=self.recorded_file)
         return line
 
     def close(self):
-- 
2.13.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [spp] [PATCH 2/3] spp: add record file check
  2017-10-03 10:42 [spp] [PATCH 1/3] spp: fix bug of precmd ogawa.yasufumi
@ 2017-10-03 10:42 ` ogawa.yasufumi
  2017-10-03 10:42 ` [spp] [PATCH 3/3] spp: change logger to optional ogawa.yasufumi
  2017-11-29  1:35 ` [spp] [PATCH 1/3] spp: fix bug of precmd Ferruh Yigit
  2 siblings, 0 replies; 4+ messages in thread
From: ogawa.yasufumi @ 2017-10-03 10:42 UTC (permalink / raw)
  To: spp; +Cc: gerald.rogers, sy.jong.choi, Yasufumi Ogawa

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

record and playback command should be given a record file name
but there are no checking if it is given.

This change adds checking for record file in do_record and
do_playback methods.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp.py | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/spp.py b/src/spp.py
index 4aa0c62..4bbbb44 100755
--- a/src/spp.py
+++ b/src/spp.py
@@ -477,29 +477,35 @@ class Shell(cmd.Cmd):
             print ("first %s" % cmds[1])
             self.response(CMD_ERROR, "invalid format")
 
-    def do_record(self, arg):
+    def do_record(self, fname):
         """Save future commands to filename:  RECORD filename.cmd"""
 
-        self.recorded_file = open(arg, 'w')
-        self.response(CMD_OK, "record")
+        if fname == '':
+            print("Record file is required!")
+        else:
+            self.recorded_file = open(fname, 'w')
+            self.response(CMD_OK, "record")
 
-    def do_playback(self, arg):
+    def do_playback(self, fname):
         """Playback commands from a file:  PLAYBACK filename.cmd"""
 
-        self.close()
-        try:
-            with open(arg) as recorded_file:
-                lines = []
-                for line in recorded_file:
-                    if line.strip().startswith("#"):
-                        continue
-                    lines.append(line)
-                self.cmdqueue.extend(lines)
-                self.response(CMD_OK, "playback")
-        except IOError:
-            message = "Error: File does not exist."
-            print(message)
-            self.response(CMD_NG, message)
+        if fname == '':
+            print("Record file is required!")
+        else:
+            self.close()
+            try:
+                with open(fname) as recorded_file:
+                    lines = []
+                    for line in recorded_file:
+                        if line.strip().startswith("#"):
+                            continue
+                        lines.append(line)
+                    self.cmdqueue.extend(lines)
+                    self.response(CMD_OK, "playback")
+            except IOError:
+                message = "Error: File does not exist."
+                print(message)
+                self.response(CMD_NG, message)
 
     def precmd(self, line):
         line = line.lower()
-- 
2.13.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [spp] [PATCH 3/3] spp: change logger to optional
  2017-10-03 10:42 [spp] [PATCH 1/3] spp: fix bug of precmd ogawa.yasufumi
  2017-10-03 10:42 ` [spp] [PATCH 2/3] spp: add record file check ogawa.yasufumi
@ 2017-10-03 10:42 ` ogawa.yasufumi
  2017-11-29  1:35 ` [spp] [PATCH 1/3] spp: fix bug of precmd Ferruh Yigit
  2 siblings, 0 replies; 4+ messages in thread
From: ogawa.yasufumi @ 2017-10-03 10:42 UTC (permalink / raw)
  To: spp; +Cc: gerald.rogers, sy.jong.choi, Yasufumi Ogawa

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

Logger in spp.py is used only for debugging and useless for users.

Use of logger is selectable by comment/uncomment logger's setting
defined after importing libraries.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp.py | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/spp.py b/src/spp.py
index 4bbbb44..ce8aff0 100755
--- a/src/spp.py
+++ b/src/spp.py
@@ -18,14 +18,17 @@ import readline
 import threading
 import json
 
-from logging import getLogger,StreamHandler,Formatter,DEBUG
-logger = getLogger(__name__)
-handler = StreamHandler()
-handler.setLevel(DEBUG)
-formatter = Formatter('%(asctime)s - [%(name)s] - [%(levelname)s] - %(message)s')
-handler.setFormatter(formatter)
-logger.setLevel(DEBUG)
-logger.addHandler(handler)
+logger = None
+
+# Comment out to activate debug logging
+#from logging import getLogger,StreamHandler,Formatter,DEBUG
+#logger = getLogger(__name__)
+#handler = StreamHandler()
+#handler.setLevel(DEBUG)
+#formatter = Formatter('%(asctime)s - [%(name)s] - [%(levelname)s] - %(message)s')
+#handler.setFormatter(formatter)
+#logger.setLevel(DEBUG)
+#logger.addHandler(handler)
 
 
 CMD_OK = "OK"
@@ -53,13 +56,16 @@ class CmdRequestHandler(SocketServer.BaseRequestHandler):
             CmdRequestHandler.CMD.onecmd(self.data)
             ret = RCMD_RESULT_QUEUE.get()
             if (ret is not None):
-                logger.debug("ret:%s" % ret)
+                if logger != None:
+                    logger.debug("ret:%s" % ret)
                 self.request.send(ret)
             else:
-                logger.debug("ret is none")
+                if logger != None:
+                    logger.debug("ret is none")
                 self.request.send("")
         else:
-            logger.debug("CMD is None")
+            if logger != None:
+                logger.debug("CMD is None")
             self.request.send("")
 
 
@@ -340,6 +346,7 @@ def clean_sec_cmd(cmdstr):
     return res
 
 
+
 class Shell(cmd.Cmd):
     """SPP command prompt"""
 
@@ -433,7 +440,8 @@ class Shell(cmd.Cmd):
             param = result + '\n' + message
             RCMD_RESULT_QUEUE.put(param)
         else:
-            logger.debug("unknown remote command = %s" % rcmd)
+            if logger != None:
+                logger.debug("unknown remote command = %s" % rcmd)
 
     def do_status(self, _):
         """Display Soft Patch Panel Status"""
@@ -488,7 +496,7 @@ class Shell(cmd.Cmd):
 
     def do_playback(self, fname):
         """Playback commands from a file:  PLAYBACK filename.cmd"""
-
+        
         if fname == '':
             print("Record file is required!")
         else:
-- 
2.13.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [spp] [PATCH 1/3] spp: fix bug of precmd
  2017-10-03 10:42 [spp] [PATCH 1/3] spp: fix bug of precmd ogawa.yasufumi
  2017-10-03 10:42 ` [spp] [PATCH 2/3] spp: add record file check ogawa.yasufumi
  2017-10-03 10:42 ` [spp] [PATCH 3/3] spp: change logger to optional ogawa.yasufumi
@ 2017-11-29  1:35 ` Ferruh Yigit
  2 siblings, 0 replies; 4+ messages in thread
From: Ferruh Yigit @ 2017-11-29  1:35 UTC (permalink / raw)
  To: ogawa.yasufumi, spp; +Cc: gerald.rogers, sy.jong.choi

On 10/3/2017 3:42 AM, ogawa.yasufumi@lab.ntt.co.jp wrote:
> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> 
> In precmd function, command log is not recorded if it is
> 'playback' to avoid illegal action when the log is loaded.
> However, 'bye' should be also excluded from the log because
> spp.py is terminated immediately if the log is loaded.
> This change for adding a condition for command logging.
> 
> Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Series applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-29  1:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-03 10:42 [spp] [PATCH 1/3] spp: fix bug of precmd ogawa.yasufumi
2017-10-03 10:42 ` [spp] [PATCH 2/3] spp: add record file check ogawa.yasufumi
2017-10-03 10:42 ` [spp] [PATCH 3/3] spp: change logger to optional ogawa.yasufumi
2017-11-29  1:35 ` [spp] [PATCH 1/3] spp: fix bug of precmd Ferruh Yigit

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).