summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/sbom.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oe/sbom.py')
-rw-r--r--meta/lib/oe/sbom.py16
1 files changed, 13 insertions, 3 deletions
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)