support/scripts/pkg-stats: fix flake8 errors
authorArnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Tue, 5 Jan 2021 22:23:31 +0000 (23:23 +0100)
committerArnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Tue, 5 Jan 2021 22:34:28 +0000 (23:34 +0100)
support/scripts/pkg-stats:81:22: E211 whitespace before '('
support/scripts/pkg-stats:404:1: E305 expected 2 blank lines after class or function definition, found 1
support/scripts/pkg-stats:561:12: E713 test for membership should be 'not in'
support/scripts/pkg-stats:567:1: E302 expected 2 blank lines, found 1
support/scripts/pkg-stats:595:1: E302 expected 2 blank lines, found 1
support/scripts/pkg-stats:1051:1: E302 expected 2 blank lines, found 1
support/scripts/pkg-stats:1057:1: E302 expected 2 blank lines, found 1

Also fix:
support/scripts/pkg-stats:1054:5: E722 do not use bare 'except'
found by a more recent flake8 version. The exception may be either
IndexError or AttributeError, so use Exception to catch either.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
support/scripts/pkg-stats

index 8a29531cd726654611289bb7b36a56889e3e09e3..4a9ff1ffa011c322048ea666dc53bc58c44f8791 100755 (executable)
@@ -78,7 +78,7 @@ class Package:
     all_license_files = list()
     all_versions = dict()
     all_ignored_cves = dict()
-    all_cpeids = dict ()
+    all_cpeids = dict()
     # This is the list of all possible checks. Add new checks to this list so
     # a tool that post-processeds the json output knows the checks before
     # iterating over the packages.
@@ -401,6 +401,7 @@ def package_init_make_info():
             pkgvar = pkgvar[:-7]
             Package.all_cpeids[pkgvar] = value
 
+
 check_url_count = 0
 
 
@@ -558,12 +559,13 @@ async def check_package_latest_version(packages):
 
 def check_package_cve_affects(cve, cpe_product_pkgs):
     for product in cve.affected_products:
-        if not product in cpe_product_pkgs:
+        if product not in cpe_product_pkgs:
             continue
         for pkg in cpe_product_pkgs[product]:
             if cve.affects(pkg.name, pkg.current_version, pkg.ignored_cves, pkg.cpeid) == cve.CVE_AFFECTS:
                 pkg.cves.append(cve.identifier)
 
+
 def check_package_cves(nvd_path, packages):
     if not os.path.isdir(nvd_path):
         os.makedirs(nvd_path)
@@ -592,6 +594,7 @@ def check_package_cves(nvd_path, packages):
             else:
                 pkg.status['cve'] = ("ok", "not affected by CVEs")
 
+
 def calculate_stats(packages):
     stats = defaultdict(int)
     stats['packages'] = len(packages)
@@ -1048,12 +1051,14 @@ def parse_args():
         parser.error('at least one of --html or --json (or both) is required')
     return args
 
+
 def cpeid_name(pkg):
     try:
         return pkg.cpeid.split(':')[1]
-    except:
+    except Exception:  # cpeid may be None, or improperly formatted
         return ''
 
+
 def __main__():
     args = parse_args()
     if args.packages: