test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH V1] framework/*: changed method of import Dot1BR
@ 2021-12-02  5:42 Dong JunX
  0 siblings, 0 replies; only message in thread
From: Dong JunX @ 2021-12-02  5:42 UTC (permalink / raw)
  To: dts; +Cc: lijuan.tu, weix.ling, junx.dong

Signed-off-by: Dong JunX <junx.dong@intel.com>
---
 framework/packet.py | 8 ++++++--
 framework/utils.py  | 6 ------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/framework/packet.py b/framework/packet.py
index adfa985..dac3ea5 100644
--- a/framework/packet.py
+++ b/framework/packet.py
@@ -32,12 +32,14 @@
 Generic packet create, transmit and analyze module
 Base on scapy(python program for packet manipulation)
 """
+import os
+import subprocess
 import shutil
 
 from importlib import import_module
 from socket import AF_INET6
 from scapy.all import *
-from .utils import convert_int2ip, convert_ip2int, get_module_path
+from .utils import convert_int2ip, convert_ip2int
 
 # load extension layers
 exec_file = os.path.realpath(__file__)
@@ -49,7 +51,9 @@ if not os.path.exists(TMP_PATH):
     os.system('mkdir -p %s' % TMP_PATH)
 
 # copy dep/Dot1BR to scapy
-_contrib_module_path = get_module_path('scapy.contrib')
+_scapy_module_path = subprocess.check_output("python3 -m pip show scapy |grep Location |awk -F': ' '{print $2}'",
+                                             encoding='utf-8', stderr=subprocess.STDOUT, shell=True)
+_contrib_module_path = os.path.join(_scapy_module_path.strip(), 'scapy', 'contrib')
 shutil.copy(DTS_PATH + '/dep/scapy_modules/Dot1BR.py', _contrib_module_path)
 
 scapy_modules_required = {'scapy.contrib.gtp': ['GTP_U_Header', 'GTPPDUSessionContainer'],
diff --git a/framework/utils.py b/framework/utils.py
index 269bfbb..5eefd0a 100644
--- a/framework/utils.py
+++ b/framework/utils.py
@@ -309,9 +309,3 @@ def check_dts_python_version():
              "and will not work in future releases.")), file=sys.stderr)
         print(RED("Please use Python >= 3.6.9 instead"), file=sys.stderr)
 
-def get_module_path(module_name):
-    from importlib import import_module
-    _module = import_module(module_name)
-    _module_file_path = _module.__file__
-    del _module
-    return os.path.dirname(_module_file_path)
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-02  5:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02  5:42 [dts] [PATCH V1] framework/*: changed method of import Dot1BR Dong JunX

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