From 876c76572fdb2fb8f0e8db21bc420d284dc05950 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Wed, 21 Oct 2015 03:14:26 +0300 Subject: Added support for path autocomletion for console methods :) --- .../trex_control_plane/console/trex_console.py | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'scripts/automation/trex_control_plane') diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index 27a5eeab..a9ac040b 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -23,7 +23,7 @@ import ast import argparse import random import string - +import os import sys import tty, termios import trex_root_path @@ -457,6 +457,26 @@ class TrexConsole(cmd.Cmd): print "please provide load name and YAML path, separated by space.\n" \ "Optionally, you may provide a third argument to specify multiplier." + @staticmethod + def tree_autocomplete(text): + dir = os.path.dirname(text) + if dir: + path = dir + else: + path = "." + start_string = os.path.basename(text) + return [x + for x in os.listdir(path) + if x.startswith(start_string)] + + + def complete_load_stream_list(self, text, line, begidx, endidx): + arg_num = len(line.split()) - 1 + if arg_num == 2: + return TrexConsole.tree_autocomplete(line.split()[-1]) + else: + return [text] + def do_show_stream_list(self, line): '''Shows the loaded stream list named [name] \n''' args = line.split() @@ -474,7 +494,7 @@ class TrexConsole(cmd.Cmd): print "\nAvailable stream lists:\n{0}".format(', '.join([x for x in self.user_streams.keys()])) - def complete_show_stream_list (self, text, line, begidx, endidx): + def complete_show_stream_list(self, text, line, begidx, endidx): return [x for x in self.user_streams.keys() if x.startswith(text)] -- cgit