Skip to content

Commit

Permalink
Fixing Issue intel#3377
Browse files Browse the repository at this point in the history
  • Loading branch information
Swarno-Coder committed Oct 4, 2023
1 parent 4f4ede0 commit debc9d2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cve_bin_tool/package_list_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def __init__(
logger: Logger = LOGGER.getChild("PackageListParser"),
error_mode=ErrorMode.TruncTrace,
) -> None:
"""
Initialize the PackageListParser object.
Args:
input_file (str): The path to the input file containing a list of packages.
logger (Logger): An optional logger object for logging messages.
error_mode (ErrorMode): An optional error mode specifying how errors should be handled.
"""
self.input_file = input_file

if self.__class__.__name__ != "PackageListParser":
Expand All @@ -50,6 +58,12 @@ def __init__(
self.package_names_without_vendor: List[Any] = []

def parse_list(self):
"""
Parse the package list and return parsed package information.
Returns:
Dict[Any, Any]: A dictionary containing parsed package information.
"""
input_file = self.input_file
self.check_file()
installed_packages = []
Expand Down Expand Up @@ -143,6 +157,12 @@ def parse_list(self):
return self.parsed_data_with_vendor

def add_vendor(self, vendor_package_pairs):
"""
Add vendor information to package entries based on data retrieved from the CVE database.
Args:
vendor_package_pairs: A list of vendor-product pairs obtained from the CVE database.
"""
for vendor_package_pair in vendor_package_pairs:
for package_name in self.package_names_without_vendor:
if vendor_package_pair["product"] == package_name["name"].replace(
Expand All @@ -154,6 +174,9 @@ def add_vendor(self, vendor_package_pairs):
break

def parse_data(self):
"""
Parse package data and construct a dictionary with information about each installed package.
"""
for row in self.package_names_with_vendor:
product_info = ProductInfo(
row["vendor"], row["name"].lower(), row["version"]
Expand All @@ -168,6 +191,9 @@ def parse_data(self):
self.parsed_data_with_vendor[product_info]["paths"] = {""}

def check_file(self):
"""
Perform various checks on the input file to ensure its validity and compatibility with the system's package manager.
"""
input_file = self.input_file
error_mode = self.error_mode

Expand Down

0 comments on commit debc9d2

Please sign in to comment.