Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8b4784c authored by Kelvin Zhang's avatar Kelvin Zhang Committed by Gerrit Code Review
Browse files

Merge "Fix lint errors in ota_from_target_files script"

parents 4a203a63 0876c410
Loading
Loading
Loading
Loading
+52 −47
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ from __future__ import print_function
import base64
import collections
import copy
import datetime
import errno
import fnmatch
import getopt
@@ -53,16 +54,17 @@ class Options(object):
    # running this function, user-supplied search path (`--path`) hasn't been
    # available. So the value set here is the default, which might be overridden
    # by commandline flag later.
    exec_path = sys.argv[0]
    exec_path = os.path.realpath(sys.argv[0])
    if exec_path.endswith('.py'):
      script_name = os.path.basename(exec_path)
      # logger hasn't been initialized yet at this point. Use print to output
      # warnings.
      print(
          'Warning: releasetools script should be invoked as hermetic Python '
          'executable -- build and run `{}` directly.'.format(script_name[:-3]),
          'executable -- build and run `{}` directly.'.format(
              script_name[:-3]),
          file=sys.stderr)
    self.search_path = os.path.realpath(os.path.join(os.path.dirname(exec_path), '..'))
    self.search_path = os.path.dirname(os.path.dirname(exec_path))

    self.signapk_path = "framework/signapk.jar"  # Relative to search_path
    self.signapk_shared_library_path = "lib64"   # Relative to search_path
@@ -224,7 +226,7 @@ def Run(args, verbose=None, **kwargs):
  if 'universal_newlines' not in kwargs:
    kwargs['universal_newlines'] = True
  # Don't log any if caller explicitly says so.
  if verbose != False:
  if verbose:
    logger.info("  Running: \"%s\"", " ".join(args))
  return subprocess.Popen(args, **kwargs)

@@ -274,7 +276,7 @@ def RunAndCheckOutput(args, verbose=None, **kwargs):
  if output is None:
    output = ""
  # Don't log any if caller explicitly says so.
  if verbose != False:
  if verbose:
    logger.info("%s", output.rstrip())
  if proc.returncode != 0:
    raise ExternalError(
@@ -375,7 +377,6 @@ class BuildInfo(object):
            'Invalid build fingerprint: "{}". See the requirement in Android CDD '
            "3.2.2. Build Parameters.".format(fingerprint))


    self._partition_fingerprints = {}
    for partition in PARTITIONS_WITH_CARE_MAP:
      try:
@@ -522,7 +523,8 @@ class BuildInfo(object):
          self.GetPartitionBuildProp("ro.product.device", partition),
          self.GetPartitionBuildProp("ro.build.version.release", partition),
          self.GetPartitionBuildProp("ro.build.id", partition),
          self.GetPartitionBuildProp("ro.build.version.incremental", partition),
          self.GetPartitionBuildProp(
              "ro.build.version.incremental", partition),
          self.GetPartitionBuildProp("ro.build.type", partition),
          self.GetPartitionBuildProp("ro.build.tags", partition))

@@ -703,7 +705,7 @@ def LoadInfoDict(input_file, repacking=False):
    for partition in PARTITIONS_WITH_CARE_MAP:
      fingerprint = build_info.GetPartitionFingerprint(partition)
      if fingerprint:
        d["avb_{}_salt".format(partition)] = sha256(fingerprint).hexdigest()
        d["avb_{}_salt".format(partition)] = sha256(fingerprint.encode()).hexdigest()

  return d

@@ -749,6 +751,7 @@ class PartitionBuildProps(object):
        placeholders in the build.prop file. We expect exactly one value for
        each of the variables.
  """

  def __init__(self, input_file, name, placeholder_values=None):
    self.input_file = input_file
    self.partition = name
@@ -1511,7 +1514,8 @@ def GetVendorBootImage(name, prebuilt_name, unpack_dir, tree_subdir,
  if info_dict is None:
    info_dict = OPTIONS.info_dict

  data = _BuildVendorBootImage(os.path.join(unpack_dir, tree_subdir), info_dict)
  data = _BuildVendorBootImage(
      os.path.join(unpack_dir, tree_subdir), info_dict)
  if data:
    return File(name, data)
  return None
@@ -1622,7 +1626,6 @@ def GetUserImage(which, tmpdir, input_zip,
    if reset_file_map:
      img.ResetFileMap()
    return img
  else:
  return GetNonSparseImage(which, tmpdir, hashtree_info_generator)


@@ -1822,7 +1825,6 @@ def GetMinSdkVersionInt(apk_name, codename_to_api_level_map):
    # Not a decimal number. Codename?
    if version in codename_to_api_level_map:
      return codename_to_api_level_map[version]
    else:
    raise ExternalError(
        "Unknown minSdkVersion: '{}'. Known codenames: {}".format(
            version, codename_to_api_level_map))
@@ -1930,7 +1932,8 @@ def CheckSize(data, target, info_dict):
    msg = "%s size (%d) is %.2f%% of limit (%d)" % (target, size, pct, limit)
    if pct >= 99.0:
      raise ExternalError(msg)
    elif pct >= 95.0:

    if pct >= 95.0:
      logger.warning("\n  WARNING: %s\n", msg)
    else:
      logger.info("  %s", msg)
@@ -2040,6 +2043,7 @@ Global options
      Put verbose logs to specified file (regardless of --verbose option.)
"""


