[Fuego] [PATCH 1/3] ftc: gen-report: Add pdf formatter

Tim.Bird at sony.com Tim.Bird at sony.com
Thu Mar 8 18:32:24 UTC 2018


Comments inline below.

> -----Original Message-----
> From: fuego-bounces at lists.linuxfoundation.org [mailto:fuego-
> bounces at lists.linuxfoundation.org] On Behalf Of Hoang Van Tuyen
> Sent: Wednesday, March 07, 2018 6:48 PM
> To: Bird, Timothy <Tim.Bird at sony.com>; fuego at lists.linuxfoundation.org
> Subject: Re: [Fuego] [PATCH 1/3] ftc: gen-report: Add pdf formatter
> 
> It has some difference between html and plain text format.
> 
> I re-send the patch as an attachment.
> 
> Best regards,
> 
> Tuyen
> 
> 
> On 3/8/2018 6:04 AM, Tim.Bird at sony.com wrote:
> > 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)

Eventually we'll want to be able to specify the report filename.  Using
the same one every time means it's subject to getting overwritten
every time we generate a report.  See below for more discussion about
a '-o' option.

> >> +    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/"

I prefer to use the default report_dir of '/fuego-rw/reports'
(with a trailing 's').  I changed the patch.  Let me know if you disagree.

It's nice to have the report show up in /fuego-rw, so they can
be seen from the host machine, and viewed and printed
without further fuss.

As a note, eventually we'd like to be able to specify the output
path on the ftc command line, using a '-o' option.  That would override
the report_dir setting here (as well as make it necessary to 
pass in the full final filename). 

I'm a little worried that the specification of output location is a bit
different for this format than for other formats.  This one writes
a file, and the others (txt and html) write to stdout.  We may have
to rationalize that later when we add the '-o' command line option
to 'ftc gen-report'.

This is good for now, thought.

> >> +        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

Applied.  Thanks.
 -- Tim


More information about the Fuego mailing list