Skip to content

Commit 41d2d5b

Browse files
authored
Merge pull request #2539 from itssingh/html_temp
Add emails and urls to HTML output
2 parents daeb709 + b7e35b7 commit 41d2d5b

File tree

7 files changed

+1028
-9
lines changed

7 files changed

+1028
-9
lines changed

CHANGELOG.rst

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Important API changes:
2727
that contains each package instance that can be aggregating data from
2828
multiple manifests for a single package instance.
2929

30+
- The data structure for HTML output has been changed to include emails and urls under the
31+
"infos" object. Now HTML template will output holders, authors, emails, and
32+
urls into separate tables like "licenses" and "copyrights".
3033

3134
Copyright detection:
3235
~~~~~~~~~~~~~~~~~~~~

src/formattedcode/output_html.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ def generate_output(results, version, template):
155155
LICENSES = 'licenses'
156156
COPYRIGHTS = 'copyrights'
157157
PACKAGES = 'packages'
158-
URLS = 'urls'
159-
EMAILS = 'emails'
160158

161159
# Create a flattened data dict keyed by path
162160
for scanned_file in results:
@@ -197,7 +195,7 @@ def generate_output(results, version, template):
197195
# denormalizing the list here??
198196
converted_infos[path] = {}
199197
for name, value in scanned_file.items():
200-
if name in (LICENSES, PACKAGES, COPYRIGHTS, EMAILS, URLS):
198+
if name in (LICENSES, PACKAGES, COPYRIGHTS):
201199
continue
202200
converted_infos[path][name] = value
203201

src/formattedcode/templates/html/template.html

+100
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,106 @@
131131
{% endfor %}
132132
</tbody>
133133
</table>
134+
<table>
135+
<caption>Holders</caption>
136+
<thead>
137+
<tr>
138+
<th>path</th>
139+
<th>holder</th>
140+
<th>start</th>
141+
<th>end</th>
142+
</tr>
143+
</thead>
144+
<tbody>
145+
{% for path, row in files.infos.items() %}
146+
{% if row.holders %}
147+
{% for data in row.holders %}
148+
<tr>
149+
<td>{{ path }}</td>
150+
<td>{{ data.value }}</td>
151+
<td>{{ data.start_line }}</td>
152+
<td>{{ data.end_line }}</td>
153+
</tr>
154+
{% endfor %}
155+
{% endif %}
156+
{% endfor %}
157+
</tbody>
158+
</table>
159+
<table>
160+
<caption>Authors</caption>
161+
<thead>
162+
<tr>
163+
<th>path</th>
164+
<th>Author</th>
165+
<th>start</th>
166+
<th>end</th>
167+
</tr>
168+
</thead>
169+
<tbody>
170+
{% for path, row in files.infos.items() %}
171+
{% if row.authors %}
172+
{% for data in row.authors %}
173+
<tr>
174+
<td>{{ path }}</td>
175+
<td>{{ data.value }}</td>
176+
<td>{{ data.start_line }}</td>
177+
<td>{{ data.end_line }}</td>
178+
</tr>
179+
{% endfor %}
180+
{% endif %}
181+
{% endfor %}
182+
</tbody>
183+
</table>
184+
<table>
185+
<caption>Emails</caption>
186+
<thead>
187+
<tr>
188+
<th>path</th>
189+
<th>email</th>
190+
<th>start</th>
191+
<th>end</th>
192+
</tr>
193+
</thead>
194+
<tbody>
195+
{% for path, row in files.infos.items() %}
196+
{% if row.emails %}
197+
{% for data in row.emails %}
198+
<tr>
199+
<td>{{ path }}</td>
200+
<td>{{ data.email |urlize(target='_blank') }}</td>
201+
<td>{{ data.start_line }}</td>
202+
<td>{{ data.end_line }}</td>
203+
</tr>
204+
{% endfor %}
205+
{% endif %}
206+
{% endfor %}
207+
</tbody>
208+
</table>
209+
<table>
210+
<caption>Urls</caption>
211+
<thead>
212+
<tr>
213+
<th>path</th>
214+
<th>url</th>
215+
<th>start</th>
216+
<th>end</th>
217+
</tr>
218+
</thead>
219+
<tbody>
220+
{% for path, row in files.infos.items() %}
221+
{% if row.urls %}
222+
{% for data in row.urls %}
223+
<tr>
224+
<td>{{ path }}</td>
225+
<td>{{ data.url |urlize(target='_blank') }}</td>
226+
<td>{{ data.start_line }}</td>
227+
<td>{{ data.end_line }}</td>
228+
</tr>
229+
{% endfor %}
230+
{% endif %}
231+
{% endfor %}
232+
</tbody>
233+
</table>
134234
{% endif %}
135235