def Usage(docstring):
  print(docstring.rstrip("\n"))
  print(COMMON_DOCSTRING)
@@ -2265,7 +2269,6 @@ class PasswordManager(object):

def ZipWrite(zip_file, filename, arcname=None, perms=0o644,
             compress_type=None):
  import datetime

  # http://b/18015246
  # Python 2.7's zipfile implementation wrongly thinks that zip64 is required
@@ -2391,6 +2394,7 @@ def ZipClose(zip_file):

class DeviceSpecificParams(object):
  module = None

  def __init__(self, **kwargs):
    """Keyword arguments to the constructor become attributes of this
    object, which is passed to all functions in the device-specific
@@ -2563,6 +2567,7 @@ class Difference(object):
      cmd.append(ptemp.name)
      p = Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      err = []

      def run():
        _, e = p.communicate()
        if e:
@@ -2591,7 +2596,6 @@ class Difference(object):
    self.patch = diff
    return self.tf, self.sf, self.patch


  def GetPatch(self):
    """Returns a tuple of (target_file, source_file, patch_data).

@@ -2934,6 +2938,7 @@ PARTITION_TYPES = {
    "squashfs": "EMMC"
}


def GetTypeAndDevice(mount_point, info, check_no_slot=True):
  """
  Use GetTypeAndDeviceExpr whenever possible. This function is kept for
@@ -2947,7 +2952,6 @@ def GetTypeAndDevice(mount_point, info, check_no_slot=True):
          "Use GetTypeAndDeviceExpr instead"
    return (PARTITION_TYPES[fstab[mount_point].fs_type],
            fstab[mount_point].device)
  else:
  raise KeyError


@@ -2963,7 +2967,6 @@ def GetTypeAndDeviceExpr(mount_point, info):
    if p.slotselect:
      device_expr = 'add_slot_suffix(%s)' % device_expr
    return (PARTITION_TYPES[fstab[mount_point].fs_type], device_expr)
  else:
  raise KeyError


@@ -2979,6 +2982,7 @@ def GetEntryForDevice(fstab, device):
      return fstab[mount_point]
  return None


def ParseCertificate(data):
  """Parses and converts a PEM-encoded certificate into DER-encoded.

@@ -3370,7 +3374,8 @@ class DynamicPartitionsDifference(object):

    for p, u in self._partition_updates.items():
      if u.tgt_size and u.src_size < u.tgt_size:
        comment('Grow partition %s from %d to %d' % (p, u.src_size, u.tgt_size))
        comment('Grow partition %s from %d to %d' %
                (p, u.src_size, u.tgt_size))
        append('resize %s %d' % (p, u.tgt_size))

    for p, u in self._partition_updates.items():
+15 −12
Original line number Diff line number Diff line
@@ -221,8 +221,10 @@ import zipfile
import check_target_files_vintf
import common
import edify_generator
import target_files_diff
import verity_utils


if sys.hexversion < 0x02070000:
  print("Python 2.7 or newer is required.", file=sys.stderr)
  sys.exit(1)
@@ -547,8 +549,8 @@ def HasRecoveryPatch(target_files_zip, info_dict):
  patch = "%s/recovery-from-boot.p" % target_files_dir
  img = "%s/etc/recovery.img" % target_files_dir

  namelist = [name for name in target_files_zip.namelist()]
  return (patch in namelist or img in namelist)
  namelist = target_files_zip.namelist()
  return patch in namelist or img in namelist


