Skip to contentSkip to conversation

Small spdx.bbclass fixes

PATCH New Olof Johansson 1 participant 5 messages Jul 16, 2018

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

PATCH 1/4 spdx.bbclass: Replace deprecated string.replace with str.replace

The 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
index c5f544d2a4f..ab2eaa5c0c1 100644
@@ -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
#2 lore raw

PATCH 2/4 spdx.bbclass: Fix undefined variable error

In reply to Olof Johansson

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
index ab2eaa5c0c1..9e374d70a6c 100644
@@ -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
#3 lore raw

PATCH 3/4 spdx.bbclass: Make use of bb.utils' sha1_file()

In reply to Olof Johansson

The 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
index 9e374d70a6c..a3e22afc33d 100644
@@ -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
#4 lore raw

PATCH 4/4 spdx.bbclass: Encode strings before passing to hashlib

In reply to Olof Johansson

In 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
index a3e22afc33d..fb78e274a8e 100644
@@ -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