summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/console
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-07-25 11:20:16 +0300
committerimarom <imarom@cisco.com>2016-07-25 11:20:16 +0300
commita913ed85424bd1ab38c8842dd16dd10b90db12fe (patch)
tree6e11a631fe062fa574b4c083b79691c522f85c51 /scripts/automation/trex_control_plane/stl/console
parenteab24156c82eb6d6bdef434ef48ae7287e486f6b (diff)
TUI tweaks
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/console')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/console/trex_console.py43
-rw-r--r--scripts/automation/trex_control_plane/stl/console/trex_tui.py50
2 files changed, 53 insertions, 40 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 9e3f2600..41a04617 100755
--- a/scripts/automation/trex_control_plane/stl/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py
@@ -241,20 +241,7 @@ class TRexConsole(TRexGeneralCmd):
def postcmd(self, stop, line):
-
- if not self.stateless_client.is_connected():
- self.prompt = "trex(offline)>"
- self.supported_rpc = None
-
- elif not self.stateless_client.get_acquired_ports():
- self.prompt = "trex(read-only)>"
-
- elif self.stateless_client.is_all_ports_acquired():
- self.prompt = "trex>"
-
- else:
- self.prompt = "trex {0}>".format(self.stateless_client.get_acquired_ports())
-
+ self.prompt = self.stateless_client.generate_prompt(prefix = 'trex')
return stop
@@ -316,25 +303,21 @@ class TRexConsole(TRexGeneralCmd):
self.do_history("-h")
def do_shell (self, line):
- return self.do_history(line)
+ self.do_history(line)
def do_push (self, line):
'''Push a local PCAP file\n'''
- return self.stateless_client.push_line(line)
-
- #def do_push_remote (self, line):
- # '''Push a remote accessible PCAP file\n'''
- # return self.stateless_client.push_remote_line(line)
+ self.stateless_client.push_line(line)
def help_push (self):
- return self.do_push("-h")
+ self.do_push("-h")
def do_portattr (self, line):
'''Change/show port(s) attributes\n'''
- return self.stateless_client.set_port_attr_line(line)
+ self.stateless_client.set_port_attr_line(line)
def help_portattr (self):
- return self.do_portattr("-h")
+ self.do_portattr("-h")
@verify_connected
def do_map (self, line):
@@ -548,7 +531,7 @@ class TRexConsole(TRexGeneralCmd):
def do_events (self, line):
'''shows events recieved from server\n'''
- return self.stateless_client.get_events_line(line)
+ self.stateless_client.get_events_line(line)
def complete_profile(self, text, line, begidx, endidx):
@@ -562,7 +545,6 @@ class TRexConsole(TRexGeneralCmd):
@verify_connected
def do_tui (self, line):
'''Shows a graphical console\n'''
-
parser = parsing_opts.gen_parser(self,
"tui",
self.do_tui.__doc__,
@@ -581,16 +563,19 @@ class TRexConsole(TRexGeneralCmd):
info = self.stateless_client.get_connection_info()
exe = './trex-console --top -t -q -s {0} -p {1} --async_port {2}'.format(info['server'], info['sync_port'], info['async_port'])
- cmd = ['/usr/bin/xterm', '-geometry', '111x49', '-sl', '0', '-title', 'trex_tui', '-e', exe]
+ cmd = ['/usr/bin/xterm', '-geometry', '{0}x{1}'.format(self.tui.MIN_COLS, self.tui.MIN_ROWS), '-sl', '0', '-title', 'trex_tui', '-e', exe]
# detach child
self.terminal = subprocess.Popen(cmd, preexec_fn = os.setpgrp)
return
-
- with self.stateless_client.logger.supress():
- self.tui.show(self.stateless_client, locked = opts.locked)
+
+ try:
+ with self.stateless_client.logger.supress():
+ self.tui.show(self.stateless_client, locked = opts.locked)
+ except self.tui.ScreenSizeException as e:
+ print(format_text(str(e) + "\n", 'bold'))
def help_tui (self):
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 385cd098..2e26fdfc 100644
--- a/scripts/automation/trex_control_plane/stl/console/trex_tui.py
+++ b/scripts/automation/trex_control_plane/stl/console/trex_tui.py
@@ -5,6 +5,7 @@ import time
from collections import OrderedDict, deque
import datetime
import readline
+from texttable import ansi_len
if sys.version_info > (3,0):
from io import StringIO
@@ -449,6 +450,17 @@ class TrexTUI():
STATE_RECONNECT = 2
is_graph = False
+ MIN_ROWS = 50
+ MIN_COLS = 111
+
+ class ScreenSizeException(Exception):
+ def __init__ (self, cols, rows):
+ msg = "TUI requires console screen size of at least {0}x{1}, current is {2}x{3}".format(TrexTUI.MIN_COLS,
+ TrexTUI.MIN_ROWS,
+ cols,
+ rows)
+ super(TrexTUI.ScreenSizeException, self).__init__(msg)
+
def __init__ (self, stateless_client):
self.stateless_client = stateless_client
@@ -472,6 +484,11 @@ class TrexTUI():
def show (self, client, show_log = False, locked = False):
+
+ rows, cols = os.popen('stty size', 'r').read().split()
+ if (int(rows) < TrexTUI.MIN_ROWS) or (int(cols) < TrexTUI.MIN_COLS):
+ raise self.ScreenSizeException(rows = rows, cols = cols)
+
with AsyncKeys(client, locked) as async_keys:
sys.stdout.write("\x1bc")
self.async_keys = async_keys
@@ -691,16 +708,22 @@ class AsyncKeysEngineConsole:
self.async = async
self.lines = deque(maxlen = 100)
- self.ac = {'start' : client.start_line,
- 'stop' : client.stop_line,
- 'pause' : client.pause_line,
- 'resume': client.resume_line,
- 'update': client.update_line,
- 'quit' : self.action_quit,
- 'q' : self.action_quit,
- 'exit' : self.action_quit,
- 'help' : self.action_help,
- '?' : self.action_help}
+ self.generate_prompt = client.generate_prompt
+
+ self.ac = {'start' : client.start_line,
+ 'stop' : client.stop_line,
+ 'pause' : client.pause_line,
+ 'resume' : client.resume_line,
+ 'update' : client.update_line,
+ 'connect' : client.connect_line,
+ 'disconnect' : client.disconnect_line,
+ 'acquire' : client.acquire_line,
+ 'release' : client.release_line,
+ 'quit' : self.action_quit,
+ 'q' : self.action_quit,
+ 'exit' : self.action_quit,
+ 'help' : self.action_help,
+ '?' : self.action_help}
# fetch readline history and add relevants
for i in range(0, readline.get_current_history_length()):
@@ -916,6 +939,7 @@ class AsyncKeysEngineConsole:
line.invalidate()
assert(self.lines[0].modified == False)
+ color = None
if not func:
self.last_status = "unknown command: '{0}'".format(format_text(cmd.split()[0], 'bold'))
else:
@@ -923,12 +947,16 @@ class AsyncKeysEngineConsole:
self.last_status = func_rc
else:
self.last_status = format_text("[OK]", 'green') if func_rc else format_text(str(func_rc).replace('\n', ''), 'red')
+ color = 'red'
+ # trim too long lines
+ if ansi_len(self.last_status) > 100:
+ self.last_status = format_text(self.last_status[:100] + "...", color, 'bold')
def draw (self):
sys.stdout.write("\nPress 'ESC' for navigation panel...\n")
sys.stdout.write("status: \x1b[0K{0}\n".format(self.last_status))
- sys.stdout.write("\ntui>\x1b[0K")
+ sys.stdout.write("\n{0}\x1b[0K".format(self.generate_prompt(prefix = 'tui')))
self.lines[self.line_index].draw()