From 85bc685df453ebe0c27a54e18e51e87f0c7aa4fb Mon Sep 17 00:00:00 2001 From: Chuck SmileyRekiere Date: Fri, 14 May 2021 11:14:34 -0600 Subject: [PATCH] lf_report.py : added selectable timestamd to html and pdf output, lf_check.py : formatting output --- py-scripts/lf_report.py | 28 +++++++++++++++++++++++++++- py-scripts/sandbox/lf_check.py | 11 +++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/py-scripts/lf_report.py b/py-scripts/lf_report.py index 0c6b6c85..c656c288 100755 --- a/py-scripts/lf_report.py +++ b/py-scripts/lf_report.py @@ -197,6 +197,18 @@ class lf_report(): print("write_html failed") return self.write_output_html + def write_html_with_timestamp(self): + self.write_output_html = "{}/{}-{}".format(self.path_date_time,self.date,self.output_html) + print("write_output_html: {}".format(self.write_output_html)) + try: + test_file = open(self.write_output_html, "w") + test_file.write(self.html) + test_file.close() + except: + print("write_html failed") + return self.write_output_html + + # https://wkhtmltopdf.org/usage/wkhtmltopdf.txt # page_size A4, A3, Letter, Legal # orientation Portrait , Landscape @@ -210,7 +222,21 @@ class lf_report(): 'page-size': _page_size} # prevent error Blocked access to file self.write_output_pdf = str(self.path_date_time)+'/'+ str(self.output_pdf) pdfkit.from_file(self.write_output_html, self.write_output_pdf, options=options) - pass + + # https://wkhtmltopdf.org/usage/wkhtmltopdf.txt + # page_size A4, A3, Letter, Legal + # orientation Portrait , Landscape + def write_pdf_with_timestamp(self, _page_size = 'A4', _orientation = 'Portrait'): + # write logic to generate pdf here + # wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb + # sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb + + options = {"enable-local-file-access" : None, + 'orientation': _orientation, + 'page-size': _page_size} # prevent error Blocked access to file + self.write_output_pdf = "{}/{}-{}".format(self.path_date_time,self.date,self.output_pdf) + pdfkit.from_file(self.write_output_html, self.write_output_pdf, options=options) + def generate_report(self): self.write_html() diff --git a/py-scripts/sandbox/lf_check.py b/py-scripts/sandbox/lf_check.py index 6814f680..d99067a6 100755 --- a/py-scripts/sandbox/lf_check.py +++ b/py-scripts/sandbox/lf_check.py @@ -217,8 +217,11 @@ class lf_check(): self.html_results += """ """ + str(test) + """""" + str(command) + """ """ + str(self.test_result) + """ - STDOUT - STDERR""" + STDOUT""" + if self.test_result == "Failure": + self.html_results += """STDERR""" + else: + self.html_results += """""" row = [test,command,self.test_result,stdout_log_txt,stderr_log_txt] print("row: {}".format(row)) @@ -280,12 +283,12 @@ for running scripts listed in lf_check_config.ini report.build_banner() report.set_table_title("LF Check Test Results") report.build_table_title() - # custom html (maybe try different) html_results = check.get_html_results() #print("html_results {}".format(html_results)) report.set_custom_html(html_results) report.build_custom() - report.write_html() + report.write_html_with_timestamp() + report.write_pdf_with_timestamp()