From 709eda3b4ea0385da009932df3eba457e955e887 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 23 Mar 2016 16:11:53 +0200 Subject: moving us to python 3 by default (console) --- .../trex_control_plane/stl/console/trex_console.py | 14 +++++--- .../trex_control_plane/stl/console/trex_tui.py | 2 +- .../stl/trex_stl_lib/trex_stl_client.py | 7 ++-- .../stl/trex_stl_lib/trex_stl_stats.py | 6 ++-- .../stl/trex_stl_lib/utils/common.py | 4 +++ scripts/find_python.sh | 21 ++++-------- scripts/run_functional_tests | 39 ++++++++++------------ scripts/trex-console | 3 ++ 8 files changed, 49 insertions(+), 47 deletions(-) diff --git a/scripts/automation/trex_control_plane/stl/console/trex_console.py b/scripts/automation/trex_control_plane/stl/console/trex_console.py index 2f6744cc..8c71065c 100755 --- a/scripts/automation/trex_control_plane/stl/console/trex_console.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py @@ -17,6 +17,7 @@ See the License for the specific language governing permissions and limitations under the License. """ from __future__ import print_function + import subprocess import cmd import json @@ -67,20 +68,25 @@ class ConsoleLogger(LoggerApi): def set_window_always_on_top (title): # we need the GDK module, if not available - ignroe this command try: - import gtk.gdk + if sys.version_info < (3,0): + from gtk import gdk + else: + #from gi.repository import Gdk as gdk + return + except ImportError: return # search the window and set it as above - root = gtk.gdk.get_default_root_window() + root = gdk.get_default_root_window() for id in root.property_get('_NET_CLIENT_LIST')[2]: - w = gtk.gdk.window_foreign_new(id) + w = gdk.window_foreign_new(id) if w: name = w.property_get('WM_NAME')[2] if name == title: w.set_keep_above(True) - gtk.gdk.window_process_all_updates() + gdk.window_process_all_updates() break diff --git a/scripts/automation/trex_control_plane/stl/console/trex_tui.py b/scripts/automation/trex_control_plane/stl/console/trex_tui.py index bd1eca74..88c53d10 100644 --- a/scripts/automation/trex_control_plane/stl/console/trex_tui.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_tui.py @@ -409,7 +409,7 @@ class TrexTUI(): def handle_key_input (self): # try to read a single key - ch = os.read(sys.stdin.fileno(), 1) + ch = os.read(sys.stdin.fileno(), 1).decode() if ch != None and len(ch) > 0: return (self.pm.handle_key(ch), True) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py index 0f3cd65c..25e35423 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py @@ -826,9 +826,10 @@ class STLClient(object): # stats def _get_formatted_stats(self, port_id_list, stats_mask = trex_stl_stats.COMPACT): - stats_opts = trex_stl_stats.ALL_STATS_OPTS.intersection(stats_mask) - stats_obj = {} + stats_opts = common.list_intersect(trex_stl_stats.ALL_STATS_OPTS, stats_mask) + + stats_obj = OrderedDict() for stats_type in stats_opts: stats_obj.update(self.stats_generator.generate_single_statistic(port_id_list, stats_type)) @@ -2148,7 +2149,7 @@ class STLClient(object): # set to show all stats if no filter was given mask = trex_stl_stats.ALL_STATS_OPTS - stats_opts = trex_stl_stats.ALL_STATS_OPTS.intersection(mask) + stats_opts = common.list_intersect(trex_stl_stats.ALL_STATS_OPTS, mask) stats = self._get_formatted_stats(opts.ports, mask) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py index 64e8688f..18c49d4e 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py @@ -20,9 +20,9 @@ PORT_STATS = 'p' PORT_STATUS = 'ps' STREAMS_STATS = 's' -ALL_STATS_OPTS = {GLOBAL_STATS, PORT_STATS, PORT_STATUS, STREAMS_STATS} -COMPACT = {GLOBAL_STATS, PORT_STATS} -SS_COMPAT = {GLOBAL_STATS, STREAMS_STATS} +ALL_STATS_OPTS = [GLOBAL_STATS, PORT_STATS, PORT_STATUS, STREAMS_STATS] +COMPACT = [GLOBAL_STATS, PORT_STATS] +SS_COMPAT = [GLOBAL_STATS, STREAMS_STATS] ExportableStats = namedtuple('ExportableStats', ['raw_data', 'text_table']) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py index 9490c1b0..ae74e932 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py @@ -54,3 +54,7 @@ def get_number(input): return int(input) except: return None + +def list_intersect(l1, l2): + return list(filter(lambda x: x in l2, l1)) + diff --git a/scripts/find_python.sh b/scripts/find_python.sh index aba2d936..929e873d 100755 --- a/scripts/find_python.sh +++ b/scripts/find_python.sh @@ -24,21 +24,12 @@ function find_python { exit -1 } -function find_python3 { - MACHINE_PYTHON=python3 - PYTHON3=$MACHINE_PYTHON - PCHECK=`$PYTHON3 -c "import sys; ver = sys.version_info[0] * 10 + sys.version_info[1];sys.exit(ver != 34)"` - if [ $? -eq 0 ]; then - return - fi - PYTHON3= - -} - if [ -z "$PYTHON" ]; then - find_python + # for development here - move us to python 3 for now + if [ "$USER" == "imarom" ] || [ "$USER" == "hhaim" ] || [ "$USER" == "ybrustin" ] || [ "$USER" == "ibarnea" ]; then + PYTHON=/auto/proj-pcube-b/apps/PL-b/tools/python3.4/bin/python3 + else + find_python + fi fi -if [ -z "$PYTHON3" ]; then - find_python3 -fi diff --git a/scripts/run_functional_tests b/scripts/run_functional_tests index 783d6346..995b1b0d 100755 --- a/scripts/run_functional_tests +++ b/scripts/run_functional_tests @@ -1,30 +1,27 @@ #!/bin/bash -source find_python.sh +#source find_python.sh cd automation/regression -if [ -z "$PYTHON" ]; then - echo "*** $PYTHON - python version is too old, 2.7 at least is required" -else - $PYTHON trex_unit_test.py --functional $@ - if [ $? -eq 0 ]; then - printf "\n$PYTHON test succeeded\n\n" - else - printf "\n*** $PYTHON test failed\n\n" - exit -1 - fi -fi +PYTHON=/usr/bin/python2 +PYTHON3=/auto/proj-pcube-b/apps/PL-b/tools/python3.4/bin/python3 -if [ -z "$PYTHON3" ]; then - echo "*** $PYTHON3 - python3 version required is 3.4 - skipping python3 test" +# Python 2 +$PYTHON trex_unit_test.py --functional $@ +if [ $? -eq 0 ]; then + printf "\n$PYTHON test succeeded\n\n" else - $PYTHON3 trex_unit_test.py --functional $@ - if [ $? -eq 0 ]; then - printf "\n$PYTHON3 test succeeded\n\n" - else - printf "\n*** $PYTHON3 test failed\n\n" - exit -1 - fi + printf "\n*** $PYTHON test failed\n\n" + exit -1 +fi +# Python 3 +$PYTHON3 trex_unit_test.py --functional $@ +if [ $? -eq 0 ]; then + printf "\n$PYTHON3 test succeeded\n\n" +else + printf "\n*** $PYTHON3 test failed\n\n" + exit -1 fi + diff --git a/scripts/trex-console b/scripts/trex-console index 58944237..ea253fdd 100755 --- a/scripts/trex-console +++ b/scripts/trex-console @@ -3,4 +3,7 @@ source find_python.sh export PYTHONPATH=automation/trex_control_plane/stl + +printf "\nUsing '$PYTHON' as Python interpeter\n\n" + $PYTHON -m console.trex_console $@ -- cgit 1.2.3-korg