Skip to content

Commit

Permalink
Test py migration - 2
Browse files Browse the repository at this point in the history
Signed-off-by: celadon <[email protected]>
  • Loading branch information
celadon authored and SaliniVenate committed Aug 19, 2024
1 parent 574c7a3 commit 56de869
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 46 deletions.
8 changes: 4 additions & 4 deletions bootloader_from_zip
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def main(argv):
sys.exit(1)

if not OPTIONS.zipfile:
print "--zipfile is required"
print ("--zipfile is required")
common.Usage(__doc__)
sys.exit(1)

tf = tempfile.NamedTemporaryFile()
tf.write("foo")
tf.write(b"foo")
tf.flush()

extra_files = OPTIONS.bootimage
Expand All @@ -106,9 +106,9 @@ if __name__ == '__main__':
try:
common.CloseInheritedPipes()
main(sys.argv[1:])
except common.ExternalError, e:
except (common.ExternalError,e):
print
print " ERROR: %s" % (e,)
print (" ERROR: %s" % (e,))
print
sys.exit(1)

2 changes: 1 addition & 1 deletion create_gpt_image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
# -*- coding: utf-8; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-

# Copyright (c) 2014, Intel Corporation.
Expand Down
20 changes: 10 additions & 10 deletions generate_factory_images
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import os

