Control: tag -1 patch

The attached patch ports simg_dump.py to Python 3.

As far as I can tell, android-sdk-libsparse-utils is the only package requiring 
Python 2, and the only python file in that package is
simg_dump.

I've tested this by comparing the output on a valid sparse image file (both 
verbose, and csv).  They are identical.

Antonio
Description: Port simg_dump to Python 3.
Author: Antonio Russo <antonio.e.ru...@gmail.com>
Forwarded: no
Last-Update: 2019-01-05

Index: android-platform-system-core/libsparse/simg_dump.py
===================================================================
--- android-platform-system-core.orig/libsparse/simg_dump.py
+++ android-platform-system-core/libsparse/simg_dump.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 
 # Copyright (C) 2012 The Android Open Source Project
 #
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from __future__ import print_function
+
 import csv
 import getopt
 import hashlib
@@ -47,7 +47,7 @@ def main():
     opts, args = getopt.getopt(sys.argv[1:],
                                "vsc:",
                                ["verbose", "showhash", "csvfile"])
-  except getopt.GetoptError, e:
+  except getopt.GetoptError as e:
     print(e)
     usage(me)
   for o, a in opts:
@@ -66,7 +66,7 @@ def main():
     usage(me)
 
   if csvfilename:
-    csvfile = open(csvfilename, "wb")
+    csvfile = open(csvfilename, "w", newline='')
     csvwriter = csv.writer(csvfile)
 
   output = verbose or csvfilename or showhash
@@ -121,7 +121,7 @@ def main():
                           "output offset", "output blocks", "type", "hash"])
 
     offset = 0
-    for i in xrange(1, total_chunks + 1):
+    for i in range(1, total_chunks + 1):
       header_bin = FH.read(12)
       header = struct.unpack("<2H2I", header_bin)
       chunk_type = header[0]
@@ -160,7 +160,7 @@ def main():
           if showhash:
             h = hashlib.sha1()
             data = fill_bin * (blk_sz / 4);
-            for block in xrange(chunk_sz):
+            for block in range(chunk_sz):
               h.update(data)
             curhash = h.hexdigest()
       elif chunk_type == 0xCAC3:

Reply via email to