releasetools: Replace print stmt with print().

So that it's compatible with Python 3.

Test: pylint --pylint=pylintrc

Change-Id: If06c135a492c94bedd713c8cbdf03155a502d5cd
This commit is contained in:
Tao Bao
2017-01-10 10:47:58 -08:00
parent 4dbe67cddc
commit 89fbb0f6d5
5 changed files with 109 additions and 105 deletions

View File

@@ -43,10 +43,12 @@ Usage: add_img_to_target_files [flag] target_files
are signing the target files.
"""
from __future__ import print_function
import sys
if sys.hexversion < 0x02070000:
print >> sys.stderr, "Python 2.7 or newer is required."
print("Python 2.7 or newer is required.", file=sys.stderr)
sys.exit(1)
import datetime
@@ -89,7 +91,7 @@ def AddSystem(output_zip, prefix="IMAGES/", recovery_img=None, boot_img=None):
prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "system.img")
if os.path.exists(prebuilt_path):
print "system.img already exists in %s, no need to rebuild..." % (prefix,)
print("system.img already exists in %s, no need to rebuild..." % (prefix,))
return prebuilt_path
def output_sink(fn, data):
@@ -98,7 +100,7 @@ def AddSystem(output_zip, prefix="IMAGES/", recovery_img=None, boot_img=None):
ofile.close()
if OPTIONS.rebuild_recovery:
print "Building new recovery patch"
print("Building new recovery patch")
common.MakeRecoveryPatch(OPTIONS.input_tmp, output_sink, recovery_img,
boot_img, info_dict=OPTIONS.info_dict)
@@ -123,7 +125,8 @@ def AddSystemOther(output_zip, prefix="IMAGES/"):
prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "system_other.img")
if os.path.exists(prebuilt_path):
print "system_other.img already exists in %s, no need to rebuild..." % (prefix,)
print("system_other.img already exists in %s, no need to rebuild..." % (
prefix,))
return
imgname = BuildSystemOther(OPTIONS.input_tmp, OPTIONS.info_dict)
@@ -141,7 +144,7 @@ def AddVendor(output_zip, prefix="IMAGES/"):
prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "vendor.img")
if os.path.exists(prebuilt_path):
print "vendor.img already exists in %s, no need to rebuild..." % (prefix,)
print("vendor.img already exists in %s, no need to rebuild..." % (prefix,))
return prebuilt_path
block_list = common.MakeTempFile(prefix="vendor-blocklist-", suffix=".map")
@@ -159,7 +162,7 @@ def BuildVendor(input_dir, info_dict, block_list=None):
def CreateImage(input_dir, info_dict, what, block_list=None):
print "creating " + what + ".img..."
print("creating " + what + ".img...")
img = common.MakeTempFile(prefix=what + "-", suffix=".img")
@@ -223,7 +226,8 @@ def AddUserdata(output_zip, prefix="IMAGES/"):
prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "userdata.img")
if os.path.exists(prebuilt_path):
print "userdata.img already exists in %s, no need to rebuild..." % (prefix,)
print("userdata.img already exists in %s, no need to rebuild..." % (
prefix,))
return
# Skip userdata.img if no size.
@@ -231,7 +235,7 @@ def AddUserdata(output_zip, prefix="IMAGES/"):
if not image_props.get("partition_size"):
return
print "creating userdata.img..."
print("creating userdata.img...")
# Use a fixed timestamp (01/01/2009) when packaging the image.
# Bug: 24377993
@@ -321,7 +325,7 @@ def AddCache(output_zip, prefix="IMAGES/"):
prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "cache.img")
if os.path.exists(prebuilt_path):
print "cache.img already exists in %s, no need to rebuild..." % (prefix,)
print("cache.img already exists in %s, no need to rebuild..." % (prefix,))
return
image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, "cache")
@@ -329,7 +333,7 @@ def AddCache(output_zip, prefix="IMAGES/"):
if "fs_type" not in image_props:
return
print "creating cache.img..."
print("creating cache.img...")
# Use a fixed timestamp (01/01/2009) when packaging the image.
# Bug: 24377993
@@ -364,7 +368,7 @@ def AddImagesToTargetFiles(filename):
if not OPTIONS.add_missing:
for n in input_zip.namelist():
if n.startswith("IMAGES/"):
print "target_files appears to already contain images."
print("target_files appears to already contain images.")
sys.exit(1)
try:
@@ -386,13 +390,13 @@ def AddImagesToTargetFiles(filename):
system_root_image = (OPTIONS.info_dict.get("system_root_image", None) == "true")
def banner(s):
print "\n\n++++ " + s + " ++++\n\n"
print("\n\n++++ " + s + " ++++\n\n")
prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", "boot.img")
boot_image = None
if os.path.exists(prebuilt_path):
banner("boot")
print "boot.img already exists in IMAGES/, no need to rebuild..."
print("boot.img already exists in IMAGES/, no need to rebuild...")
if OPTIONS.rebuild_recovery:
boot_image = common.GetBootableImage(
"IMAGES/boot.img", "boot.img", OPTIONS.input_tmp, "BOOT")
@@ -408,7 +412,7 @@ def AddImagesToTargetFiles(filename):
banner("recovery")
prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", "recovery.img")
if os.path.exists(prebuilt_path):
print "recovery.img already exists in IMAGES/, no need to rebuild..."
print("recovery.img already exists in IMAGES/, no need to rebuild...")
if OPTIONS.rebuild_recovery:
recovery_image = common.GetBootableImage(
"IMAGES/recovery.img", "recovery.img", OPTIONS.input_tmp,
@@ -474,7 +478,7 @@ def AddImagesToTargetFiles(filename):
img_name = line.strip() + ".img"
prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", img_name)
if os.path.exists(prebuilt_path):
print "%s already exists, no need to overwrite..." % (img_name,)
print("%s already exists, no need to overwrite..." % (img_name,))
continue
img_radio_path = os.path.join(OPTIONS.input_tmp, "RADIO", img_name)
@@ -530,16 +534,14 @@ def main(argv):
sys.exit(1)
AddImagesToTargetFiles(args[0])
print "done."
print("done.")
if __name__ == '__main__':
try:
common.CloseInheritedPipes()
main(sys.argv[1:])
except common.ExternalError as e:
print
print " ERROR: %s" % (e,)
print
print("\n ERROR: %s\n" % (e,))
sys.exit(1)
finally:
common.Cleanup()