_FLASHALL_FILENAME = "flash-all.sh"
# chmod (octal) -rwxr-x--x
_PERMS = 0751
_PERMS = 0o751
_FLASH_HEADER = """#!/bin/bash
# Copyright 2012 The Android Open Source Project
Expand Down Expand Up @@ -103,7 +103,7 @@ def ConvertToDOSFormat(filename):


def AddFlashScript(filename, tar, commands, windows):
print "Archiving", filename
print ("Archiving", filename)
tf = tempfile.NamedTemporaryFile(delete=False)
if (windows):
tf.write(_WIN_FLASH_HEADER)
Expand Down Expand Up @@ -146,8 +146,8 @@ class CommandlineParser(ArgumentParser):
self.description = __doc__

def error(self, message):
print >>stderr, "ERROR: {}".format(message)
print >>stderr, "\n------\n"
print ("ERROR: {}".format(message), file=sys.stderr)
print ("\n------\n", file=sys.stderr)
self.print_help()
exit(2)

Expand Down Expand Up @@ -230,31 +230,31 @@ def main():
archive_name = args.output

# Create Archive
print "Creating archive: " + archive_name
print ("Creating archive: " + archive_name)
tar = TarOpen(archive_name, "w:gz")

for src_path, dst_path in files:
print "Archiving " + src_path
print ("Archiving " + src_path)
RequireFile(src_path)
tar.add(src_path, arcname=dst_path)

# 'fastboot update' covers the additional AOSP pieces, add this to the
# command list now
commands.append(UpdateCommand(update_fn, True))
print "Archiving " + args.update_archive
print ("Archiving " + args.update_archive)
RequireFile(args.update_archive)
tar.add(args.update_archive, update_fn)
AddFlashScript(_FLASHALL_FILENAME, tar, commands, windows=False)
AddFlashScript(_WIN_FLASHALL_FILENAME, tar, commands, windows=True)

tar.close()

print "Done."
print ("Done.")

if __name__ == "__main__":
try:
exit(main())
except Usage, err:
print >>stderr, "ERROR: {}".format(err.msg)
print >>stderr, " for help use --help"
print ("ERROR: {}".format(err.msg), file=sys.stderr)
print (" for help use --help", file=sys.stderr)
exit(2)
8 changes: 4 additions & 4 deletions releasetools/bootloader_from_target_files
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (C) 2008 The Android Open Source Project
#
Expand Down Expand Up @@ -61,7 +61,7 @@ def main(argv):
common.Usage(__doc__)
sys.exit(1)

print "unzipping target-files..."
print ("unzipping target-files...")
#OPTIONS.input_tmp = common.UnzipTemp(args[0])
OPTIONS.input_tmp = args[0]
#input_zip = zipfile.ZipFile(args[0], "r")
Expand Down Expand Up @@ -89,9 +89,9 @@ if __name__ == '__main__':
try:
common.CloseInheritedPipes()
main(sys.argv[1:])
except common.ExternalError, e:
except common.ExternalError as e:
print
print " ERROR: %s" % (e,)
print (" ERROR: %s" %, (e,))
print
sys.exit(1)
finally:
Expand Down
8 changes: 7 additions & 1 deletion releasetools/flash_cmd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,13 @@ def parse_config(ips, variant, platform):
results_list = []
for k,v in results.items():
results_list.append((k,v))
flist = [f.rsplit(':', 1) for f in set(files)]
unique_files = []
for file in files:
# If the number is not already in the unique_numbers list, add it
if file not in unique_files:
unique_files.append(file)

flist = [f.rsplit(':', 1) for f in unique_files]
return results_list, flist


Expand Down
42 changes: 22 additions & 20 deletions releasetools/flashfiles_from_target_files
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ class VariantIpGenerator:

def __add_variant_flashfile(self, ip, variant):
variant_flashfile = self.flashfile + "_" + variant + ".ini"
print "Variant flashfile = %s"%variant_flashfile
print ("Variant flashfile = %s"%variant_flashfile)
# Sanity check to avoid future silent removal
eg = self.empty_groups(ip)
if eg:
raise AssertionError("Unexpected malformed section %s" % eg[0])

if os.path.isfile(variant_flashfile):
print "Reading INI configuration for %s ..."%variant
print ("Reading INI configuration for %s ..."%variant)
with open(variant_flashfile, "r") as f:
ip.parse(f)
self.variant_files = self.variant_files_common
Expand All @@ -125,7 +125,7 @@ class VariantIpGenerator:
# This may happen when a mixin (platform level) disables a feature, while
# local flashfile.ini (variant level) is kept and customizes this feature.
for s in self.empty_groups(ip):
print "Removing malformed section : ", s
print ("Removing malformed section : ", s)
ip.delete_section(s)

def empty_groups(self, ip):
Expand Down Expand Up @@ -214,7 +214,7 @@ def getFromZip(zip_path, filename):
with zipfile.ZipFile(zip_path, "r") as zf:
data = zf.open(filename).read()
info = zf.getinfo(filename)
return (common.File(filename, data), (info.external_attr >> 16L) & 0xFFFF)
return (common.File(filename, data), (info.external_attr >> 16) & 0xFFFF)

def getProvdataVariants(unpack_dir):
variants = []
Expand Down Expand Up @@ -250,7 +250,7 @@ def process_image(unpack_dir, dest_zip, source, target, configs, variant=None, t
if target_out in flashfile_content:
return
else:
print "-- Adding", target_out
print ("-- Adding", target_out)
# Default is no special permissions
perms = None
# retrieve file from target file package based on source & target strings
Expand Down Expand Up @@ -310,7 +310,7 @@ def process_image_fast(product_out, flashfiles_out, source, target, variant=None
if target_out in flashfile_content:
return

print "-- Adding", target_out
print ("-- Adding", target_out)
outfile = os.path.join(flashfiles_out, target_out)
if not os.path.exists(os.path.dirname(outfile)):
os.mkdir(os.path.dirname(outfile))
Expand Down Expand Up @@ -374,7 +374,7 @@ def main(argv):

flashfile = getIntermediates(product_out, "flashfiles", "flashfiles")
else:
print "Unzipping target-files..."
print ("Unzipping target-files...")
unpack_dir = common.UnzipTemp(args[0])
if OPTIONS.add_image:
input_super = os.path.join(unpack_dir, "IMAGES")
Expand All @@ -392,39 +392,39 @@ def main(argv):

# Retrieve "generic" PFT instructions from target file package
if os.path.isfile(flashfile + ".ini"):
print "Reading INI configuration..."
print ("Reading INI configuration...")
with open(flashfile + ".ini", "r") as f:
ip = iniparser.IniParser()
ip.parse(f)
configs, files = flash_cmd_generator.parse_config([ip], build_type, platform)
elif os.path.isfile(flashfile + ".json") and not OPTIONS.unified_variants:
print "Reading JSON configuration..."
print ("Reading JSON configuration...")
with open(flashfile + ".json", "r") as f:
conf = json.loads(f.read())
configs, files = flashxml.parse_config(conf, build_type, platform)
elif os.path.isfile(flashfile + "_fls.json") and not OPTIONS.unified_variants:
if not OPTIONS.mv_config_default:
common.Usage(__doc__)
sys.exit(1)
print "Reading JSON FLS configuration..."
print ("Reading JSON FLS configuration...")
with open(flashfile + "_fls.json", "r") as f:
conf = json.loads(f.read())
configs, files = flashflsxml.parse_config(conf, build_type, platform, OPTIONS.mv_config_default, system)
else:
print "Exiting, Missing correct flashfile configuration for generating Flashfiles."
print ("Exiting, Missing correct flashfile configuration for generating Flashfiles.")
sys.exit(1)

if OPTIONS.fast:
fastff_dir = args[1]
# If mega flashfile is enabled, create multi-variant version of PFT instructions
if OPTIONS.unified_variants or OPTIONS.variants :
print "Adding variant specific configurations to ip..."
print ("Adding variant specific configurations to ip...")
vip = VariantIpGenerator(ip, configs, OPTIONS.variants, variant_files, flashfile)
vip.generate_variant_ip()
configs, cmd_files = flash_cmd_generator.parse_config(vip.variant_ips, build_type, platform)
cmd_files = set([i for _,i in cmd_files])

print "Adding required binaries..."
print ("Adding required binaries...")
for src, target in files:
if OPTIONS.variants:
for variant in OPTIONS.variants:
Expand All @@ -442,22 +442,22 @@ def main(argv):
src,target = file.split(":")
process_image_fast(product_out, fastff_dir, src, target, variant, variantFilename(target, variant))

print "Generating JSON flash configuration files..."
print ("Generating JSON flash configuration files...")
for fn, data in configs:
with open(os.path.join(fastff_dir,fn), 'w') as file:
file.write(data)
else:
with zipfile.ZipFile(args[1], "w", zipfile.ZIP_DEFLATED,allowZip64=True) as dest_zip:
# If mega flashfile is enabled, create multi-variant version of PFT instructions
if OPTIONS.unified_variants or OPTIONS.variants :
print "Adding variant specific configurations to ip..."
print ("Adding variant specific configurations to ip...")
vip = VariantIpGenerator(ip, configs, OPTIONS.variants, variant_files, flashfile)
vip.generate_variant_ip()
configs, cmd_files = flash_cmd_generator.parse_config(vip.variant_ips, build_type, platform)
cmd_files = set([i for _,i in cmd_files])

# Using "generic" instructions as reference, grab required files & insert into flashfile zip
print "Adding required binaries..."
print ("Adding required binaries...")
for src, target in files:
if OPTIONS.variants:
for variant in OPTIONS.variants:
Expand All @@ -477,19 +477,21 @@ def main(argv):
process_image(unpack_dir, dest_zip, src, target, configs, variant, variantFilename(target, variant))

# Write flash_cmd_generator parsed PFT flashing instructions to file & insert into flashfile zip
print "Generating JSON flash configuration files..."
print ("Generating JSON flash configuration files...")
for fn, data in configs:
if isinstance(data, str):
data = data.encode('utf-8')
ifile = common.File(fn, data)
ifile.AddToZip(dest_zip)
print "All done."
print ("All done.")

if __name__ == '__main__':
try:
common.CloseInheritedPipes()
main(sys.argv[1:])
except common.ExternalError, e:
except common.ExternalError as e:
print
print " ERROR: %s" % (e,)
print (" ERROR: %s" % (e,))
print
sys.exit(1)
finally:
Expand Down
4 changes: 2 additions & 2 deletions releasetools/intel_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def GetBootloaderImageFromTFP(unpack_dir, autosize=False, extra_files=None, vari
block_size=info["block_size"],
extra_files=extra_files)

bootloader = open(filename)
bootloader = open(filename,'rb')
data = bootloader.read()
bootloader.close()
os.unlink(filename)
Expand Down Expand Up @@ -482,7 +482,7 @@ def MakeVFATFilesystem(root_zip, filename, title="ANDROIDIA", size=0, block_size
cmd = ["mkdosfs"]
if block_size:
cmd.extend(["-S", str(block_size)])
cmd.extend(["-n", title, "-C", filename, str(size / 1024)])
cmd.extend(["-n", title, "-C", filename, str(size // 1024)])
try:
p = common.Run(cmd)
except Exception as exc:
Expand Down
2 changes: 1 addition & 1 deletion releasetools/ota_deployment_fixup
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

"""
Fix-up the product information in an OTA package to match deployment
Expand Down
2 changes: 1 addition & 1 deletion releasetools/sign_target_files_efis
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (C) 2014 The Android Open Source Project
#
Expand Down
2 changes: 1 addition & 1 deletion releasetools/verifybootimg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

import tempfile
import argparse
Expand Down
2 changes: 1 addition & 1 deletion tasks/checkvendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,4 @@ def main():
return 0

if __name__ == "__main__":
exit(main())
sys.exit(main())

0 comments on commit 56de869

Please sign in to comment.