diff options
Diffstat (limited to 'tools/releasetools/ota_from_target_files.py')
-rwxr-xr-x | tools/releasetools/ota_from_target_files.py | 104 |
1 files changed, 53 insertions, 51 deletions
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index 3e72ede2d..6e5124a93 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -106,10 +106,12 @@ Usage: ota_from_target_files [flags] input_target_files output_ota_package """ +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 multiprocessing @@ -150,7 +152,7 @@ OPTIONS.override_prop = False def MostPopularKey(d, default): """Given a dict, return the key corresponding to the largest value. Returns 'default' if the dict is empty.""" - x = [(v, k) for (k, v) in d.iteritems()] + x = list(d.items()) if not x: return default x.sort() @@ -269,14 +271,14 @@ class Item(object): def Dump(self, indent=0): if self.uid is not None: - print "%s%s %d %d %o" % ( - " " * indent, self.name, self.uid, self.gid, self.mode) + print("%s%s %d %d %o" % ( + " " * indent, self.name, self.uid, self.gid, self.mode)) else: - print "%s%s %s %s %s" % ( - " " * indent, self.name, self.uid, self.gid, self.mode) + print("%s%s %s %s %s" % ( + " " * indent, self.name, self.uid, self.gid, self.mode)) if self.is_dir: - print "%s%s" % (" "*indent, self.descendants) - print "%s%s" % (" "*indent, self.best_subtree) + print("%s%s" % (" "*indent, self.descendants)) + print("%s%s" % (" "*indent, self.best_subtree)) for i in self.children: i.Dump(indent=indent+1) @@ -300,7 +302,7 @@ class Item(object): d = self.descendants for i in self.children: if i.is_dir: - for k, v in i.CountChildMetadata().iteritems(): + for k, v in i.CountChildMetadata().items(): d[k] = d.get(k, 0) + v else: k = (i.uid, i.gid, None, i.mode, i.selabel, i.capabilities) @@ -312,7 +314,7 @@ class Item(object): # First, find the (uid, gid) pair that matches the most # descendants. ug = {} - for (uid, gid, _, _, _, _), count in d.iteritems(): + for (uid, gid, _, _, _, _), count in d.items(): ug[(uid, gid)] = ug.get((uid, gid), 0) + count ug = MostPopularKey(ug, (0, 0)) @@ -322,7 +324,7 @@ class Item(object): best_fmode = (0, 0o644) best_selabel = (0, None) best_capabilities = (0, None) - for k, count in d.iteritems(): + for k, count in d.items(): if k[:2] != ug: continue if k[2] is not None and count >= best_dmode[0]: @@ -483,11 +485,11 @@ def GetImage(which, tmpdir, info_dict): path = os.path.join(tmpdir, "IMAGES", which + ".img") mappath = os.path.join(tmpdir, "IMAGES", which + ".map") if os.path.exists(path) and os.path.exists(mappath): - print "using %s.img from target-files" % (which,) + print("using %s.img from target-files" % which) # This is a 'new' target-files, which already has the image in it. else: - print "building %s.img from target-files" % (which,) + print("building %s.img from target-files" % which) # This is an 'old' target-files, which does not contain images # already built. Build them. @@ -620,8 +622,8 @@ else if get_stage("%(bcb_dev)s") == "3/3" then CopyInstallTools(output_zip) script.UnpackPackageDir("install", "/tmp/install") - script.SetPermissionsRecursive("/tmp/install", 0, 0, 0755, 0644, None, None) - script.SetPermissionsRecursive("/tmp/install/bin", 0, 0, 0755, 0755, None, None) + script.SetPermissionsRecursive("/tmp/install", 0, 0, 0o755, 0o644, None, None) + script.SetPermissionsRecursive("/tmp/install/bin", 0, 0, 0o755, 0o755, None, None) if OPTIONS.backuptool: script.Mount("/system") @@ -759,7 +761,7 @@ def WritePolicyConfig(file_name, output_zip): def WriteMetadata(metadata, output_zip): common.ZipWriteStr(output_zip, "META-INF/com/android/metadata", "".join(["%s=%s\n" % kv - for kv in sorted(metadata.iteritems())])) + for kv in sorted(metadata.items())])) def LoadPartitionFiles(z, partition): @@ -969,8 +971,8 @@ else if get_stage("%(bcb_dev)s") != "3/3" then else: include_full_boot = False - print "boot target: %d source: %d diff: %d" % ( - target_boot.size, source_boot.size, len(d)) + print("boot target: %d source: %d diff: %d" % ( + target_boot.size, source_boot.size, len(d))) common.ZipWriteStr(output_zip, "patch/boot.img.p", d) @@ -1006,19 +1008,19 @@ else if OPTIONS.two_step: common.ZipWriteStr(output_zip, "boot.img", target_boot.data) script.WriteRawImage("/boot", "boot.img") - print "writing full boot image (forced by two-step mode)" + print("writing full boot image (forced by two-step mode)") if not OPTIONS.two_step: if updating_boot: if include_full_boot: - print "boot image changed; including full." + print("boot image changed; including full.") script.Print("Installing boot image...") script.WriteRawImage("/boot", "boot.img") else: # Produce the boot image by applying a patch to the current # contents of the boot partition, and write it back to the # partition. - print "boot image changed; including patch." + print("boot image changed; including patch.") script.Print("Patching boot image...") script.ShowProgress(0.1, 10) script.ApplyPatch("%s:%s:%d:%s:%d:%s" @@ -1029,7 +1031,7 @@ else target_boot.size, target_boot.sha1, source_boot.sha1, "patch/boot.img.p") else: - print "boot image unchanged; skipping." + print("boot image unchanged; skipping.") # Do device-specific installation (eg, write radio image). device_specific.IncrementalOTA_InstallEnd() @@ -1056,9 +1058,9 @@ endif; class FileDifference(object): def __init__(self, partition, source_zip, target_zip, output_zip): self.deferred_patch_list = None - print "Loading target..." + print("Loading target...") self.target_data = target_data = LoadPartitionFiles(target_zip, partition) - print "Loading source..." + print("Loading source...") self.source_data = source_data = LoadPartitionFiles(source_zip, partition) self.verbatim_targets = verbatim_targets = [] @@ -1085,14 +1087,14 @@ class FileDifference(object): assert fn == tf.name sf = ClosestFileMatch(tf, matching_file_cache, renames) if sf is not None and sf.name != tf.name: - print "File has moved from " + sf.name + " to " + tf.name + print("File has moved from " + sf.name + " to " + tf.name) renames[sf.name] = tf if sf is None or fn in OPTIONS.require_verbatim: # This file should be included verbatim if fn in OPTIONS.prohibit_verbatim: raise common.ExternalError("\"%s\" must be sent verbatim" % (fn,)) - print "send", fn, "verbatim" + print("send", fn, "verbatim") tf.AddToZip(output_zip) verbatim_targets.append((fn, tf.size, tf.sha1)) if fn in target_data.keys(): @@ -1177,8 +1179,8 @@ class FileDifference(object): def EmitRenames(self, script): if len(self.renames) > 0: script.Print("Renaming files...") - for src, tgt in self.renames.iteritems(): - print "Renaming " + src + " to " + tgt.name + for src, tgt in self.renames.items(): + print("Renaming " + src + " to " + tgt.name) script.RenameFile(src, tgt.name) @@ -1321,8 +1323,8 @@ else if get_stage("%(bcb_dev)s") != "3/3" then """ % bcb_dev) # Dump fingerprints - script.Print("Source: %s" % (source_fp,)) - script.Print("Target: %s" % (target_fp,)) + script.Print("Source: %s" % source_fp) + script.Print("Target: %s" % target_fp) script.Print("Verifying current system...") @@ -1336,8 +1338,8 @@ else if get_stage("%(bcb_dev)s") != "3/3" then if updating_boot: d = common.Difference(target_boot, source_boot) _, _, d = d.ComputePatch() - print "boot target: %d source: %d diff: %d" % ( - target_boot.size, source_boot.size, len(d)) + print("boot target: %d source: %d diff: %d" % ( + target_boot.size, source_boot.size, len(d))) common.ZipWriteStr(output_zip, "patch/boot.img.p", d) @@ -1376,7 +1378,7 @@ else if OPTIONS.two_step: common.ZipWriteStr(output_zip, "boot.img", target_boot.data) script.WriteRawImage("/boot", "boot.img") - print "writing full boot image (forced by two-step mode)" + print("writing full boot image (forced by two-step mode)") script.Print("Removing unneeded files...") system_diff.RemoveUnneededFiles(script, ("/system/recovery.img",)) @@ -1411,9 +1413,9 @@ else source_boot.sha1, "patch/boot.img.p") so_far += target_boot.size script.SetProgress(so_far / total_patch_size) - print "boot image changed; including." + print("boot image changed; including.") else: - print "boot image unchanged; skipping." + print("boot image unchanged; skipping.") system_items = ItemSet("system", "META/filesystem_config.txt") if vendor_diff: @@ -1438,9 +1440,9 @@ else target_recovery, target_boot) script.DeleteFiles(["/system/recovery-from-boot.p", "/system/etc/install-recovery.sh"]) - print "recovery image changed; including as patch from boot." + print("recovery image changed; including as patch from boot.") else: - print "recovery image unchanged; skipping." + print("recovery image unchanged; skipping.") script.ShowProgress(0.1, 10) @@ -1610,7 +1612,7 @@ def main(argv): OPTIONS.verify = True elif o == "--block": OPTIONS.block_based = True - elif o in ("-b", "--binary"): + elif o in ("-b", "--binary",): OPTIONS.updater_binary = a elif o in ("--no_fallback_to_full",): OPTIONS.fallback_to_full = False @@ -1620,11 +1622,11 @@ def main(argv): except ValueError: raise ValueError("Cannot parse value %r for option %r - expecting " "a float" % (a, o)) - elif o in ("--backup"): + elif o in ("--backup",): OPTIONS.backuptool = bool(a.lower() == 'true') - elif o in ("--override_device"): + elif o in ("--override_device",): OPTIONS.override_device = a - elif o in ("--override_prop"): + elif o in ("--override_prop",): OPTIONS.override_prop = bool(a.lower() == 'true') else: return False @@ -1663,7 +1665,7 @@ def main(argv): if OPTIONS.extra_script is not None: OPTIONS.extra_script = open(OPTIONS.extra_script).read() - print "unzipping target target-files..." + print("unzipping target target-files...") OPTIONS.input_tmp, input_zip = common.UnzipTemp(args[0]) OPTIONS.target_tmp = OPTIONS.input_tmp @@ -1678,7 +1680,7 @@ def main(argv): OPTIONS.input_tmp, "BOOT", "RAMDISK", "file_contexts") if OPTIONS.verbose: - print "--- target info ---" + print("--- target info ---") common.DumpInfoDict(OPTIONS.info_dict) # If the caller explicitly specified the device-specific extensions @@ -1691,7 +1693,7 @@ def main(argv): if OPTIONS.device_specific is None: from_input = os.path.join(OPTIONS.input_tmp, "META", "releasetools.py") if os.path.exists(from_input): - print "(using device-specific extensions from target_files)" + print("(using device-specific extensions from target_files)") OPTIONS.device_specific = from_input else: OPTIONS.device_specific = OPTIONS.info_dict.get("tool_extensions", None) @@ -1726,7 +1728,7 @@ def main(argv): break else: - print "unzipping source target-files..." + print("unzipping source target-files...") OPTIONS.source_tmp, source_zip = common.UnzipTemp( OPTIONS.incremental_source) OPTIONS.target_info_dict = OPTIONS.info_dict @@ -1739,7 +1741,7 @@ def main(argv): "default_system_dev_certificate", "build/target/product/security/testkey") if OPTIONS.verbose: - print "--- source info ---" + print("--- source info ---") common.DumpInfoDict(OPTIONS.source_info_dict) try: WriteIncrementalOTAPackage(input_zip, source_zip, output_zip) @@ -1748,7 +1750,7 @@ def main(argv): except ValueError: if not OPTIONS.fallback_to_full: raise - print "--- failed to build incremental; falling back to full ---" + print("--- failed to build incremental; falling back to full ---") OPTIONS.incremental_source = None common.ZipClose(output_zip) @@ -1756,7 +1758,7 @@ def main(argv): SignOutput(temp_zip_file.name, args[1]) temp_zip_file.close() - print "done." + print("done.") if __name__ == '__main__': @@ -1764,9 +1766,9 @@ if __name__ == '__main__': common.CloseInheritedPipes() main(sys.argv[1:]) except common.ExternalError as e: - print - print " ERROR: %s" % (e,) - print + print() + print(" ERROR: %s" % e) + print() sys.exit(1) finally: common.Cleanup() |