summaryrefslogtreecommitdiff
path: root/scripts/payload_info.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/payload_info.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/payload_info.py')
-rwxr-xr-xscripts/payload_info.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/scripts/payload_info.py b/scripts/payload_info.py
index bb7f8a41..965bb76f 100755
--- a/scripts/payload_info.py
+++ b/scripts/payload_info.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 The Android Open Source Project
@@ -18,15 +18,17 @@
"""payload_info: Show information about an update payload."""
+from __future__ import absolute_import
from __future__ import print_function
import argparse
-import itertools
import sys
import textwrap
+from six.moves import range
import update_payload
+
MAJOR_PAYLOAD_VERSION_BRILLO = 2
def DisplayValue(key, value):
@@ -40,12 +42,12 @@ def DisplayValue(key, value):
def DisplayHexData(data, indent=0):
"""Print out binary data as a hex values."""
for off in range(0, len(data), 16):
- chunk = data[off:off + 16]
+ chunk = bytearray(data[off:off + 16])
print(' ' * indent +
- ' '.join('%.2x' % ord(c) for c in chunk) +
+ ' '.join('%.2x' % c for c in chunk) +
' ' * (16 - len(chunk)) +
' | ' +
- ''.join(c if 32 <= ord(c) < 127 else '.' for c in chunk))
+ ''.join(chr(c) if 32 <= c < 127 else '.' for c in chunk))
class PayloadCommand(object):
@@ -144,7 +146,7 @@ class PayloadCommand(object):
op_dict = update_payload.common.OpType.NAMES
print('%s:' % name)
- for op, op_count in itertools.izip(operations, itertools.count()):
+ for op_count, op in enumerate(operations):
print(' %d: %s' % (op_count, op_dict[op.type]))
if op.HasField('data_offset'):
print(' Data offset: %s' % op.data_offset)
@@ -178,8 +180,8 @@ class PayloadCommand(object):
last_ext = curr_ext
# Old and new partitions are read once during verification.
- read_blocks += partition.old_partition_info.size / manifest.block_size
- read_blocks += partition.new_partition_info.size / manifest.block_size
+ read_blocks += partition.old_partition_info.size // manifest.block_size
+ read_blocks += partition.new_partition_info.size // manifest.block_size
stats = {'read_blocks': read_blocks,
'written_blocks': written_blocks,
@@ -212,7 +214,7 @@ class PayloadCommand(object):
def main():
parser = argparse.ArgumentParser(
description='Show information about an update payload.')
- parser.add_argument('payload_file', type=file,
+ parser.add_argument('payload_file', type=argparse.FileType('rb'),
help='The update payload file.')
parser.add_argument('--list_ops', default=False, action='store_true',
help='List the install operations and their extents.')
@@ -224,5 +226,6 @@ def main():
PayloadCommand(args).Run()
+
if __name__ == '__main__':
sys.exit(main())