Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions scripts/devops_tasks/inline_css_for_cobertura.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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))