Convert extract_lsdump to python3 am: 97e65cac9f am: ca338da6d4 am: a8a0229694

Original change: https://android-review.googlesource.com/c/platform/test/vts-testcase/vndk/+/1346264

Change-Id: I85f8dc7a7e401b08a65c9f9dfae7247bc3e2a36f
diff --git a/dependency/vts_vndk_dependency_test.py b/dependency/vts_vndk_dependency_test.py
index fb0431a..4e37c90 100644
--- a/dependency/vts_vndk_dependency_test.py
+++ b/dependency/vts_vndk_dependency_test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright (C) 2020 The Android Open Source Project
 #
diff --git a/golden/Android.bp b/golden/Android.bp
index c9abdaa..f5230f4 100644
--- a/golden/Android.bp
+++ b/golden/Android.bp
@@ -18,11 +18,11 @@
     srcs: ["extract_lsdump.py"],
     version: {
         py2: {
-            enabled: true,
-            embedded_launcher: true,
+            enabled: false,
         },
         py3: {
-            enabled: false,
+            enabled: true,
+            embedded_launcher: true,
         },
     }
 }
diff --git a/golden/extract_lsdump.py b/golden/extract_lsdump.py
index fd42be6..8849d48 100755
--- a/golden/extract_lsdump.py
+++ b/golden/extract_lsdump.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright (C) 2018 The Android Open Source Project
 #
@@ -19,6 +19,7 @@
 import gzip
 import json
 import os
+import sys
 import zipfile
 
 
@@ -45,27 +46,27 @@
 def _GetTypeSymbol(record_type):
     """Gets the mangled name of a record type.
 
-    Before Android R, unique_id was mangled name starting with "_ZTS".
+    Before Android R, unique_id was mangled name starting with '_ZTS'.
     linker_set_key was unmangled.
     Since Android R, unique_id has been removed, and linker_set_key has
-    been changed to mangled name starting with "_ZTI".
+    been changed to mangled name starting with '_ZTI'.
 
     Args:
         record_type: An AttrDict, a record type in lsdump.
 
     Returns:
-        A string, the mangled name starting with "_ZTI".
+        A string, the mangled name starting with '_ZTI'.
     """
-    if "unique_id" in record_type:
-        return record_type["unique_id"].replace("_ZTS", "_ZTI", 1)
-    return record_type["linker_set_key"]
+    if 'unique_id' in record_type:
+        return record_type['unique_id'].replace('_ZTS', '_ZTI', 1)
+    return record_type['linker_set_key']
 
 
 def _OpenFileOrGzipped(file_name):
     """Opens a file that is either in gzip or uncompressed format.
 
-    If file_name ends with '.gz' then return gzip.open(file_name, 'rb'),
-    else return open(file_name, 'rb').
+    If file_name ends with '.gz' then an opened gzip text file, else return an
+    opened text file.
 
     Args:
         file_name: The file name to open.
@@ -77,8 +78,8 @@
         IOError if fails to open.
     """
     if file_name.endswith('.gz'):
-        return gzip.open(file_name, 'rb')
-    return open(file_name, 'rb')
+        return gzip.open(file_name, 'rt')
+    return open(file_name, 'r')
 
 
 def _ConsumeOffset(tok, beg=0):
@@ -235,8 +236,8 @@
 def _ParseLsdumpZipFile(lsdump_zip, output_zip):
     """Converts zipped lsdump files to the dump files for ABI test."""
     for name in lsdump_zip.namelist():
-        if name.endswith(".lsdump"):
-            with lsdump_zip.open(name, mode="r") as lsdump_file:
+        if name.endswith('.lsdump'):
+            with lsdump_zip.open(name, mode='r') as lsdump_file:
                 output_dump = _ParseLsdumpFileObject(lsdump_file)
             output_str = json.dumps(output_dump, indent=1,
                                     separators=(',', ':'))
@@ -262,7 +263,7 @@
 
         with _OpenFileOrGzipped(input_path) as lsdump_file:
             output_dump = _ParseLsdumpFileObject(lsdump_file)
-        with open(output_path, 'wb') as output_file:
+        with open(output_path, 'w') as output_file:
             json.dump(output_dump, output_file,
                       indent=1, separators=(',', ':'))
     except (IOError, OSError) as e:
@@ -288,13 +289,13 @@
             with zipfile.ZipFile(args.output_path, mode='w',
                                  compression=zipfile.ZIP_STORED) as output_zip:
                 _ParseLsdumpZipFile(input_zip, output_zip)
-        exit(0)
+        sys.exit(0)
 
     try:
         ParseLsdumpFile(args.input_path, args.output_path)
     except LsdumpError as e:
         print(e)
-        exit(1)
+        sys.exit(1)
 
 
 if __name__ == '__main__':
diff --git a/utils.py b/utils.py
index 65b2eee..b5cc47d 100644
--- a/utils.py
+++ b/utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright (C) 2020 The Android Open Source Project
 #