moving us to python 3 by default (console)
authorimarom <[email protected]>
Wed, 23 Mar 2016 14:11:53 +0000 (16:11 +0200)
committerimarom <[email protected]>
Wed, 23 Mar 2016 14:11:53 +0000 (16:11 +0200)
scripts/automation/trex_control_plane/stl/console/trex_console.py
scripts/automation/trex_control_plane/stl/console/trex_tui.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py
scripts/find_python.sh
scripts/run_functional_tests
scripts/trex-console

index 2f6744c..8c71065 100755 (executable)
@@ -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
 
 
index bd1eca7..88c53d1 100644 (file)
@@ -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)
 
index 0f3cd65..25e3542 100644 (file)
@@ -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)
 
index 64e8688..18c49d4 100644 (file)
@@ -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'])
 
index 9490c1b..ae74e93 100644 (file)
@@ -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))
+
index aba2d93..929e873 100755 (executable)
@@ -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
index 783d634..995b1b0 100755 (executable)
@@ -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
 
+
index 5894423..ea253fd 100755 (executable)
@@ -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 $@