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

Tim.Bird at sony.com Tim.Bird at sony.com
Tue Mar 20 22:14:56 UTC 2018


Thanks very much.  Looks good.  Applied.
 -- Tim

> -----Original Message-----
> From: fuego-bounces at lists.linuxfoundation.org [mailto:fuego-
> bounces at lists.linuxfoundation.org] On Behalf Of Hoang Van Tuyen
> Sent: Tuesday, March 13, 2018 3:16 AM
> To: fuego at lists.linuxfoundation.org
> Subject: [Fuego] [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>
> <mailto: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 <mailto:Fuego at lists.linuxfoundation.org>
> https://lists.linuxfoundation.org/mailman/listinfo/fuego


More information about the Fuego mailing list