All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/4] support/scripts/pkg-stats: import cve module only when needed
@ 2020-11-19 14:53 Thomas Petazzoni
  2020-11-19 14:53 ` [Buildroot] [PATCH 2/4] support/scripts/pkg-stats: fix Python 3.8 deprecation warning Thomas Petazzoni
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Thomas Petazzoni @ 2020-11-19 14:53 UTC (permalink / raw)
  To: buildroot

The cve module needs ijson, which may not be installed. Since cve
matching is only enabled when --nvd-path is passed, it is a bit silly
to error out about ijson being missing if it's not used.

So instead of unconditionally importing the cve module, only do it
conditionally.

However, instead of doing it right at the point where it is used, we
do it at the beginning of the main() function. Indeed, if the cve
module is needed but cannot be imported, we want to error out
immediately rather than doing a whole bunch of things, and failing on
the user later on in the middle of the pkg-stats execution.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 support/scripts/pkg-stats | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/support/scripts/pkg-stats b/support/scripts/pkg-stats
index d44f8241c1..2676cc49dd 100755
--- a/support/scripts/pkg-stats
+++ b/support/scripts/pkg-stats
@@ -32,7 +32,6 @@ brpath = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))
 
 sys.path.append(os.path.join(brpath, "utils"))
 from getdeveloperlib import parse_developers  # noqa: E402
-import cve as cvecheck  # noqa: E402
 
 
 INFRA_RE = re.compile(r"\$\(eval \$\(([a-z-]*)-package\)\)")
@@ -950,7 +949,13 @@ def parse_args():
 
 
 def __main__():
+    global cvecheck
+
     args = parse_args()
+
+    if args.nvd_path:
+        import cve as cvecheck
+
     if args.packages:
         package_list = args.packages.split(",")
     elif args.configpackages:
-- 
2.28.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-01-19 14:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19 14:53 [Buildroot] [PATCH 1/4] support/scripts/pkg-stats: import cve module only when needed Thomas Petazzoni
2020-11-19 14:53 ` [Buildroot] [PATCH 2/4] support/scripts/pkg-stats: fix Python 3.8 deprecation warning Thomas Petazzoni
2020-11-19 14:53 ` [Buildroot] [PATCH 3/4] utils/get-developers: use Developers.hasfile() where appropriate Thomas Petazzoni
2020-11-20 10:03   ` Heiko Thiery
2020-11-19 14:53 ` [Buildroot] [PATCH 4/4] utils/getdeveloperlib.py: use relative paths for files Thomas Petazzoni
2020-11-20 10:03   ` Heiko Thiery
2020-11-20 14:14     ` Thomas Petazzoni
2020-11-20 14:26       ` Heiko Thiery
2020-11-20 10:02 ` [Buildroot] [PATCH 1/4] support/scripts/pkg-stats: import cve module only when needed Heiko Thiery
2021-01-17 14:32 ` Thomas Petazzoni
2021-01-19 14:24   ` Peter Korsgaard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.