Skip to content

Commit

Permalink
feat: use cve-bin-tool without Reportlab (Fixes #1464) (#1485)
Browse files Browse the repository at this point in the history
* fixes #1464
  • Loading branch information
anthonyharrison committed Dec 29, 2021
1 parent 4088489 commit d2c1e27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

import argparse
import importlib.util
import logging
import os
import platform
Expand Down Expand Up @@ -348,6 +349,15 @@ def main(argv=None):
if int(args["cvss"]) > 0:
score = int(args["cvss"])

# Check for PDF support
output_format = args["format"]
if output_format == "pdf" and importlib.util.find_spec("reportlab") is None:
LOGGER.info("PDF output not available. Default to console.")
LOGGER.info(
"If you want to produce PDF output, please install reportlab using pip install reportlab"
)
output_format = "console"

merged_reports = None
if args["merge"]:
LOGGER.info(
Expand Down Expand Up @@ -545,7 +555,7 @@ def main(argv=None):
)

if not args["quiet"]:
output.output_file(args["format"])
output.output_file(output_format)
if args["backport_fix"] or args["available_fix"]:
distro_info = args["backport_fix"] or args["available_fix"]
is_backport = True if args["backport_fix"] else False
Expand Down
6 changes: 6 additions & 0 deletions test/test_output_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
CVE-bin-tool OutputEngine tests
"""
import csv
import importlib.util
import json
import logging
import os
Expand Down Expand Up @@ -470,6 +471,11 @@ def test_output_csv(self):
expected_value = [dict(x) for x in reader]
self.assertEqual(expected_value, self.FORMATTED_OUTPUT)

@unittest.skipUnless(
importlib.util.find_spec("reportlab") is not None
and importlib.util.find_spec("pdftotext") is not None,
"Skipping PDF tests. Please install reportlab and pdftotext to run these tests.",
)
def test_output_pdf(self):
"""Test formatting output as PDF"""
output_pdf(self.MOCK_PDF_OUTPUT, False, 1, "cve_test.pdf", False)
Expand Down

0 comments on commit d2c1e27

Please sign in to comment.