Skip to content

Commit

Permalink
Add expand button in html
Browse files Browse the repository at this point in the history
  • Loading branch information
bjk7119 committed Jun 28, 2022
1 parent 9e0b3a6 commit 0c7229d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
12 changes: 7 additions & 5 deletions src/fosslight_reuse/_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
OSS_PKG_INFO_FILES = ["oss-pkg-info.yaml", "oss-pkg-info.yml", r"oss-package*.info", "requirement.txt",
"requirements.txt", "package.json", "pom.xml", "build.gradle", "podfile.lock", "cartfile.resolved",
"pubspec.yaml", "package.resolved", "go.mod", r"fosslight-sbom-info*.yaml"]
HTML_RESULT_EXPAND_LIMIT = 10
HTML_RESULT_PRINT_LIMIT = 100

HTML_FORMAT_PREFIX = """
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
Expand All @@ -16,6 +18,7 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style>
.marker{background-color: Yellow;}
.underline{text-decoration-line: underline;}
</style>
<title>FOSSLight Reuse</title>
</head>
Expand All @@ -38,11 +41,7 @@
<td style="padding:40px;">
<div style="padding-bottom:10px;font-size:16px;font-weight:bold;">"""

HTML_COMPLIANCE_SUFFIX = """
</div>
<p style="font-size:12px;">
"""

HTML_COMPLIANCE_SUFFIX = "</div>"
HTML_CELL_PREFIX = """
<h2 style="margin:20px 0 0;padding:10px;font-size:16px;">« Files without License or Copyright »</h2>
<table cellspacing="0" cellpadding="0" width="100%" border="1" style="font-size:12px;border-color:#ddd;">
Expand Down Expand Up @@ -72,3 +71,6 @@
</body>
</html>
"""

HTML_EXPAND_PREFIX = """<details style="font-size:12px;">
<summary style="font-size:12px;color:blue;" class='underline'>Click to expand...</summary>"""
48 changes: 30 additions & 18 deletions src/fosslight_reuse/_result_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,41 @@
import os
from reuse import report
from reuse.project import Project
from fosslight_reuse._constant import HTML_FORMAT_PREFIX, HTML_CELL_PREFIX, HTML_FORMAT_SUFFIX, HTML_COMPLIANCE_SUFFIX
from fosslight_reuse._constant import HTML_FORMAT_PREFIX, HTML_CELL_PREFIX, HTML_FORMAT_SUFFIX, HTML_EXPAND_PREFIX,\
HTML_COMPLIANCE_SUFFIX, HTML_RESULT_PRINT_LIMIT, HTML_RESULT_EXPAND_LIMIT


def get_html_summary(result_item):
pkg_file_str = ""
detected_lic_str = ""
if result_item._oss_pkg_files:
for pkg_file in result_item._oss_pkg_files:
pkg_file_str += f"<br>&nbsp;&nbsp;&nbsp; - {pkg_file}"
def check_length_of_print_list(input_list: list, list_len: int):
print_cnt = 0
print_str = ""
if not input_list:
print_str = 'N/A'
else:
pkg_file_str = 'N/A'
if list_len <= HTML_RESULT_EXPAND_LIMIT:
for file in input_list:
print_str += f"<br>&nbsp;&nbsp;&nbsp; &#183; {file}"
elif HTML_RESULT_EXPAND_LIMIT < list_len:
print_str = HTML_EXPAND_PREFIX
for file in input_list:
print_str += f"<br>&nbsp;&nbsp;&nbsp; &#183; {file}"
print_cnt += 1
if print_cnt >= HTML_RESULT_PRINT_LIMIT:
print_str += "<br><b>&nbsp;&nbsp;&nbsp; See the log file for more listings...</b>"
break
print_str += "</details>"
return print_str

if result_item._detected_licenses:
for detected_lic in result_item._detected_licenses:
detected_lic_str += f"<br>&nbsp;&nbsp;&nbsp; - {detected_lic}"
else:
detected_lic_str = 'N/A'

def get_html_summary(result_item):
pkg_file_str = check_length_of_print_list(result_item._oss_pkg_files, len(result_item._oss_pkg_files))
detected_lic_str = check_length_of_print_list(result_item._detected_licenses, len(result_item._detected_licenses))

html_lint_str = f"""
- Open Source Package file: {pkg_file_str}</br>
- Detected licenses: {detected_lic_str}</br>
- Files without copyright / total: {result_item._count_without_cop} / {result_item._count_total_files}</br>
- Files without license / total: {result_item._count_without_lic} / {result_item._count_total_files}</br></p>
<p style="font-size:14px;line-height:1.2;">
- Open Source Package file: {pkg_file_str}<br>
- Detected licenses: {detected_lic_str}<br>
- Files without copyright / total: {result_item._count_without_cop} / {result_item._count_total_files}<br>
- Files without license / total: {result_item._count_without_lic} / {result_item._count_total_files}<br></p>
"""
return html_lint_str

Expand Down Expand Up @@ -80,7 +92,7 @@ def result_for_html(result_item, project: Project, path_to_find):
summary_str = get_html_summary(result_item)
cell_contents_str = ""

if get_num_of_not_compliant(result_item) <= 100:
if get_num_of_not_compliant(result_item) <= HTML_RESULT_PRINT_LIMIT:
cell_contents_str = get_html_cell(result_item, project, path_to_find)
html_in_str = f"{HTML_FORMAT_PREFIX}{compliance_str}{summary_str}{HTML_CELL_PREFIX}{cell_contents_str}{HTML_FORMAT_SUFFIX}"
else:
Expand Down

0 comments on commit 0c7229d

Please sign in to comment.