Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com
Cc: spp@dpdk.org, Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Subject: [spp] [PATCH v2 1/3] controller: change importing for python3
Date: Thu, 24 May 2018 05:11:48 +0900	[thread overview]
Message-ID: <20180523201150.23042-2-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20180523201150.23042-1-ogawa.yasufumi@lab.ntt.co.jp>

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

This is the first patch for updating to python3. To keep backward
compatibility with python2, it uses future module.

To comply with python3, it uses absolute_import module in __future__
and changes importing modules with path info. Some of module name, for
instance Queue or SocketServer, are also changed to the names of
python3's.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/conn_thread.py |  8 +++++---
 src/controller/shell.py       | 28 +++++++++++++++-------------
 src/controller/spp.py         | 21 +++++++++++----------
 src/controller/spp_common.py  |  2 +-
 src/controller/topo.py        |  4 ++--
 src/spp.py                    |  1 +
 6 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/src/controller/conn_thread.py b/src/controller/conn_thread.py
index e42b0e8..bffdcee 100644
--- a/src/controller/conn_thread.py
+++ b/src/controller/conn_thread.py
@@ -2,11 +2,13 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2015-2016 Intel Corporation
 
-from Queue import Queue
+from __future__ import absolute_import
+
+from queue import Queue
 import select
 import socket
-import spp_common
-from spp_common import logger
+from . import spp_common
+from .spp_common import logger
 import threading
 import traceback
 
diff --git a/src/controller/shell.py b/src/controller/shell.py
index eac6aec..6bd9cb0 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -2,16 +2,18 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2015-2016 Intel Corporation
 
+from __future__ import absolute_import
+
 import cmd
 import json
 import os
-from Queue import Empty
+from queue import Empty
 import re
-from shell_lib import common
-import spp_common
-from spp_common import logger
+from .shell_lib import common
+from . import spp_common
+from .spp_common import logger
 import subprocess
-import topo
+from . import topo
 
 
 class Shell(cmd.Cmd, object):
@@ -87,11 +89,11 @@ class Shell(cmd.Cmd, object):
     def print_status(self):
         """Display information about connected clients"""
 
-        print ("Soft Patch Panel Status :")
-        print ("primary: %d" % spp_common.PRIMARY)  # it is 1 if PRIMA == True
-        print ("secondary count: %d" % len(spp_common.SECONDARY_LIST))
+        print("Soft Patch Panel Status :")
+        print("primary: %d" % spp_common.PRIMARY)  # it is 1 if PRIMA == True
+        print("secondary count: %d" % len(spp_common.SECONDARY_LIST))
         for i in spp_common.SECONDARY_LIST:
-            print ("Connected secondary id: %d" % i)
+            print("Connected secondary id: %d" % i)
 
     def print_sec_status(self, msg):
         """Parse and print message from SPP secondary
@@ -142,11 +144,11 @@ class Shell(cmd.Cmd, object):
         if spp_common.PRIMARY:
             spp_common.MAIN2PRIMARY.put(command)
             recv = spp_common.PRIMARY2MAIN.get(True)
-            print (recv)
+            print(recv)
             return self.CMD_OK, recv
         else:
             recv = "primary not started"
-            print (recv)
+            print(recv)
             return self.CMD_NOTREADY, recv
 
     def command_secondary(self, sec_id, command):
@@ -331,8 +333,8 @@ class Shell(cmd.Cmd, object):
                 print(message)
                 self.response(self.CMD_ERROR, message)
         else:
-            print (cmds[0])
-            print ("first %s" % cmds[1])
+            print(cmds[0])
+            print("first %s" % cmds[1])
             self.response(self.CMD_ERROR, "invalid format")
 
     def complete_sec(self, text, line, begidx, endidx):
diff --git a/src/controller/spp.py b/src/controller/spp.py
index 9c13d59..57604de 100644
--- a/src/controller/spp.py
+++ b/src/controller/spp.py
@@ -2,22 +2,23 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2015-2016 Intel Corporation
 
-from __future__ import print_function
+from __future__ import absolute_import
+# from __future__ import print_function
 
 import argparse
-from conn_thread import AcceptThread
-from conn_thread import PrimaryThread
-from shell import Shell
+from .conn_thread import AcceptThread
+from .conn_thread import PrimaryThread
+from .shell import Shell
 import socket
-import SocketServer
-import spp_common
-from spp_common import logger
+import socketserver
+from . import spp_common
+from .spp_common import logger
 import sys
 import threading
 import traceback
 
 
-class CmdRequestHandler(SocketServer.BaseRequestHandler):
+class CmdRequestHandler(socketserver.BaseRequestHandler):
     """Request handler for getting message from remote entities"""
 
     CMD = None  # contains a instance of Shell class
@@ -87,9 +88,9 @@ def main(argv):
     shell = Shell()
 
     # Run request handler as a TCP server thread
-    SocketServer.ThreadingTCPServer.allow_reuse_address = True
+    socketserver.ThreadingTCPServer.allow_reuse_address = True
     CmdRequestHandler.CMD = shell
-    command_server = SocketServer.ThreadingTCPServer(
+    command_server = socketserver.ThreadingTCPServer(
         (host, management_port), CmdRequestHandler)
 
     t = threading.Thread(target=command_server.serve_forever)
diff --git a/src/controller/spp_common.py b/src/controller/spp_common.py
index d89461b..80fab76 100644
--- a/src/controller/spp_common.py
+++ b/src/controller/spp_common.py
@@ -4,7 +4,7 @@
 
 import logging
 import os
-from Queue import Queue
+from queue import Queue
 
 # Setup logger object
 logger = logging.getLogger(__name__)
diff --git a/src/controller/topo.py b/src/controller/topo.py
index a09a873..c6347a4 100644
--- a/src/controller/topo.py
+++ b/src/controller/topo.py
@@ -4,8 +4,8 @@
 
 import os
 import re
-import spp_common
-from spp_common import logger
+from . import spp_common
+from .spp_common import logger
 import subprocess
 import traceback
 import uuid
diff --git a/src/spp.py b/src/spp.py
index 5c63924..62606e7 100755
--- a/src/spp.py
+++ b/src/spp.py
@@ -2,6 +2,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2015-2016 Intel Corporation
 
+from __future__ import absolute_import
 from controller import spp
 import sys
 
-- 
2.17.0

  reply	other threads:[~2018-05-23 20:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-15  1:20 [spp] [PATCH 0/3] Update for Python 3 support ogawa.yasufumi
2018-05-15  1:20 ` [spp] [PATCH 1/3] controller: change importing for python3 ogawa.yasufumi
2018-05-15  1:20 ` [spp] [PATCH 2/3] controller: fix encoding for socket ogawa.yasufumi
2018-05-15  1:20 ` [spp] [PATCH 3/3] docs: add description for python 3 support ogawa.yasufumi
2018-05-23 20:11 ` [spp] [PATCH v2 0/3] Update for Python " ogawa.yasufumi
2018-05-23 20:11   ` ogawa.yasufumi [this message]
2018-05-23 20:11   ` [spp] [PATCH v2 2/3] controller: fix encoding for socket ogawa.yasufumi
2018-05-23 20:11   ` [spp] [PATCH v2 3/3] docs: add description for python 3 support ogawa.yasufumi
2018-05-24 13:18   ` [spp] [PATCH v2 0/3] Update for Python " 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=20180523201150.23042-2-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).