Skip to content

Commit

Permalink
Record and report scancode file licenses
Browse files Browse the repository at this point in the history
Running Tern with the scancode extension was not reporting file level
license information due to a logic error. This commit updates the
add_file_data() function in scancode/executor.py to update file metadata
from scancode if the file already exists in the cache, or if not, add
the file object to the layer file list.

This commit also changes the default format to report the name of the
file licenses instead of the license expression as the license is human
readable and consistent with the other human readable license
expressions typically reported by the package managers.

Resolves #959

Signed-off-by: Rose Judge <[email protected]>
  • Loading branch information
rnjudge committed May 21, 2021
1 parent 22ac183 commit 6ada44b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions tern/extensions/scancode/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ def add_file_data(layer_obj, collected_files):
checkfile = collected_files.pop()
for f in layer_obj.files:
if f.merge(checkfile):
# file already exists and has now been updated
break
# file didn't previously exist in layer so add it now
layer_obj.files.append(checkfile)


def add_package_data(layer_obj, collected_packages):
Expand Down
2 changes: 1 addition & 1 deletion tern/formats/default/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_layer_info_list(layer):
package_list.print_empty = False

for f in layer.files:
layer_file_licenses_list.extend(f.license_expressions)
layer_file_licenses_list.extend(f.licenses)

layer_file_licenses_list = list(set(layer_file_licenses_list))
if layer_file_licenses_list:
Expand Down
6 changes: 3 additions & 3 deletions tern/report/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def get_layer_files_licenses(layer):
'''Given a image layer collect complete list of file licenses'''
file_level_licenses = set()
for f in layer.files:
for license_expression in f.license_expressions:
if license_expression:
file_level_licenses.add(license_expression)
for lic in f.licenses:
if lic:
file_level_licenses.add(lic)
return list(file_level_licenses)


Expand Down

0 comments on commit 6ada44b

Please sign in to comment.