summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/common/text_opts.py
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-01-12 08:01:27 -0500
committerimarom <imarom@cisco.com>2016-01-12 08:04:12 -0500
commit7ce793d732d7692a60672db7f9e4f1bac9cad81e (patch)
tree640054df4d97d41725df3c4a54094b0561479fbe /scripts/automation/trex_control_plane/common/text_opts.py
parent0f49e42f202491f7d8e23be237f9c94f136fe384 (diff)
some modifactions to the TUI
few things were fixed
Diffstat (limited to 'scripts/automation/trex_control_plane/common/text_opts.py')
-rwxr-xr-xscripts/automation/trex_control_plane/common/text_opts.py42
1 files changed, 36 insertions, 6 deletions
diff --git a/scripts/automation/trex_control_plane/common/text_opts.py b/scripts/automation/trex_control_plane/common/text_opts.py
index 29fbd69b..30d38d3f 100755
--- a/scripts/automation/trex_control_plane/common/text_opts.py
+++ b/scripts/automation/trex_control_plane/common/text_opts.py
@@ -18,14 +18,42 @@ TEXT_CODES = {'bold': {'start': '\x1b[1m',
'underline': {'start': '\x1b[4m',
'end': '\x1b[24m'}}
+class TextCodesStripper:
+ keys = [re.escape(v['start']) for k,v in TEXT_CODES.iteritems()]
+ keys += [re.escape(v['end']) for k,v in TEXT_CODES.iteritems()]
+ pattern = re.compile("|".join(keys))
+
+ @staticmethod
+ def strip (s):
+ return re.sub(TextCodesStripper.pattern, '', s)
+
+def format_num (size, suffix = "", compact = True, opts = ()):
+ txt = "NaN"
+
+ if type(size) == str:
+ return "N/A"
+
+ u = ''
+
+ if compact:
+ for unit in ['','K','M','G','T','P']:
+ if abs(size) < 1000.0:
+ #txt = "%3.2f %s%s" % (size, unit, suffix)
+ u = unit
+ break
+ size /= 1000.0
+
+ if isinstance(size, float):
+ txt = "%3.2f %s%s" % (size, u, suffix)
+ else:
+ txt = "{:,} {:}{:}".format(size, u, suffix)
+
+ if isinstance(opts, tuple):
+ return format_text(txt, *opts)
+ else:
+ return format_text(txt, (opts))
-def format_num (size, suffix = ""):
- for unit in ['','K','M','G','T','P']:
- if abs(size) < 1000.0:
- return "%3.2f %s%s" % (size, unit, suffix)
- size /= 1000.0
- return "NaN"
def format_time (t_sec):
if t_sec < 0:
@@ -122,8 +150,10 @@ def format_text(text, *args):
func = FUNC_DICT.get(i)
if func:
return_string = func(return_string)
+
return return_string
+
def format_threshold (value, red_zone, green_zone):
if value >= red_zone[0] and value <= red_zone[1]:
return format_text("{0}".format(value), 'red')