From 2ef3df72dd970c7b887d0625e467731bc6dd0b30 Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Thu, 7 Feb 2019 15:04:58 -0800 Subject: [PATCH] finally cleaning up the html coverage report such that it displays properly in the DevOps tab --- .../devops_tasks/inline_css_for_cobertura.py | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/scripts/devops_tasks/inline_css_for_cobertura.py b/scripts/devops_tasks/inline_css_for_cobertura.py index fc4b82c9e0cd..2bb8537ba404 100644 --- a/scripts/devops_tasks/inline_css_for_cobertura.py +++ b/scripts/devops_tasks/inline_css_for_cobertura.py @@ -3,6 +3,7 @@ import bs4 import io import sys +import shutil COVERAGE_REPORT_DIR = 'htmlcov/' COVERAGE_REPORT = os.path.join(COVERAGE_REPORT_DIR, 'index.html') @@ -38,9 +39,39 @@ def embed_css_in_html_file(html_file, css_dir): with io.open(html_file, 'w', encoding='utf-8') as f: f.write(__str_version_handler(soup)) +def clean_index(html_file): + with io.open(html_file, 'r', encoding='utf-8') as f: + soup = bs4.BeautifulSoup(f.read(), "html.parser") + + # remove all links to the files that don't exist anymore + for a in soup.findAll('a'): + a.replaceWithChildren() + + # embedded CSS corrupts the sort indicator image. Javascript doesn't work in the devops display anyway. Removing the class + module_title = soup.find('th', class_='headerSortDown')["class"].remove('headerSortDown') + + # remove input filter + input_filter = soup.find(id= 'filter') + input_filter.decompose() + + # remove keyboard icon + keyboard_icon = soup.find(id='keyboard_icon') + keyboard_icon.decompose() + + # write final results + with io.open(html_file, 'w', encoding='utf-8') as f: + f.write(__str_version_handler(soup)) if __name__ == '__main__': for file in os.listdir(COVERAGE_REPORT_DIR): - if file.endswith(".html"): - print("Embedding CSS in {}".format(file)) - embed_css_in_html_file(os.path.join(COVERAGE_REPORT_DIR, file), COVERAGE_REPORT_DIR) + name, ext = os.path.splitext(os.path.basename(file.lower())) + if ext == ".html": + if name == "index": + print("Cleaning index in {}".format(file)) + clean_index(os.path.join(COVERAGE_REPORT_DIR, file)) + print("Embedding CSS in {}".format(file)) + embed_css_in_html_file(os.path.join(COVERAGE_REPORT_DIR, file), COVERAGE_REPORT_DIR) + else: + os.remove(os.path.join(COVERAGE_REPORT_DIR, file)) + +