summaryrefslogtreecommitdiff
path: root/scripts/update_payload/common.py
diff options
context:
space:
mode:
authorAndrew Lassalle <andrewlassalle@chromium.org>2019-11-05 13:30:34 -0800
committerCommit Bot <commit-bot@chromium.org>2019-11-19 20:22:42 +0000
commit165843ca10908d7bd79582829a5ee51b098685e6 (patch)
treec4c98899ca4d134af1b2655afbe17dc7cb843b40 /scripts/update_payload/common.py
parentd04ca0c5cc9e4507301be355fd3bd86b871b05c4 (diff)
update_payload: Port scripts to python3
Update the update_payload scripts to be compatible with python2 and python3. Python2 compatibility is needed since the repo is shared with Android. BUG=chromium:1011631 TEST=Executed aosp/system/update_engine/scripts/run_unittests and cros_generate_update_payload Cq-Depend: chromium:1904837, chromium:1911499 Change-Id: Ie450b80b5f7550051b38d320173ccc0c915f65e7 Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/1904310 Commit-Queue: Andrew Lassalle <andrewlassalle@chromium.org> Tested-by: Andrew Lassalle <andrewlassalle@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: Amin Hassani <ahassani@chromium.org> Auto-Submit: Andrew Lassalle <andrewlassalle@chromium.org>
Diffstat (limited to 'scripts/update_payload/common.py')
-rw-r--r--scripts/update_payload/common.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/scripts/update_payload/common.py b/scripts/update_payload/common.py
index dfb8181a..b934cf88 100644
--- a/scripts/update_payload/common.py
+++ b/scripts/update_payload/common.py
@@ -16,8 +16,11 @@
"""Utilities for update payload processing."""
+from __future__ import absolute_import
from __future__ import print_function
+import base64
+
from update_payload import update_metadata_pb2
from update_payload.error import PayloadError
@@ -26,9 +29,9 @@ from update_payload.error import PayloadError
# Constants.
#
SIG_ASN1_HEADER = (
- '\x30\x31\x30\x0d\x06\x09\x60\x86'
- '\x48\x01\x65\x03\x04\x02\x01\x05'
- '\x00\x04\x20'
+ b'\x30\x31\x30\x0d\x06\x09\x60\x86'
+ b'\x48\x01\x65\x03\x04\x02\x01\x05'
+ b'\x00\x04\x20'
)
BRILLO_MAJOR_PAYLOAD_VERSION = 2
@@ -43,6 +46,7 @@ ROOTFS = 'root'
# Tuple of (name in system, name in protobuf).
CROS_PARTITIONS = ((KERNEL, KERNEL), (ROOTFS, 'rootfs'))
+
#
# Payload operation types.
#
@@ -138,7 +142,7 @@ def Read(file_obj, length, offset=None, hasher=None):
try:
data = file_obj.read(length)
- except IOError, e:
+ except IOError as e:
raise PayloadError('error reading from file (%s): %s' % (file_obj.name, e))
if len(data) != length:
@@ -164,7 +168,7 @@ def FormatExtent(ex, block_size=0):
def FormatSha256(digest):
"""Returns a canonical string representation of a SHA256 digest."""
- return digest.encode('base64').strip()
+ return base64.b64encode(digest).decode('utf-8')
#