Skip to content

Commit

Permalink
Fix linting error for generator.py
Browse files Browse the repository at this point in the history
Add a new function get_layer_info_list() to replace the deeper branches.

Remove unused variable layer_file_licenses_list in the origin
function print_full_report(image).

Fixes tern-tools#648.
Signed-off-by: WangJL <[email protected]>
  • Loading branch information
ForgetMe17 committed Apr 23, 2020
1 parent a6fde9e commit 217bca4
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions tern/formats/default/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,8 @@ def print_full_report(image):
for layer_origin in layer.origins.origins:
notes = notes + content.print_notices(layer_origin,
'\t', '\t\t')
layer_pkg_list = []
layer_license_list = []
layer_file_licenses_list = []
file_level_licenses = None

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

layer_file_licenses_list = list(set(layer_file_licenses_list))
if layer_file_licenses_list:
file_level_licenses = ", ".join(layer_file_licenses_list)

for package in layer.packages:
pkg = package.name + "-" + package.version
if pkg not in layer_pkg_list and pkg:
layer_pkg_list.append(pkg)
if package.pkg_license not in layer_license_list and \
package.pkg_license:
layer_license_list.append(package.pkg_license)

(layer_pkg_list, layer_license_list,
file_level_licenses) = get_layer_info_list(layer)
# Collect files + packages + licenses in the layer
notes += formats.layer_file_licenses_list.format(
list=file_level_licenses)
Expand All @@ -66,6 +48,31 @@ def print_full_report(image):
return notes


def get_layer_info_list(layer):
'''Given a layer, collect files + packages + licenses in the layer,
return them as lists.'''
layer_pkg_list = []
layer_license_list = []
layer_file_licenses_list = []
file_level_licenses = None

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

layer_file_licenses_list = list(set(layer_file_licenses_list))
if layer_file_licenses_list:
file_level_licenses = ", ".join(layer_file_licenses_list)

for package in layer.packages:
pkg = package.name + "-" + package.version
if pkg not in layer_pkg_list and pkg:
layer_pkg_list.append(pkg)
if package.pkg_license not in layer_license_list and \
package.pkg_license:
layer_license_list.append(package.pkg_license)
return layer_pkg_list, layer_license_list, file_level_licenses


def print_licenses_only(image_obj_list):
'''Print a complete list of licenses for all images'''
full_license_list = []
Expand Down

0 comments on commit 217bca4

Please sign in to comment.