From 86b529a23eb8f7800024cfc37c7e691183490199 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 19 Jun 2019 17:03:37 -0700 Subject: [PATCH] releasetools: Make apex_utils Python 3 compatible. In order to get a Python 2 and 3 compatible re-raise behavior, this CL removes the stack traceback for the lines within apex_util module (i.e. sys.exc_info()[2]). It's not a big loss in practice, since we only have one line within the try-except block (`common.RunAndCheckOutput()`) that's no longer reported in the traceback. Using `six` module could better solve this, but only after building releasetools as python_binary_host modules where we can properly handle the module dependency. Bug: 131631303 Test: TreeHugger Test: `python -m unittest test_apex_utils` Test: `python3 -m unittest test_apex_utils` Change-Id: I0c5a72ec9fad5ff9d8c9c94d29e813e433ec2921 --- tools/releasetools/apex_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/releasetools/apex_utils.py b/tools/releasetools/apex_utils.py index fb4ca7667f..07511258cc 100644 --- a/tools/releasetools/apex_utils.py +++ b/tools/releasetools/apex_utils.py @@ -59,9 +59,9 @@ def SignApexPayload(payload_file, payload_key_path, payload_key_name, algorithm, try: common.RunAndCheckOutput(cmd) except common.ExternalError as e: - raise ApexSigningError, \ + raise ApexSigningError( 'Failed to sign APEX payload {} with {}:\n{}'.format( - payload_file, payload_key_path, e), sys.exc_info()[2] + payload_file, payload_key_path, e)) # Verify the signed payload image with specified public key. logger.info('Verifying %s', payload_file) @@ -75,9 +75,9 @@ def VerifyApexPayload(payload_file, payload_key): try: common.RunAndCheckOutput(cmd) except common.ExternalError as e: - raise ApexSigningError, \ + raise ApexSigningError( 'Failed to validate payload signing for {} with {}:\n{}'.format( - payload_file, payload_key, e), sys.exc_info()[2] + payload_file, payload_key, e)) def ParseApexPayloadInfo(payload_path): @@ -100,9 +100,9 @@ def ParseApexPayloadInfo(payload_path): try: output = common.RunAndCheckOutput(cmd) except common.ExternalError as e: - raise ApexInfoError, \ + raise ApexInfoError( 'Failed to get APEX payload info for {}:\n{}'.format( - payload_path, e), sys.exc_info()[2] + payload_path, e)) # Extract the Algorithm / Salt / Prop info from payload (i.e. an image signed # with avbtool). For example,