Skip to content

Commit 860af82

Browse files
author
shanko07
committed
Add simple function to turn JSON notices data into standalone single HTML file
1 parent 1f27bf2 commit 860af82

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## To use ##
2+
3+
```
4+
pip3 install blackduck
5+
pip3 install -r requirements.txt
6+
```
7+
8+
```
9+
cd ../../
10+
python3 examples/generate_notices_report_for_project_version.py project-name version-name -f examples/generate_html_notices_report_from_json/bd-notices -r JSON -c
11+
cd examples/generate_html_notices_report_from_json
12+
python3 generate_html_notices_from_json.py bd-notices.json my-report.html
13+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from jinja2 import Environment, FileSystemLoader
2+
import os
3+
import json
4+
import argparse
5+
6+
parser = argparse.ArgumentParser("A program to transform a JSON formatted representation of a Black Duck notices file into a standalone HTML document")
7+
parser.add_argument("json_file", help="The input JSON file to be converted")
8+
parser.add_argument("output_file_html", help="The file to output the results to")
9+
10+
args = parser.parse_args()
11+
12+
templates_dir = os.path.dirname(os.path.abspath(__file__))
13+
env = Environment(loader=FileSystemLoader(templates_dir))
14+
template = env.get_template('notices-template.html')
15+
16+
with open(args.output_file_html, 'w+') as fh:
17+
with open(args.json_file, 'r') as lj:
18+
data = json.load(lj)
19+
fileContent = data['reportContent'][0]['fileContent']
20+
21+
fh.write(template.render(componentLicenses=fileContent['componentLicenses'],
22+
licenseTexts=fileContent['licenseTexts'],
23+
componentCopyrightTexts=fileContent['componentCopyrightTexts'],
24+
projectVersion=fileContent['projectVersion']))
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<!DOCTYPE html>
2+
<html style="font-family:Open Sans,sans-serif;">
3+
<body>
4+
<h1>
5+
{{ projectVersion.projectName }} <span>&mdash;</span> {{ projectVersion.versionName }} <span>&mdash;</span> Notices File
6+
</h1>
7+
<div style="clear:both;display:block;">
8+
<div style="display:inline-block;">
9+
<span>Phase:</span>
10+
<span>{{ projectVersion.versionPhase }}</span>
11+
</div>
12+
|
13+
<div style="display:inline-block;">
14+
<span>Distribution:</span>
15+
<span>{{ projectVersion.versionDistribution }}</span>
16+
</div>
17+
</div>
18+
19+
<h1 id="comp-header" style="cursor:pointer;">Components</h1>
20+
<table style="width:100%;border-collapse:collapse;font-family:Open Sans,sans-serif;" id="comp-container">
21+
<thead>
22+
<tr style="border-bottom:1px solid black">
23+
<th style="text-align:left;background-color:#f6f6f6;font-weight:500">Component</th>
24+
<th style="text-align:left;background-color:#f6f6f6;font-weight:500">License</th>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
{% for row in componentLicenses %}
29+
<tr style="border-bottom:1px solid black">
30+
<td>
31+
<span>
32+
<span style="font-weight:700">{{ row.component.projectName }}</span>
33+
<span style="font-weight:500">
34+
{% if row.component.versionName %}
35+
{{ row.component.versionName }}
36+
{% endif %}
37+
</span>
38+
</span>
39+
</td>
40+
<td>
41+
<div>
42+
{% if row.licenses|length > 0 %}
43+
{{ row.licenses[0]['name'] }}
44+
{% endif %}
45+
</div>
46+
</td>
47+
</tr>
48+
{% endfor %}
49+
</tbody>
50+
</table>
51+
52+
{% if componentCopyrightTexts|length > 0 %}
53+
<h1 id="copyright-header" style="cursor:pointer;">Copyright Data</h1>
54+
<div id="copyright-container">
55+
{% for row in componentCopyrightTexts %}
56+
<h2>
57+
{{ row.componentVersionSummary.projectName }} <span>&mdash;</span> {{ row.originFullName }}
58+
</h2>
59+
{% for cr in row.copyrightTexts %}
60+
<ul>
61+
<li style="list-style-type:disc;">
62+
{{ cr|e }}
63+
</li>
64+
</ul>
65+
{% endfor %}
66+
{% endfor %}
67+
</div>
68+
{% endif %}
69+
70+
<h1 id="license-header" style="cursor:pointer;">Licenses</h1>
71+
<div id="license-container">
72+
{% for row in licenseTexts %}
73+
<h2>{{ row.name }}</h2>
74+
<div>
75+
{% for comp in row.components %}
76+
{{ comp.projectName }} {{ comp.versionName }}{% if not loop.last %},{% endif %}
77+
{% endfor %}
78+
</div>
79+
<pre style="background-color:#f6f6f6;border:1px solid black">{{ row.text|e }}</pre>
80+
{% endfor %}
81+
</div>
82+
83+
84+
85+
<script>
86+
compheader = document.getElementById("comp-header")
87+
if (!(compheader === null)) {
88+
compheader.addEventListener("click", function() {
89+
container = document.getElementById("comp-container")
90+
if (container.style.display === "none") {
91+
container.style.display = null;
92+
} else {
93+
container.style.display = "none";
94+
}
95+
});
96+
}
97+
98+
copyheader = document.getElementById("copyright-header")
99+
if (!(copyheader === null)) {
100+
copyheader.addEventListener("click", function() {
101+
container = document.getElementById("copyright-container")
102+
if (container.style.display === "none") {
103+
container.style.display = null;
104+
} else {
105+
container.style.display = "none";
106+
}
107+
});
108+
}
109+
110+
licenseheader = document.getElementById("license-header")
111+
if (!(licenseheader === null)) {
112+
licenseheader.addEventListener("click", function() {
113+
container = document.getElementById("license-container")
114+
if (container.style.display === "none") {
115+
container.style.display = null;
116+
} else {
117+
container.style.display = "none";
118+
}
119+
});
120+
}
121+
122+
</script>
123+
124+
</body>
125+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# for use of the template to generate the html
2+
jinja2

0 commit comments

Comments
 (0)