Fixed up the last pieces to make avbtool work with py3.
When changing the shebang in avbtool to python3 all
libavb_host_unittest are now passing. There will be a follow up CL
to switch over to Python 3 entirely.
This change is still compatible with Python 2.
Bug: 151336743
Test: atest --host libavb_host_unittest
Test: atest --host aftltool_test
Test: ./aftltool_integration_test.py
Change-Id: Iddbf73026d960a76deb3a62ae0583c32aa0c81db
diff --git a/avbtool b/avbtool
index a7edfaf..9a79e7c 100755
--- a/avbtool
+++ b/avbtool
@@ -1544,7 +1544,7 @@
if tag != self.TAG or num_bytes_following != expected_size:
raise LookupError('Given data does not look like a hash descriptor.')
# Nuke NUL-bytes at the end.
- self.hash_algorithm = self.hash_algorithm.split('\0', 1)[0]
+ self.hash_algorithm = self.hash_algorithm.rstrip(b'\0').decode('ascii')
o = 0
try:
self.partition_name = data[
@@ -2926,7 +2926,7 @@
# pylint: disable=redefined-variable-type
desc = AvbPropertyDescriptor()
desc.key = prop[0:idx]
- desc.value = prop[(idx + 1):]
+ desc.value = prop[(idx + 1):].encode('utf-8')
encoded_descriptors.extend(desc.encode())
if props_from_file:
for prop in props_from_file:
@@ -2935,7 +2935,6 @@
raise AvbError('Malformed property "{}".'.format(prop))
desc = AvbPropertyDescriptor()
desc.key = prop[0:idx]
- desc.value = prop[(idx + 1):]
file_path = prop[(idx + 1):]
with open(file_path, 'rb') as f:
desc.value = f.read()