summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oe')
-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):
45 return doc_sha1 45 return doc_sha1
46 46
47 47
48def read_doc(filename): 48def read_doc(fn):
49 import hashlib 49 import hashlib
50 import oe.spdx 50 import oe.spdx
51 51 import io
52 with filename.open("rb") as f: 52 import contextlib
53
54 @contextlib.contextmanager
55 def get_file():
56 if isinstance(fn, io.IOBase):
57 yield fn
58 else:
59 with fn.open("rb") as f:
60 yield f
61
62 with get_file() as f:
53 sha1 = hashlib.sha1() 63 sha1 = hashlib.sha1()
54 while True: 64 while True:
55 chunk = f.read(4096) 65 chunk = f.read(4096)