(partitions, directory)
return return_dict
Validate partitions and images.

  Validate all partition names and partition directories. Cannot stop mid
  flash so its important to validate everything first.

  Args:
    Partitions: partitions to be tested.
    directory: directory containing the images.

  Returns:
    Dictionary with exact partition, image name mapping.
Validate partitions and images.
Validate partitions and images .
def _FindAndVerifyPartitionsAndImages(partitions, directory):
  """Validate partitions and images.

  Validate all partition names and partition directories. Cannot stop mid
  flash so its important to validate everything first.

  Args:
    Partitions: partitions to be tested.
    directory: directory containing the images.

  Returns:
    Dictionary with exact partition, image name mapping.
  """

  files = os.listdir(directory)
  return_dict = collections.OrderedDict()

  def find_file(pattern):
    for filename in files:
      if fnmatch.fnmatch(filename, pattern):
        return os.path.join(directory, filename)
    return None
  for partition in partitions:
    partition_info = _KNOWN_PARTITIONS[partition]
    image_file = find_file(partition_info['image'])
    if image_file:
      return_dict[partition] = image_file
    elif not partition_info.get('optional'):
      raise device_errors.FastbootCommandFailedError(
          'Failed to flash device. Could not find image for %s.',
          partition_info['image'])
  return return_dict
def _FindAndVerifyPartitionsAndImages ( partitions , directory ) : files = os . listdir ( directory ) return_dict = collections . OrderedDict ( ) def find_file ( pattern ) : for filename in files : if fnmatch . fnmatch ( filename , pattern ) : return os . path . join ( directory , filename ) return None for partition in partitions : partition_info = _KNOWN_PARTITIONS [ partition ] image_file = find_file ( partition_info [ 'image' ] ) if image_file : return_dict [ partition ] = image_file elif not partition_info . get ( 'optional' ) : raise device_errors . FastbootCommandFailedError ( 'Failed to flash device. Could not find image for %s.' , partition_info [ 'image' ] ) return return_dict