Skip to content

Commit 0c7229d

Browse files
committed
Add expand button in html
1 parent 9e0b3a6 commit 0c7229d

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

src/fosslight_reuse/_constant.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
OSS_PKG_INFO_FILES = ["oss-pkg-info.yaml", "oss-pkg-info.yml", r"oss-package*.info", "requirement.txt",
99
"requirements.txt", "package.json", "pom.xml", "build.gradle", "podfile.lock", "cartfile.resolved",
1010
"pubspec.yaml", "package.resolved", "go.mod", r"fosslight-sbom-info*.yaml"]
11+
HTML_RESULT_EXPAND_LIMIT = 10
12+
HTML_RESULT_PRINT_LIMIT = 100
1113

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

41-
HTML_COMPLIANCE_SUFFIX = """
42-
</div>
43-
<p style="font-size:12px;">
44-
"""
45-
44+
HTML_COMPLIANCE_SUFFIX = "</div>"
4645
HTML_CELL_PREFIX = """
4746
<h2 style="margin:20px 0 0;padding:10px;font-size:16px;">« Files without License or Copyright »</h2>
4847
<table cellspacing="0" cellpadding="0" width="100%" border="1" style="font-size:12px;border-color:#ddd;">
@@ -72,3 +71,6 @@
7271
</body>
7372
</html>
7473
"""
74+
75+
HTML_EXPAND_PREFIX = """<details style="font-size:12px;">
76+
<summary style="font-size:12px;color:blue;" class='underline'>Click to expand...</summary>"""

src/fosslight_reuse/_result_html.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,41 @@
55
import os
66
from reuse import report
77
from reuse.project import Project
8-
from fosslight_reuse._constant import HTML_FORMAT_PREFIX, HTML_CELL_PREFIX, HTML_FORMAT_SUFFIX, HTML_COMPLIANCE_SUFFIX
8+
from fosslight_reuse._constant import HTML_FORMAT_PREFIX, HTML_CELL_PREFIX, HTML_FORMAT_SUFFIX, HTML_EXPAND_PREFIX,\
9+
HTML_COMPLIANCE_SUFFIX, HTML_RESULT_PRINT_LIMIT, HTML_RESULT_EXPAND_LIMIT
910

1011

11-
def get_html_summary(result_item):
12-
pkg_file_str = ""
13-
detected_lic_str = ""
14-
if result_item._oss_pkg_files:
15-
for pkg_file in result_item._oss_pkg_files:
16-
pkg_file_str += f"<br>&nbsp;&nbsp;&nbsp; - {pkg_file}"
12+
def check_length_of_print_list(input_list: list, list_len: int):
13+
print_cnt = 0
14+
print_str = ""
15+
if not input_list:
16+
print_str = 'N/A'
1717
else:
18-
pkg_file_str = 'N/A'
18+
if list_len <= HTML_RESULT_EXPAND_LIMIT:
19+
for file in input_list:
20+
print_str += f"<br>&nbsp;&nbsp;&nbsp; &#183; {file}"
21+
elif HTML_RESULT_EXPAND_LIMIT < list_len:
22+
print_str = HTML_EXPAND_PREFIX
23+
for file in input_list:
24+
print_str += f"<br>&nbsp;&nbsp;&nbsp; &#183; {file}"
25+
print_cnt += 1
26+
if print_cnt >= HTML_RESULT_PRINT_LIMIT:
27+
print_str += "<br><b>&nbsp;&nbsp;&nbsp; See the log file for more listings...</b>"
28+
break
29+
print_str += "</details>"
30+
return print_str
1931

20-
if result_item._detected_licenses:
21-
for detected_lic in result_item._detected_licenses:
22-
detected_lic_str += f"<br>&nbsp;&nbsp;&nbsp; - {detected_lic}"
23-
else:
24-
detected_lic_str = 'N/A'
32+
33+
def get_html_summary(result_item):
34+
pkg_file_str = check_length_of_print_list(result_item._oss_pkg_files, len(result_item._oss_pkg_files))
35+
detected_lic_str = check_length_of_print_list(result_item._detected_licenses, len(result_item._detected_licenses))
2536

2637
html_lint_str = f"""
27-
- Open Source Package file: {pkg_file_str}</br>
28-
- Detected licenses: {detected_lic_str}</br>
29-
- Files without copyright / total: {result_item._count_without_cop} / {result_item._count_total_files}</br>
30-
- Files without license / total: {result_item._count_without_lic} / {result_item._count_total_files}</br></p>
38+
<p style="font-size:14px;line-height:1.2;">
39+
- Open Source Package file: {pkg_file_str}<br>
40+
- Detected licenses: {detected_lic_str}<br>
41+
- Files without copyright / total: {result_item._count_without_cop} / {result_item._count_total_files}<br>
42+
- Files without license / total: {result_item._count_without_lic} / {result_item._count_total_files}<br></p>
3143
"""
3244
return html_lint_str
3345

@@ -80,7 +92,7 @@ def result_for_html(result_item, project: Project, path_to_find):
8092
summary_str = get_html_summary(result_item)
8193
cell_contents_str = ""
8294

83-
if get_num_of_not_compliant(result_item) <= 100:
95+
if get_num_of_not_compliant(result_item) <= HTML_RESULT_PRINT_LIMIT:
8496
cell_contents_str = get_html_cell(result_item, project, path_to_find)
8597
html_in_str = f"{HTML_FORMAT_PREFIX}{compliance_str}{summary_str}{HTML_CELL_PREFIX}{cell_contents_str}{HTML_FORMAT_SUFFIX}"
8698
else:

0 commit comments

Comments
 (0)