From 0da4aabf7dc3fda9e389b90084470764f8351570 Mon Sep 17 00:00:00 2001 From: Jed Reynolds Date: Thu, 26 Aug 2021 14:28:21 -0700 Subject: [PATCH] lf_report.py: many html corrections, adds javascript functions - There was significant copy-paste garbage from method to method that had useless [html] tags in it. - Footer is actually a legal html element, it doesn't need to be a div - removed suprious and inconsistent spaces - refactored [head] elements - adds notes about how these methods could better be named - copy_js method can be provided to allow clicking on elements to copy text to clipboard - reduces heavy indentation, report html looks better in view-source Signed-off-by: Jed Reynolds --- py-scripts/lf_report.py | 192 +++++++++++++++++++++------------------- 1 file changed, 103 insertions(+), 89 deletions(-) diff --git a/py-scripts/lf_report.py b/py-scripts/lf_report.py index 7342e67a..182c2efa 100755 --- a/py-scripts/lf_report.py +++ b/py-scripts/lf_report.py @@ -119,6 +119,7 @@ class lf_report(): def copy_css(self): reportcss_src_file = str(self.current_path)+'/'+str(self.banner_directory)+'/report.css' + # print("copy_css: source file is: "+reportcss_src_file) 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) @@ -309,7 +310,7 @@ class lf_report(): pdfkit.from_file(self.write_output_html, self.write_output_pdf, options=options) def get_pdf_path(self): - pdf_link_path = "{}/{}-{}".format(self.path_date_time,self.date,self.output_pdf) + pdf_link_path = "{}/{}-{}".format(self.path_date_time, self.date, self.output_pdf) return pdf_link_path def build_pdf_link(self,_pdf_link_name,_pdf_link_path): @@ -317,13 +318,13 @@ class lf_report(): {pdf_link_name}
- """.format(pdf_link_path=_pdf_link_path,pdf_link_name=_pdf_link_name) + """.format(pdf_link_path=_pdf_link_path,pdf_link_name=_pdf_link_name) self.html += self.pdf_link_html def build_link(self,_link_name,_link_path): self.link = """ - {link_name} + {link_name}
""".format(link_path=_link_path,link_name=_link_name) self.html += self.link @@ -339,33 +340,39 @@ class lf_report(): self.build_table() self.end_content_div() + def get_html_head(self, title='Untitled'): + return """ + + + + + + {title} + """.format(title=title) + def build_banner(self): # NOTE: {{ }} are the ESCAPED curly braces + # JBR removed deep indentation of html tag because it makes browser view-source is hard to debug + # JBR suggests rename method to start_html_doc() self.banner_html = """ - - - - - - - - {title} - - -
- -
+ + {head_tag} + +
+ +
""".format( + head_tag=self.get_html_head(title=self.title), title=self.title, date=self.date, ) @@ -373,31 +380,26 @@ class lf_report(): def build_banner_left(self): # NOTE: {{ }} are the ESCAPED curly braces + # JBR suggests rename method to start_html_doc() + # This method violates DRY, if the ID of the body/div#BannerBack/div element is actually necessary + # to specify, this needs to be made a parameter for build_banner() or start_html_doc() self.banner_html = """ - - - - - - - - {title} - - -
-
-
- -
-
-

{title}

-

{date}

-
-
-
+ + {head_tag} + +
+
+
+ +
+
+

{title}

+

{date}

+
+
+
""".format( + head_tag=self.get_html_head(title=self.title), title=self.title, date=self.date, ) @@ -469,51 +471,63 @@ class lf_report(): self.html += setup_information def build_footer(self): - self.footer_html = """ - -
- - - - - -
- - - - - """ + self.footer_html = """ + + """ self.html += self.footer_html def build_footer_no_png(self): - self.footer_html = """ - -
- - - - - -
- -
-

Generate by Candela Technologies LANforge network testing tool

-

www.candelatech.com

-

- - - """ + self.footer_html = """ + """ self.html += self.footer_html + def copy_js(self): + self.html += """ + + """ def build_custom(self): self.html += self.custom_html