Skip to content

Commit 6ada44b

Browse files
committed
Record and report scancode file licenses
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]>
1 parent 22ac183 commit 6ada44b

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

tern/extensions/scancode/executor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ def add_file_data(layer_obj, collected_files):
160160
checkfile = collected_files.pop()
161161
for f in layer_obj.files:
162162
if f.merge(checkfile):
163+
# file already exists and has now been updated
163164
break
165+
# file didn't previously exist in layer so add it now
166+
layer_obj.files.append(checkfile)
164167

165168

166169
def add_package_data(layer_obj, collected_packages):

tern/formats/default/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def get_layer_info_list(layer):
106106
package_list.print_empty = False
107107

108108
for f in layer.files:
109-
layer_file_licenses_list.extend(f.license_expressions)
109+
layer_file_licenses_list.extend(f.licenses)
110110

111111
layer_file_licenses_list = list(set(layer_file_licenses_list))
112112
if layer_file_licenses_list:

tern/report/content.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def get_layer_files_licenses(layer):
2626
'''Given a image layer collect complete list of file licenses'''
2727
file_level_licenses = set()
2828
for f in layer.files:
29-
for license_expression in f.license_expressions:
30-
if license_expression:
31-
file_level_licenses.add(license_expression)
29+
for lic in f.licenses:
30+
if lic:
31+
file_level_licenses.add(lic)
3232
return list(file_level_licenses)
3333

3434

0 commit comments

Comments
 (0)