def HasPartition(target_files_zip, partition):
@@ -626,7 +628,8 @@ def GetBlockDifferences(target_zip, source_zip, target_info, source_info,

  def GetIncrementalBlockDifferenceForPartition(name):
    if not HasPartition(source_zip, name):
      raise RuntimeError("can't generate incremental that adds {}".format(name))
      raise RuntimeError(
          "can't generate incremental that adds {}".format(name))

    partition_src = common.GetUserImage(name, OPTIONS.source_tmp, source_zip,
                                        info_dict=source_info,
@@ -637,8 +640,7 @@ def GetBlockDifferences(target_zip, source_zip, target_info, source_info,
    partition_tgt = common.GetUserImage(name, OPTIONS.target_tmp, target_zip,
                                        info_dict=target_info,
                                        allow_shared_blocks=allow_shared_blocks,
                                        hashtree_info_generator=
                                        hashtree_info_generator)
                                        hashtree_info_generator=hashtree_info_generator)

    # Check the first block of the source system partition for remount R/W only
    # if the filesystem is ext4.
@@ -1668,7 +1670,7 @@ def GetTargetFilesZipForSecondaryImages(input_file, skip_postinstall=False):
        partitions = [partition for partition in partitions if partition
                      not in SECONDARY_PAYLOAD_SKIPPED_IMAGES]
        output_list.append('{}={}'.format(key, ' '.join(partitions)))
      elif key == 'virtual_ab' or key == "virtual_ab_retrofit":
      elif key in ['virtual_ab', "virtual_ab_retrofit"]:
        # Remove virtual_ab flag from secondary payload so that OTA client
        # don't use snapshots for secondary update
        pass
@@ -1712,7 +1714,8 @@ def GetTargetFilesZipForSecondaryImages(input_file, skip_postinstall=False):
          partition_list = f.read().splitlines()
        partition_list = [partition for partition in partition_list if partition
                          and partition not in SECONDARY_PAYLOAD_SKIPPED_IMAGES]
        common.ZipWriteStr(target_zip, info.filename, '\n'.join(partition_list))
        common.ZipWriteStr(target_zip, info.filename,
                           '\n'.join(partition_list))
      # Remove the unnecessary partitions from the dynamic partitions list.
      elif (info.filename == 'META/misc_info.txt' or
            info.filename == DYNAMIC_PARTITION_INFO):
@@ -1795,7 +1798,8 @@ def GetTargetFilesZipForRetrofitDynamicPartitions(input_file,
      "{} is in super_block_devices but not in {}".format(
          super_device_not_updated, AB_PARTITIONS)
  # ab_partitions -= (dynamic_partition_list - super_block_devices)
  new_ab_partitions = common.MakeTempFile(prefix="ab_partitions", suffix=".txt")
  new_ab_partitions = common.MakeTempFile(
      prefix="ab_partitions", suffix=".txt")
  with open(new_ab_partitions, 'w') as f:
    for partition in ab_partitions:
      if (partition in dynamic_partition_list and
@@ -2245,7 +2249,6 @@ def main(argv):
        OPTIONS.incremental_source, TARGET_DIFFING_UNZIP_PATTERN)

    with open(OPTIONS.log_diff, 'w') as out_file:
      import target_files_diff
      target_files_diff.recursiveDiff(
          '', source_dir, target_dir, out_file)

+14 −15
Original line number Diff line number Diff line
@@ -623,7 +623,7 @@ def ProcessTargetFiles(input_tf_zip, output_tf_zip, misc_info,
      pass

    # Skip the care_map as we will regenerate the system/vendor images.
    elif filename == "META/care_map.pb" or filename == "META/care_map.txt":
    elif filename in ["META/care_map.pb", "META/care_map.txt"]:
      pass

    # Updates system_other.avbpubkey in /product/etc/.
@@ -967,11 +967,10 @@ def ReplaceAvbSigningKeys(misc_info):
    if extra_args:
      print('Setting extra AVB signing args for %s to "%s"' % (
          partition, extra_args))
      if partition in AVB_FOOTER_ARGS_BY_PARTITION:
        args_key = AVB_FOOTER_ARGS_BY_PARTITION[partition]
      else:
      args_key = AVB_FOOTER_ARGS_BY_PARTITION.get(
          partition,
          # custom partition
        args_key = "avb_{}_add_hashtree_footer_args".format(partition)
          "avb_{}_add_hashtree_footer_args".format(partition))
      misc_info[args_key] = (misc_info.get(args_key, '') + ' ' + extra_args)

  for partition in AVB_FOOTER_ARGS_BY_PARTITION: