From f1cd4f264d206a3bf9d95cc1e632a476299643e3 Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Wed, 1 Sep 2021 08:44:43 -0500 Subject: classes/create-spdx: Add SHA1 to index file (From OE-Core rev: ebfe78ad26b643ce0fb22ba5b3ede43da4a78987) Signed-off-by: Joshua Watt Signed-off-by: Richard Purdie --- meta/lib/oe/sbom.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'meta/lib') diff --git a/meta/lib/oe/sbom.py b/meta/lib/oe/sbom.py index d40e5b792f..294feee10b 100644 --- a/meta/lib/oe/sbom.py +++ b/meta/lib/oe/sbom.py @@ -45,11 +45,21 @@ def write_doc(d, spdx_doc, subdir): return doc_sha1 -def read_doc(filename): +def read_doc(fn): import hashlib import oe.spdx - - with filename.open("rb") as f: + import io + import contextlib + + @contextlib.contextmanager + def get_file(): + if isinstance(fn, io.IOBase): + yield fn + else: + with fn.open("rb") as f: + yield f + + with get_file() as f: sha1 = hashlib.sha1() while True: chunk = f.read(4096) -- cgit v1.2.3-54-g00ecf