From 5d9e797028461fffa2c21ca03d116909158044eb Mon Sep 17 00:00:00 2001 From: Swarnodip Nag <77166101+Swarno-Coder@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:23:54 +0530 Subject: [PATCH] fix: add missing docstrings to package_list_parser.py * fixes #3377 --- cve_bin_tool/package_list_parser.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cve_bin_tool/package_list_parser.py b/cve_bin_tool/package_list_parser.py index f7be11e33f..6e00a2a040 100644 --- a/cve_bin_tool/package_list_parser.py +++ b/cve_bin_tool/package_list_parser.py @@ -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": @@ -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 = [] @@ -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( @@ -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"] @@ -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