Skip to content

Commit

Permalink
Show package type in default report
Browse files Browse the repository at this point in the history
This commit adds package type/format information to the default report.
This is a useful datapoint as it corresponds to the package manager in
base.yml that was used to inventory the layer. Sometimes there may be
two collection  methods used per layer and it will be helpful to
differentiate between the two by noting the package format.

Resolves #984

Signed-off-by: Rose Judge <rjudge@vmware.com>
  • Loading branch information
rnjudge committed Jul 6, 2021
1 parent e62a6c1 commit b8e7837
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tern/analyze/default/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ def convert_to_pkg_dicts(attr_lists):
return pkg_list


def fill_pkg_results(image_layer, pkg_list_dict):
def fill_pkg_results(image_layer, pkg_list_dict, pkg_format):
"""Fill results from collecting package information into the image layer
object"""
if 'names' in pkg_list_dict and len(pkg_list_dict['names']) > 1:
pkg_list = convert_to_pkg_dicts(pkg_list_dict)
for pkg_dict in pkg_list:
pkg = Package(pkg_dict['name'])
pkg.fill(pkg_dict)
pkg.pkg_format = pkg_format
image_layer.add_package(pkg)
2 changes: 1 addition & 1 deletion tern/analyze/default/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def execute_base(layer_obj, prereqs):
if warnings:
logger.warning("Some metadata may be missing")
# bundle the results into Package objects
bundle.fill_pkg_results(layer_obj, pkg_dict)
bundle.fill_pkg_results(layer_obj, pkg_dict, listing.get("pkg_format"))
# remove extra FileData objects from the layer
com.remove_duplicate_layer_files(layer_obj)
# if there is no listing add a notice
Expand Down
2 changes: 1 addition & 1 deletion tern/analyze/default/live/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def fill_packages(layer, prereqs):
"metadata.")
if warnings:
logger.warning("Some metadata may be missing.")
bundle.fill_pkg_results(layer, pkg_dict)
bundle.fill_pkg_results(layer, pkg_dict, listing.get("pkg_format"))
com.remove_duplicate_layer_files(layer)


Expand Down
9 changes: 9 additions & 0 deletions tern/classes/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, name):
self.__origins = Origins()
self.__files = []
self.__pkg_licenses = []
self.__pkg_format = ''

@property
def name(self):
Expand Down Expand Up @@ -115,6 +116,14 @@ def checksum(self):
def checksum(self, checksum):
self.__checksum = checksum

@property
def pkg_format(self):
return self.__pkg_format

@pkg_format.setter
def pkg_format(self, pkg_format):
self.__pkg_format = pkg_format

def get_file_paths(self):
"""Return a list of paths of all the files in a package"""
return [f.path for f in self.__files]
Expand Down
4 changes: 2 additions & 2 deletions tern/formats/default/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_layer_info_list(layer):
layer_file_licenses_list = []
file_level_licenses = None
package_list = PrettyTable()
package_list.field_names = ["Package", "Version", "License"]
package_list.field_names = ["Package", "Version", "License", "Pkg Format"]
package_list.align = "l"
package_list.print_empty = False

Expand All @@ -114,7 +114,7 @@ def get_layer_info_list(layer):

for package in layer.packages:
package_list.add_row([package.name, package.version,
package.pkg_license])
package.pkg_license, package.pkg_format])

return file_level_licenses, package_list.get_string()

Expand Down
3 changes: 2 additions & 1 deletion tests/test_class_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def testFill(self):
'checksum': 'abcxyz',
'pkg_licenses': ['MIT', 'GPL'],
'files': [{'name': 'a.txt', 'path': '/usr/a.txt'},
{'name': 'b.txt', 'path': '/lib/b.txt'}]}
{'name': 'b.txt', 'path': '/lib/b.txt'}],
'pkg_format': 'rpm'}
p = Package('p1')
p.fill(p_dict)
self.assertEqual(p.name, 'p1')
Expand Down

0 comments on commit b8e7837

Please sign in to comment.