[Fuego] [PATCH 1/3] ftc: gen-report: Add pdf formatter
Tim.Bird at sony.com
Tim.Bird at sony.com
Wed Mar 7 23:04:14 UTC 2018
This patch also has wrapping issues.
-- Tim
> -----Original Message-----
> From: fuego-bounces at lists.linuxfoundation.org [mailto:fuego-
> bounces at lists.linuxfoundation.org] On Behalf Of Hoang Van Tuyen
> Sent: Thursday, March 01, 2018 7:36 PM
> To: fuego at lists.linuxfoundation.org
> Subject: [Fuego] [PATCH 1/3] ftc: gen-report: Add pdf formatter
>
> Add a formatter for pdf report output. By default, the pdf
> output file is stored in /fuego-rw/report with name report.pdf.
>
> It uses a reportlab python library for generating the report,
> So, please make sure that the library is available in the system.
>
> 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 c6a0f3d..0b99f94 100755
> --- a/engine/scripts/ftc
> +++ b/engine/scripts/ftc
> @@ -2037,6 +2037,46 @@ def gen_html_report(header_data, report_data):
>
> return report
>
> +# add page number for a pdf file
> +def add_page_number(canvas, doc):
> + from reportlab.lib.units import mm
> +
> + page_num = canvas.getPageNumber()
> + text = "Page %s" % page_num
> + canvas.drawRightString(200*mm, 20*mm, text)
> +
> +def gen_pdf_report(header_data, report_data, report_dir):
> + from reportlab.lib import colors
> + from reportlab.lib.pagesizes import A4
> + from reportlab.lib.styles import getSampleStyleSheet
> + from reportlab.platypus import SimpleDocTemplate, Table,
> TableStyle, Paragraph
> +
> + # create a pdf file
> + doc = SimpleDocTemplate(report_dir + "report.pdf", pagesize=A4)
> + elements = []
> +
> + # generate header
> + styles = getSampleStyleSheet()
> + elements.append(Paragraph("Fuego Test Report\n", styles["Heading1"]))
> + for field,val_str in header_data:
> + elements.append(Paragraph("%s: %s\n" % (field, val_str),
> styles["Normal"]))
> +
> + # generate lines for this report
> + fields = report_data[0]
> +
> + # create the table with a header row in each page
> + report_data = [[Paragraph(str(cell), styles["Normal"]) for cell in
> row] for row in report_data]
> + table = Table(report_data, repeatRows=1, colWidths=[75,75])
> +
> + # format for table in the report file
> + table.setStyle(TableStyle([("INNERGRID", (0, 0), (-1, -1), 0.25,
> colors.black),
> + ("BOX", (0, 0), (-1, -1), 0.25,
> colors.black),
> + ("BACKGROUND",(0, 0), (len(fields) -
> 1,0), colors.silver),
> + ("VALIGN",(0, 0), (-1, -1), "MIDDLE")]))
> +
> + elements.append(table)
> + doc.build(elements, onFirstPage=add_page_number,
> onLaterPages=add_page_number)
> +
> # generate a report from run results
> def do_gen_report(conf, options):
> global quiet, verbose
> @@ -2058,7 +2098,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"]:
> + if fmt not in ["txt","html","pdf"]:
> error_out("Unsupported format '%s' specified" % fmt)
>
> if "--layout" in options:
> @@ -2073,6 +2113,11 @@ def do_gen_report(conf, options):
> #fields = ["test_name", "spec", "board", "timestamp", "tguid",
> "status"]
> #rfields = ["test_name", "spec", "board", "timestamp",
> "tguid", "tguid:measure", "tguid:unit", "tguid:status", "tguid:result"]
>
> + # create a directory to save report files
> + report_dir = "/fuego-rw/report/"
> + if not os.path.exists(report_dir):
> + os.makedirs(report_dir)
> +
> # get data for report
> header_data = get_report_header_data(run_list, run_map,
> header_fields)
> report_data = get_report_data(run_list, run_map, fields)
> @@ -2081,6 +2126,9 @@ def do_gen_report(conf, options):
> report = gen_text_report(header_data, report_data)
> if fmt=="html":
> report = gen_html_report(header_data, report_data)
> + if fmt=="pdf":
> + gen_pdf_report(header_data, report_data, report_dir)
> + sys.exit(0)
>
> print report
>
> --
> 2.1.4
>
>
> --
> ==========================================================
> ======
> Hoang Van Tuyen (Mr.)
> TOSHIBA SOFTWARE DEVELOPMENT (VIETNAM) CO., LTD.
> 16th Floor, VIT Building, 519 Kim Ma Str., Ba Dinh Dist., Hanoi, Vietnam
> Tel: 84-4-22208801 (Company) - Ext.251
> Fax: 84-4-22208802 (Company)
> Email: tuyen.hoangvan at toshiba-tsdv.com
> ==========================================================
> ======
>
>
> --
> This mail was scanned by BitDefender
> For more information please visit http://www.bitdefender.com
>
> _______________________________________________
> Fuego mailing list
> Fuego at lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/fuego
More information about the Fuego
mailing list