Small spdx.bbclass fixes
cover Small spdx.bbclass fixes
This patch series contain small adaptions, primarily for the spdx bbclasss to work with Python3. But with that said, I was unable to get it working when it came to interfacing with Fossology.
Olof Johansson (4):
spdx.bbclass: Replace deprecated string.replace with str.replace spdx.bbclass: Fix undefined variable error spdx.bbclass: Make use of bb.utils' sha1_file() spdx.bbclass: Encode strings before passing to hashlib
meta/classes/spdx.bbclass | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
Signature · 1 line
2.11.0
PATCH 2/4 spdx.bbclass: Fix undefined variable error
The path variable is used in an error message a few lines later, but was never defined.
--- meta/classes/spdx.bbclass | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes/spdx.bbclass +2 -1
@@ -289,7 +289,8 @@ def create_spdx_doc(file_info, scanned_files): def get_ver_code(dirname): chksums = [] for f_dir, f in list_files(dirname): - hash = hash_file(os.path.join(dirname, f_dir, f)) + path = os.path.join(dirname, f_dir, f) + hash = hash_file(path) if not hash is None: chksums.append(hash) else:
Signature · 1 line
2.11.0
PATCH 3/4 spdx.bbclass: Make use of bb.utils' sha1_file()
In reply to Olof JohanssonThe same functionality already exists within bitbake, so avoid duplicating.
--- meta/classes/spdx.bbclass | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
meta/classes/spdx.bbclass +2 -7
@@ -202,13 +202,8 @@ def list_files(dir): return def hash_file(file_name): - try: - with open(file_name, 'rb') as f: - data_string = f.read() - sha1 = hash_string(data_string) - return sha1 - except: - return None + from bb.utils import sha1_file + return sha1_file(file_name) def hash_string(data): import hashlib
Signature · 1 line
2.11.0
PATCH 4/4 spdx.bbclass: Encode strings before passing to hashlib
In reply to Olof JohanssonIn python3, passing a unicode object to hashlib will result in an exception that encourages you to encode it first.
--- meta/classes/spdx.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes/spdx.bbclass +1 -1
@@ -208,7 +208,7 @@ def hash_file(file_name): def hash_string(data): import hashlib sha1 = hashlib.sha1() - sha1.update(data) + sha1.update(data.encode('utf-8')) return sha1.hexdigest() def run_fossology(foss_command, full_spdx):
Signature · 1 line
2.11.0
PATCH 1/4 spdx.bbclass: Replace deprecated string.replace with str.replace
In reply to Olof JohanssonThe string.replace function is removed in python3. Instead, the str method "replace" should be used instead.
--- meta/classes/spdx.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes/spdx.bbclass +1 -1
@@ -226,7 +226,7 @@ def run_fossology(foss_command, full_spdx): except subprocess.CalledProcessError as e: return None - foss_output = string.replace(foss_output, '\r', '') + foss_output = foss_output.replace('\r', '') # Package info package_info = {}
Signature · 1 line
2.11.0