def PrintFullInfoAboutObject()

in gslib/utils/ls_helper.py [0:0]


def PrintFullInfoAboutObject(bucket_listing_ref, incl_acl=True):
  """Print full info for given object (like what displays for gsutil ls -L).

  Args:
    bucket_listing_ref: BucketListingRef being listed.
                        Must have ref_type OBJECT and a populated root_object
                        with the desired fields.
    incl_acl: True if ACL info should be output.

  Returns:
    Tuple (number of objects, object_length)

  Raises:
    Exception: if calling bug encountered.
  """
  url_str = bucket_listing_ref.url_string
  storage_url = StorageUrlFromString(url_str)
  obj = bucket_listing_ref.root_object

  if (obj.metadata and
      S3_DELETE_MARKER_GUID in obj.metadata.additionalProperties):
    num_bytes = 0
    num_objs = 0
    url_str += '<DeleteMarker>'
  else:
    num_bytes = obj.size
    num_objs = 1

  text_util.print_to_fd('{}:'.format(url_str))
  if obj.timeCreated:
    text_util.print_to_fd(
        MakeMetadataLine('Creation time',
                         obj.timeCreated.strftime('%a, %d %b %Y %H:%M:%S GMT')))
  if obj.updated:
    text_util.print_to_fd(
        MakeMetadataLine('Update time',
                         obj.updated.strftime('%a, %d %b %Y %H:%M:%S GMT')))
  if (obj.timeStorageClassUpdated and
      obj.timeStorageClassUpdated != obj.timeCreated):
    text_util.print_to_fd(
        MakeMetadataLine(
            'Storage class update time',
            obj.timeStorageClassUpdated.strftime('%a, %d %b %Y %H:%M:%S GMT')))
  if obj.storageClass:
    text_util.print_to_fd(MakeMetadataLine('Storage class', obj.storageClass))
  if obj.temporaryHold:
    text_util.print_to_fd(MakeMetadataLine('Temporary Hold', 'Enabled'))
  if obj.eventBasedHold:
    text_util.print_to_fd(MakeMetadataLine('Event-Based Hold', 'Enabled'))
  if obj.retentionExpirationTime:
    text_util.print_to_fd(
        MakeMetadataLine(
            'Retention Expiration',
            obj.retentionExpirationTime.strftime('%a, %d %b %Y %H:%M:%S GMT')))
  if obj.kmsKeyName:
    text_util.print_to_fd(MakeMetadataLine('KMS key', obj.kmsKeyName))
  if obj.cacheControl:
    text_util.print_to_fd(MakeMetadataLine('Cache-Control', obj.cacheControl))
  if obj.contentDisposition:
    text_util.print_to_fd(
        MakeMetadataLine('Content-Disposition', obj.contentDisposition))
  if obj.contentEncoding:
    text_util.print_to_fd(
        MakeMetadataLine('Content-Encoding', obj.contentEncoding))
  if obj.contentLanguage:
    text_util.print_to_fd(
        MakeMetadataLine('Content-Language', obj.contentLanguage))
  text_util.print_to_fd(MakeMetadataLine('Content-Length', obj.size))
  text_util.print_to_fd(MakeMetadataLine('Content-Type', obj.contentType))
  if obj.componentCount:
    text_util.print_to_fd(
        MakeMetadataLine('Component-Count', obj.componentCount))
  if obj.customTime:
    text_util.print_to_fd(MakeMetadataLine('Custom-Time', obj.customTime))
  if obj.timeDeleted:
    text_util.print_to_fd(
        MakeMetadataLine('Noncurrent time',
                         obj.timeDeleted.strftime('%a, %d %b %Y %H:%M:%S GMT')))
  marker_props = {}
  if obj.metadata and obj.metadata.additionalProperties:
    non_marker_props = []
    for add_prop in obj.metadata.additionalProperties:
      if add_prop.key not in S3_MARKER_GUIDS:
        non_marker_props.append(add_prop)
      else:
        marker_props[add_prop.key] = add_prop.value
    if non_marker_props:
      text_util.print_to_fd(MakeMetadataLine('Metadata', ''))
      for ap in non_marker_props:
        ap_key = '{}'.format(ap.key)
        ap_value = '{}'.format(ap.value)
        meta_data_line = MakeMetadataLine(ap_key, ap_value, indent=2)
        text_util.print_to_fd(meta_data_line)
  if obj.customerEncryption:
    if not obj.crc32c:
      text_util.print_to_fd(MakeMetadataLine('Hash (crc32c)', 'encrypted'))
    if not obj.md5Hash:
      text_util.print_to_fd(MakeMetadataLine('Hash (md5)', 'encrypted'))
    text_util.print_to_fd(
        MakeMetadataLine('Encryption algorithm',
                         obj.customerEncryption.encryptionAlgorithm))
    text_util.print_to_fd(
        MakeMetadataLine('Encryption key SHA256',
                         obj.customerEncryption.keySha256))
  if obj.crc32c:
    text_util.print_to_fd(MakeMetadataLine('Hash (crc32c)', obj.crc32c))
  if obj.md5Hash:
    text_util.print_to_fd(MakeMetadataLine('Hash (md5)', obj.md5Hash))
  text_util.print_to_fd(MakeMetadataLine('ETag', obj.etag.strip('"\'')))
  if obj.generation:
    generation_str = GenerationFromUrlAndString(storage_url, obj.generation)
    text_util.print_to_fd(MakeMetadataLine('Generation', generation_str))
  if obj.metageneration:
    text_util.print_to_fd(MakeMetadataLine('Metageneration',
                                           obj.metageneration))
  if incl_acl:
    # JSON API won't return acls as part of the response unless we have
    # full control scope
    if obj.acl:
      text_util.print_to_fd(
          MakeMetadataLine('ACL', AclTranslation.JsonFromMessage(obj.acl)))
    elif S3_ACL_MARKER_GUID in marker_props:
      text_util.print_to_fd(
          MakeMetadataLine('ACL', marker_props[S3_ACL_MARKER_GUID]))
    else:
      # Empty ACLs are possible with Bucket Policy Only and no longer imply
      # ACCESS DENIED anymore.
      text_util.print_to_fd(MakeMetadataLine('ACL', '[]'))

  return (num_objs, num_bytes)