Skip to content

Commit d2c1e27

Browse files
feat: use cve-bin-tool without Reportlab (Fixes #1464) (#1485)
* fixes #1464
1 parent 4088489 commit d2c1e27

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cve_bin_tool/cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414

1515
import argparse
16+
import importlib.util
1617
import logging
1718
import os
1819
import platform
@@ -348,6 +349,15 @@ def main(argv=None):
348349
if int(args["cvss"]) > 0:
349350
score = int(args["cvss"])
350351

352+
# Check for PDF support
353+
output_format = args["format"]
354+
if output_format == "pdf" and importlib.util.find_spec("reportlab") is None:
355+
LOGGER.info("PDF output not available. Default to console.")
356+
LOGGER.info(
357+
"If you want to produce PDF output, please install reportlab using pip install reportlab"
358+
)
359+
output_format = "console"
360+
351361
merged_reports = None
352362
if args["merge"]:
353363
LOGGER.info(
@@ -545,7 +555,7 @@ def main(argv=None):
545555
)
546556

547557
if not args["quiet"]:
548-
output.output_file(args["format"])
558+
output.output_file(output_format)
549559
if args["backport_fix"] or args["available_fix"]:
550560
distro_info = args["backport_fix"] or args["available_fix"]
551561
is_backport = True if args["backport_fix"] else False

test/test_output_engine.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
CVE-bin-tool OutputEngine tests
66
"""
77
import csv
8+
import importlib.util
89
import json
910
import logging
1011
import os
@@ -470,6 +471,11 @@ def test_output_csv(self):
470471
expected_value = [dict(x) for x in reader]
471472
self.assertEqual(expected_value, self.FORMATTED_OUTPUT)
472473

474+
@unittest.skipUnless(
475+
importlib.util.find_spec("reportlab") is not None
476+
and importlib.util.find_spec("pdftotext") is not None,
477+
"Skipping PDF tests. Please install reportlab and pdftotext to run these tests.",
478+
)
473479
def test_output_pdf(self):
474480
"""Test formatting output as PDF"""
475481
output_pdf(self.MOCK_PDF_OUTPUT, False, 1, "cve_test.pdf", False)

0 commit comments

Comments
 (0)