136236
{% if files.packages %}

tests/formattedcode/data/templated/sample-template.html

+101-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</style>
6363
</head>
6464
<body>
65-
<p> Scanned with ScanCode version {{ version }} </p>
65+
<p> Scanned with ScanCode </p>
6666
{% if files.license_copyright %}
6767
<table>
6868
<caption>Copyrights and Licenses Information</caption>
@@ -104,7 +104,6 @@
104104
<th>type</th>
105105
<th>name</th>
106106
<th>extension</th>
107-
<th>date</th>
108107
<th>size</th>
109108
<th>sha1</th>
110109
<th>md5</th>
@@ -127,7 +126,6 @@
127126
<td>{{ row.type }}</td>
128127
<td>{{ row.name }}</td>
129128
<td>{{ row.extension }}</td>
130-
<td>{{ row.date }}</td>
131129
<td>{{ row.size }}</td>
132130
<td>{{ row.sha1 }}</td>
133131
<td>{{ row.md5 }}</td>
@@ -145,6 +143,106 @@
145143
{% endfor %}
146144
</tbody>
147145
</table>
146+
<table>
147+
<caption>Holders</caption>
148+
<thead>
149+
<tr>
150+
<th>path</th>
151+
<th>holder</th>
152+
<th>start</th>
153+
<th>end</th>
154+
</tr>
155+
</thead>
156+
<tbody>
157+
{% for path, row in files.infos.items() %}
158+
{% if row.holders %}
159+
{% for data in row.holders %}
160+
<tr>
161+
<td>{{ path }}</td>
162+
<td>{{ data.value }}</td>
163+
<td>{{ data.start_line }}</td>
164+
<td>{{ data.end_line }}</td>
165+
</tr>
166+
{% endfor %}
167+
{% endif %}
168+
{% endfor %}
169+
</tbody>
170+
</table>
171+
<table>
172+
<caption>Authors</caption>
173+
<thead>
174+
<tr>
175+
<th>path</th>
176+
<th>Author</th>
177+
<th>start</th>
178+
<th>end</th>
179+
</tr>
180+
</thead>
181+
<tbody>
182+
{% for path, row in files.infos.items() %}
183+
{% if row.authors %}
184+
{% for data in row.authors %}
185+
<tr>
186+
<td>{{ path }}</td>
187+
<td>{{ data.value }}</td>
188+
<td>{{ data.start_line }}</td>
189+
<td>{{ data.end_line }}</td>
190+
</tr>
191+
{% endfor %}
192+
{% endif %}
193+
{% endfor %}
194+
</tbody>
195+
</table>
196+
<table>
197+
<caption>Emails</caption>
198+
<thead>
199+
<tr>
200+
<th>path</th>
201+
<th>email</th>
202+
<th>start</th>
203+
<th>end</th>
204+
</tr>
205+
</thead>
206+
<tbody>
207+
{% for path, row in files.infos.items() %}
208+
{% if row.emails %}
209+
{% for data in row.emails %}
210+
<tr>
211+
<td>{{ path }}</td>
212+
<td>{{ data.email |urlize(target='_blank') }}</td>
213+
<td>{{ data.start_line }}</td>
214+
<td>{{ data.end_line }}</td>
215+
</tr>
216+
{% endfor %}
217+
{% endif %}
218+
{% endfor %}
219+
</tbody>
220+
</table>
221+
<table>
222+
<caption>Urls</caption>
223+
<thead>
224+
<tr>
225+
<th>path</th>
226+
<th>url</th>
227+
<th>start</th>
228+
<th>end</th>
229+
</tr>
230+
</thead>
231+
<tbody>
232+
{% for path, row in files.infos.items() %}
233+
{% if row.urls %}
234+
{% for data in row.urls %}
235+
<tr>
236+
<td>{{ path }}</td>
237+
<td>{{ data.url |urlize(target='_blank') }}</td>
238+
<td>{{ data.start_line }}</td>
239+
<td>{{ data.end_line }}</td>
240+
</tr>
241+
{% endfor %}
242+
{% endif %}
243+
{% endfor %}
244+
</tbody>
245+
</table>
148246
{% endif %}
149247

150248
{% if files.packages %}

0 commit comments

Comments
 (0)