[Fuego] [PATCH 3/3] ftc: gen-report: Add support rst format

Hoang Van Tuyen tuyen.hoangvan at toshiba-tsdv.com
Tue Mar 13 10:16:11 UTC 2018


With ReStructureText format, We can convert the report to another
format easily. Use option --format rst

Signed-off-by: Hoang Van Tuyen <tuyen.hoangvan at toshiba-tsdv.com>
---
  engine/scripts/ftc | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/engine/scripts/ftc b/engine/scripts/ftc
index c1a2887..6b88cc7 100755
--- a/engine/scripts/ftc
+++ b/engine/scripts/ftc
@@ -2177,6 +2177,52 @@ def gen_csv_report(header_data, report_data, 
report_file):
      # generate lines for this report
          writer.writerows(report_data)

+# create a rst table
+def make_table(grid):
+    # adjust column width size
+    max_cols = [max(out) for out in map(list, zip(*[[len(str(item)) for 
item in row] for row in grid]))]
+    rst = table_div(max_cols, 1)
+
+    for i, row in enumerate(grid):
+        header_flag = 0
+        if i == 0 or i == len(grid)-1: header_flag = 1
+        rst += normalize_row(row,max_cols)
+        rst += table_div(max_cols, header_flag )
+    return rst
+
+def table_div(max_cols, header_flag=1):
+    out = ""
+    if header_flag == 1:
+        style = "="
+    else:
+        style = "-"
+
+    for max_col in max_cols:
+        out += max_col * style + " "
+
+    return out + "\n"
+
+def normalize_row(row, max_cols):
+    r = ""
+    for i, max_col in enumerate(max_cols):
+        r += str(row[i]) + (max_col - len(str(row[i])) + 1) * " "
+    return r + "\n"
+
+def gen_rst_report(header_data, report_data):
+    # generate header
+    title = "Fuego Test Report"
+    title_len = len(title)
+    report = title + "\n"
+    report += table_div([title_len], 1)
+
+    for field,val_str in header_data:
+        report += ":%s: %s\n" % (field, val_str)
+    report += "\n"
+
+    # generate lines for this report
+    report += make_table(report_data)
+    return report
+
  # generate a report from run results
  def do_gen_report(conf, options):
      global quiet, verbose
@@ -2198,7 +2244,7 @@ def do_gen_report(conf, options):
      fmt="txt"
      if "--format" in options:
          fmt = options[options.index("--format")+1]
-        if fmt not in ["txt","html","pdf","excel","csv"]:
+        if fmt not in ["txt","html","pdf","excel","csv","rst"]:
              error_out("Unsupported format '%s' specified" % fmt)

      if "--layout" in options:
@@ -2267,6 +2313,8 @@ def do_gen_report(conf, options):
      if fmt=="csv":
          gen_csv_report(header_data, report_data, report_file)
          sys.exit(0)
+    if fmt=="rst":
+        report = gen_rst_report(header_data, report_data)

      print report

-- 
2.1.4

_______________________________________________
Fuego mailing list
Fuego at lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/fuego

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfoundation.org/pipermail/fuego/attachments/20180313/8a5c15a0/attachment-0001.html>
-------------- next part --------------
From 11844084fc15eff69584bc9103c57a8dac448eac Mon Sep 17 00:00:00 2001
From: Hoang Van Tuyen <tuyen.hoangvan at toshiba-tsdv.com>
Date: Tue, 13 Mar 2018 17:08:18 +0700
Subject: [PATCH 3/3] ftc: gen-report: Add support rst format

With ReStructureText format, We can convert the report to another
format easily. Use option --format rst

Signed-off-by: Hoang Van Tuyen <tuyen.hoangvan at toshiba-tsdv.com>
---
 engine/scripts/ftc | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/engine/scripts/ftc b/engine/scripts/ftc
index c1a2887..6b88cc7 100755
--- a/engine/scripts/ftc
+++ b/engine/scripts/ftc
@@ -2177,6 +2177,52 @@ def gen_csv_report(header_data, report_data, report_file):
     # generate lines for this report
         writer.writerows(report_data)
 
+# create a rst table
+def make_table(grid):
+    # adjust column width size
+    max_cols = [max(out) for out in map(list, zip(*[[len(str(item)) for item in row] for row in grid]))]
+    rst = table_div(max_cols, 1)
+
+    for i, row in enumerate(grid):
+        header_flag = 0
+        if i == 0 or i == len(grid)-1: header_flag = 1
+        rst += normalize_row(row,max_cols)
+        rst += table_div(max_cols, header_flag )
+    return rst
+
+def table_div(max_cols, header_flag=1):
+    out = ""
+    if header_flag == 1:
+        style = "="
+    else:
+        style = "-"
+
+    for max_col in max_cols:
+        out += max_col * style + " "
+
+    return out + "\n"
+
+def normalize_row(row, max_cols):
+    r = ""
+    for i, max_col in enumerate(max_cols):
+        r += str(row[i]) + (max_col - len(str(row[i])) + 1) * " "
+    return r + "\n"
+
+def gen_rst_report(header_data, report_data):
+    # generate header
+    title = "Fuego Test Report"
+    title_len = len(title)
+    report = title + "\n"
+    report += table_div([title_len], 1)
+
+    for field,val_str in header_data:
+        report += ":%s: %s\n" % (field, val_str)
+    report += "\n"
+
+    # generate lines for this report
+    report += make_table(report_data)
+    return report
+
 # generate a report from run results
 def do_gen_report(conf, options):
     global quiet, verbose
@@ -2198,7 +2244,7 @@ def do_gen_report(conf, options):
     fmt="txt"
     if "--format" in options:
         fmt = options[options.index("--format")+1]
-        if fmt not in ["txt","html","pdf","excel","csv"]:
+        if fmt not in ["txt","html","pdf","excel","csv","rst"]:
             error_out("Unsupported format '%s' specified" % fmt)
 
     if "--layout" in options:
@@ -2267,6 +2313,8 @@ def do_gen_report(conf, options):
     if fmt=="csv":
         gen_csv_report(header_data, report_data, report_file)
         sys.exit(0)
+    if fmt=="rst":
+        report = gen_rst_report(header_data, report_data)
 
     print report
 
-- 
2.1.4
-------------- next part --------------
-- 
This mail was scanned by BitDefender
For more information please visit http://www.bitdefender.com


More information about the Fuego mailing list