From 882bc200c58a18a1eabd7b5db6c0ee7e6e5068f1 Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 17 Apr 2016 14:30:58 +0300 Subject: TUI might crash - do not include unicode chars if stdout encoding is not 'UTF-8' also, some fixes for the TUI port screen --- scripts/automation/trex_control_plane/stl/console/trex_tui.py | 11 ++++++++--- .../trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py | 11 ++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) 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 effcf55e..cbaae392 100644 --- a/scripts/automation/trex_control_plane/stl/console/trex_tui.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_tui.py @@ -73,7 +73,10 @@ class TrexTUIDashBoard(TrexTUIPanel): self.key_actions['o'] = {'action': self.action_show_owned, 'legend': 'owned ports', 'show': True} self.key_actions['a'] = {'action': self.action_show_all, 'legend': 'all ports', 'show': True} - self.ports_filter = self.FILTER_ALL + if self.stateless_client.get_acquired_ports(): + self.ports_filter = self.FILTER_ACQUIRED + else: + self.ports_filter = self.FILTER_ALL def get_ports (self): @@ -99,7 +102,7 @@ class TrexTUIDashBoard(TrexTUIPanel): allowed['o'] = self.key_actions['o'] allowed['a'] = self.key_actions['a'] - if self.ports_filter == self.FILTER_ALL: + if self.ports_filter == self.FILTER_ALL and self.stateless_client.get_acquired_ports() != self.stateless_client.get_all_ports(): return allowed if len(self.stateless_client.get_transmitting_ports()) > 0: @@ -201,7 +204,7 @@ class TrexTUIPort(TrexTUIPanel): allowed['c'] = self.key_actions['c'] allowed['t'] = self.key_actions['t'] - if self.stateless_client.is_all_ports_acquired(): + if self.port_id not in self.stateless_client.get_acquired_ports(): return allowed if self.port.state == self.port.STATE_TX: @@ -535,7 +538,9 @@ class TrexTUI(): sys.stdout = old_stdout self.clear_screen() + print(mystdout.getvalue()) + sys.stdout.flush() self.draw_policer = 0 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 6b1185ef..4057c50d 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 @@ -201,6 +201,10 @@ class CTRexInfoGenerator(object): def _get_rational_block_char(value, range_start, interval): # in Konsole, utf-8 is sometimes printed with artifacts, return ascii for now #return 'X' if value >= range_start + float(interval) / 2 else ' ' + + if sys.__stdout__.encoding != 'UTF-8': + return 'X' if value >= range_start + float(interval) / 2 else ' ' + value -= range_start ratio = float(value) / interval if ratio <= 0.0625: @@ -532,7 +536,12 @@ class CTRexStats(object): v = self.get_trend(field, use_raw) value = abs(v) - arrow = u'\u25b2' if v > 0 else u'\u25bc' + + # use arrows if utf-8 is supported + if sys.__stdout__.encoding == 'UTF-8': + arrow = u'\u25b2' if v > 0 else u'\u25bc' + else: + arrow = '' if sys.version_info < (3,0): arrow = arrow.encode('utf-8') -- cgit 1.2.3-korg