From 94ec2f0c0a6fc30fb3a9a11243146e0d878c4c5b Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 20 Mar 2016 11:49:17 +0200 Subject: ZMQ CEL5.9 / 32 bit / 64 bit with python 2 / python 3 --- .../stl/trex_stl_lib/trex_stl_ext.py | 81 +++++++++------------- 1 file changed, 31 insertions(+), 50 deletions(-) (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py index 9289e513..fe89160a 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py @@ -1,6 +1,7 @@ import sys import os import warnings +import platform # if not set - set it to default TREX_STL_EXT_PATH = os.environ.get('TREX_STL_EXT_PATH') @@ -20,9 +21,15 @@ CLIENT_UTILS_MODULES = ['dpkt-1.8.6', ] -def import_module_list(modules_list): +CLIENT_PLATFORM_MODULES = ['pyzmq-14.5.0'] + + +def import_module_list(modules_list, platform_modules_list): + assert(isinstance(modules_list, list)) + assert(isinstance(platform_modules_list, list)) + # regular modules for p in modules_list: full_path = os.path.join(TREX_STL_EXT_PATH, p) fix_path = os.path.normcase(full_path) @@ -30,57 +37,31 @@ def import_module_list(modules_list): if not os.path.exists(fix_path): print "Unable to find required module library: '{0}'".format(p) print "Please provide the correct path using TREX_STL_EXT_PATH variable" - print "current path used: '{0}'".format(TREX_STL_EXT_PATH) + print "current path used: '{0}'".format(fix_path) exit(0) sys.path.insert(1, full_path) + # platform depdendant modules + is_64bit = platform.architecture()[0] == '64bit' + is_python3 = (sys.version_info >= (3, 0)) + is_cel = os.path.exists('/etc/system-profile') + + platform_path = "{0}/{1}/{2}".format('cel59' if is_cel else 'fedora18', + 'python3' if is_python3 else 'python2', + '64bit' if is_64bit else '32bit') + + for p in platform_modules_list: + full_path = os.path.join(TREX_STL_EXT_PATH, p, platform_path) + fix_path = os.path.normcase(full_path) + + if not os.path.exists(fix_path): + print "Unable to find required platfrom dependant module library: '{0}'".format(p) + print "platform dependant path used was '{0}'".format(fix_path) + exit(0) + + sys.path.insert(1, full_path) + + -# TODO; REFACTOR THIS....it looks horrible -def import_platform_dirs (): - # handle platform dirs - - # try fedora 18 first and then cel5.9 - # we are using the ZMQ module to determine the right platform - - full_path = os.path.join(TREX_STL_EXT_PATH, 'platform/fedora18') - fix_path = os.path.normcase(full_path) - sys.path.insert(0, full_path) - try: - # try to import and delete it from the namespace - import zmq - del zmq - return - except: - sys.path.pop(0) - pass - - full_path = os.path.join(TREX_STL_EXT_PATH, 'platform/cel59') - fix_path = os.path.normcase(full_path) - sys.path.insert(0, full_path) - try: - # try to import and delete it from the namespace - import zmq - del zmq - return - except: - sys.path.pop(0) - pass - - full_path = os.path.join(TREX_STL_EXT_PATH, 'platform/cel59/32bit') - fix_path = os.path.normcase(full_path) - sys.path.insert(0, full_path) - try: - # try to import and delete it from the namespace - import zmq - del zmq - return - - except: - sys.path.pop(0) - sys.modules['zmq'] = None - warnings.warn("unable to determine platform type for ZMQ import") - - -import_module_list(CLIENT_UTILS_MODULES) -import_platform_dirs() +import_module_list(CLIENT_UTILS_MODULES, CLIENT_PLATFORM_MODULES) -- cgit 1.2.3-korg