From 0c60abb8fb14e50b0e267163a8cc9b17a09007c4 Mon Sep 17 00:00:00 2001 From: Jed Reynolds Date: Wed, 2 Jun 2021 12:37:03 -0700 Subject: [PATCH] Reporting: now supports new artifacts and CSS styles: - CenturyGothic font - report.css and custom.css - start_content_div() for centered body content - end_content_div() to end body content - fixes lots of copy-paste html errors - changes excessive string concatenation to format() calls Signed-off-by: Jed Reynolds --- py-scripts/lf_report.py | 139 ++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 64 deletions(-) diff --git a/py-scripts/lf_report.py b/py-scripts/lf_report.py index a9d76de1..7da94204 100755 --- a/py-scripts/lf_report.py +++ b/py-scripts/lf_report.py @@ -25,9 +25,10 @@ LICENSE: INCLUDE_IN_README ''' +import datetime import os import shutil -import datetime + import pandas as pd import pdfkit @@ -50,7 +51,8 @@ class lf_report(): _results_dir_name = "LANforge_Test_Results", _output_format = 'html', # pass in on the write functionality, current not used _dataframe="", - _path_date_time=""): # this is where the final report is placed. + _path_date_time="", + _custom_css='custom-example.css'): # this is where the final report is placed. #other report paths, # _path is where the directory with the data time will be created @@ -89,13 +91,15 @@ class lf_report(): self.logo_directory = "artifacts" self.logo_file_name = "CandelaLogo2-90dpi-200x90-trans.png" # does this need to be configurable. self.current_path = os.path.dirname(os.path.abspath(__file__)) - + self.custom_css = _custom_css # pass in _date to allow to change after construction self.set_date_time_directory(_date,_results_dir_name) self.build_date_time_directory() + self.font_file = "CenturyGothic.woff" # move the banners and candela images to report path self.copy_banner() + self.copy_css() self.copy_logo() def copy_banner(self): @@ -103,21 +107,35 @@ class lf_report(): banner_dst_file = str(self.path_date_time)+'/'+ str(self.banner_file_name) #print("banner src_file: {}".format(banner_src_file)) #print("dst_file: {}".format(banner_dst_file)) - shutil.copy(banner_src_file,banner_dst_file) + shutil.copy(banner_src_file, banner_dst_file) + + def copy_css(self): + reportcss_src_file = str(self.current_path)+'/'+str(self.banner_directory)+'/report.css' + reportcss_dest_file = str(self.path_date_time)+'/report.css' + + customcss_src_file = str(self.current_path)+'/'+str(self.banner_directory)+'/'+str(self.custom_css) + customcss_dest_file = str(self.path_date_time)+'/custom.css' + + font_src_file = str(self.current_path)+'/'+str(self.banner_directory)+'/'+str(self.font_file) + font_dest_file = str(self.path_date_time)+'/'+str(self.font_file) + + shutil.copy(reportcss_src_file, reportcss_dest_file) + shutil.copy(customcss_src_file, customcss_dest_file) + shutil.copy(font_src_file, font_dest_file) def copy_logo(self): logo_src_file = str(self.current_path)+'/'+str(self.logo_directory)+'/'+str(self.logo_file_name) logo_dst_file = str(self.path_date_time)+'/'+ str(self.logo_file_name) #print("logo_src_file: {}".format(logo_src_file)) #print("logo_dst_file: {}".format(logo_dst_file)) - shutil.copy(logo_src_file,logo_dst_file) + shutil.copy(logo_src_file, logo_dst_file) def move_graph_image(self,): graph_src_file = str(self.graph_image) graph_dst_file = str(self.path_date_time)+'/'+ str(self.graph_image) print("graph_src_file: {}".format(graph_src_file)) print("graph_dst_file: {}".format(graph_dst_file)) - shutil.move(graph_src_file,graph_dst_file) + shutil.move(graph_src_file, graph_dst_file) def set_path(self,_path): self.path = _path @@ -248,60 +266,54 @@ class lf_report(): def build_all(self): self.build_banner() + self.start_content_div() self.build_table_title() self.build_table() + self.end_content_div() def build_banner(self): - self.banner_html = """ - - - - - -
- - - BANNER - -
-
- - -
-
-

""" + str(self.title) + """

-

""" + str(self.date) + """

-
-
-
-
-
-
- """ + # NOTE: {{ }} are the ESCAPED curly braces + self.banner_html = """ + + + + + + + + {title} + + + +""".format( + title=self.title, + date=self.date, + ) self.html += self.banner_html def build_table_title(self): - self.table_title_html = """ - - - - -
-

""" + str(self.table_title) + """

- """ + self.table_title_html = "

{title}

".format(title=self.table_title) self.html += self.table_title_html - def build_text(self): - self.text_html = """ - - - - -
-

""" + str(self.text) + """

- """ - self.html += self.text_html + def start_content_div(self): + self.html += "\n
\n" + def build_text(self): + # please do not use 'style=' tags unless you cannot override a class + self.text_html = """ +
+

{text}

\n +
""".format(text=self.text) + self.html += self.text_html def build_date_time(self): self.date_time = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%m-m-%S-s")).replace(':','-') @@ -325,30 +337,29 @@ class lf_report(): def build_objective(self): self.obj_html = """ - -

""" + str(self.obj_title) + """

-

""" + str(self.objective) + """

- """ + +

{title}

+

{objective}

+ """.format(title=self.obj_title, + objective=self.objective) self.html += self.obj_html def build_graph_title(self): self.table_graph_html = """ - - - - -
-

""" + str(self.graph_title) + """

- """ +
+

{title}

+ """.format(title=self.graph_title) self.html += self.table_graph_html def build_graph(self): self.graph_html_obj = """ - -

- """ + + """.format(image=self.graph_image) self.html +=self.graph_html_obj + def end_content_div(self): + self.html += "\n
\n" + # Unit Test if __name__ == "__main__":