Skip to content

Commit ea71be4

Browse files
committed
feat(OutputHTML): Implement fallback for license references table
The `--license-references` cli argument enables collection and storge of license reference data in output files. So as long as it was present as a Post-Scan option the `license_references` should not be empty. In such cases, the license reference table shall be filled with the already stored data. If however the `license_references` list is empty, the licenses should be collected from the `license_db` as a fall back, similar to the legacy license collection pre 49e7d89. Fixes #4101. Signed-off-by: Jens Keim <[email protected]>
1 parent 9c43698 commit ea71be4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/formattedcode/output_html.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,13 @@ def generate_output(results, license_references, version, template):
188188
"""
189189
# FIXME: This code is highly coupled with actual scans and may not
190190
# support adding new scans at all
191+
192+
from licensedcode.cache import get_licenses_db
193+
191194
converted = {}
192195
converted_infos = {}
193196
converted_packages = {}
197+
licenses = {}
194198

195199
LICENSES = 'license_detections'
196200
COPYRIGHTS = 'copyrights'
@@ -223,6 +227,11 @@ def generate_output(results, license_references, version, template):
223227
'value': license_expression,
224228
})
225229

230+
if not license_references and license_expression not in licenses:
231+
license_object = get_licenses_db().get(license_expression)
232+
if license_object != None:
233+
licenses[license_expression] = license_object
234+
226235
if results:
227236
converted[path] = sorted(results, key=itemgetter('start'))
228237

@@ -239,6 +248,10 @@ def generate_output(results, license_references, version, template):
239248
if PACKAGES in scanned_file:
240249
converted_packages[path] = scanned_file[PACKAGES]
241250

251+
if not license_references:
252+
licenses = dict(sorted(licenses.items()))
253+
license_references = list(licenses.values())
254+
242255
files = {
243256
'license_copyright': converted,
244257
'infos': converted_infos,

0 commit comments

Comments
 (0)