summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py')
-rw-r--r--scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py35
1 files changed, 32 insertions, 3 deletions
diff --git a/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py b/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py
index 89ac9127..c6b22218 100644
--- a/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py
+++ b/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py
@@ -4,8 +4,20 @@ import outer_packages
import zmq
import json
import general_utils
+import re
from time import sleep
+class bcolors:
+ BLUE = '\033[94m'
+ GREEN = '\033[32m'
+ YELLOW = '\033[93m'
+ RED = '\033[31m'
+ MAGENTA = '\033[35m'
+ ENDC = '\033[0m'
+ BOLD = '\033[1m'
+ UNDERLINE = '\033[4m'
+
+
class JsonRpcClient(object):
def __init__ (self, default_server, default_port):
@@ -24,8 +36,25 @@ class JsonRpcClient(object):
return rc
- def pretty_json (self, json_str):
- return json.dumps(json.loads(json_str), indent = 4, separators=(',', ': '), sort_keys = True)
+ def pretty_json (self, json_str, use_colors = True):
+ pretty_str = json.dumps(json.loads(json_str), indent = 4, separators=(',', ': '), sort_keys = True)
+
+ if not use_colors:
+ return pretty_str
+
+ try:
+ # int numbers
+ pretty_str = re.sub(r'([ ]*:[ ]+)(\-?[1-9][0-9]*[^.])',r'\1{0}\2{1}'.format(bcolors.BLUE, bcolors.ENDC), pretty_str)
+ # float
+ pretty_str = re.sub(r'([ ]*:[ ]+)(\-?[1-9][0-9]*\.[0-9]+)',r'\1{0}\2{1}'.format(bcolors.MAGENTA, bcolors.ENDC), pretty_str)
+ # strings
+
+ pretty_str = re.sub(r'([ ]*:[ ]+)("[^"]*")',r'\1{0}\2{1}'.format(bcolors.RED, bcolors.ENDC), pretty_str)
+ pretty_str = re.sub(r"('[^']*')", r'{0}\1{1}'.format(bcolors.MAGENTA, bcolors.RED), pretty_str)
+ except :
+ pass
+
+ return pretty_str
def verbose_msg (self, msg):
if not self.verbose:
@@ -115,7 +144,7 @@ class JsonRpcClient(object):
return self.invoke_rpc_method("get_status")
def query_rpc_server(self):
- return self.invoke_rpc_method("get_reg_cmds")
+ return self.invoke_rpc_method("get_supported_cmds")
def set_verbose(self, mode):