def _GetObjectRef(self, bucket_url_string, gcs_object, with_version=False): """Creates a BucketListingRef of type OBJECT from the arguments. Args: bucket_url_string: Wildcardless string describing the containing bucket. gcs_object: gsutil_api root Object for populating the BucketListingRef. with_version: If true, return a reference with a versioned string. Returns: BucketListingRef of type OBJECT. """ # Generation can be None in test mocks, so just return the # live object for simplicity. if with_version and gcs_object.generation is not None: generation_str = GenerationFromUrlAndString( self.wildcard_url, gcs_object.generation) object_string = '%s%s#%s' % (bucket_url_string, gcs_object.name, generation_str) else: object_string = '%s%s' % (bucket_url_string, gcs_object.name) object_url = StorageUrlFromString(object_string) return BucketListingObject(object_url, root_object=gcs_object)
def _SingleVersionMatches(self, listed_generation): decoded_generation = GenerationFromUrlAndString( self.wildcard_url, listed_generation) return str(self.wildcard_url.generation) == str(decoded_generation)
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 print '%s:' % url_str.encode(UTF8) if obj.updated: print '\tCreation time:\t\t%s' % obj.updated.strftime( '%a, %d %b %Y %H:%M:%S GMT') if obj.cacheControl: print '\tCache-Control:\t\t%s' % obj.cacheControl if obj.contentDisposition: print '\tContent-Disposition:\t\t%s' % obj.contentDisposition if obj.contentEncoding: print '\tContent-Encoding:\t\t%s' % obj.contentEncoding if obj.contentLanguage: print '\tContent-Language:\t%s' % obj.contentLanguage print '\tContent-Length:\t\t%s' % obj.size print '\tContent-Type:\t\t%s' % obj.contentType if obj.componentCount: print '\tComponent-Count:\t%d' % obj.componentCount 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: print '\tMetadata:' for ap in non_marker_props: meta_string = '\t\t%s:\t\t%s' % (ap.key, ap.value) print meta_string.encode(UTF8) if obj.crc32c: print '\tHash (crc32c):\t\t%s' % obj.crc32c if obj.md5Hash: print '\tHash (md5):\t\t%s' % obj.md5Hash print '\tETag:\t\t\t%s' % obj.etag.strip('"\'') if obj.generation: generation_str = GenerationFromUrlAndString(storage_url, obj.generation) print '\tGeneration:\t\t%s' % generation_str if obj.metageneration: print '\tMetageneration:\t\t%s' % 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: print '\tACL:\t\t%s' % AclTranslation.JsonFromMessage(obj.acl) elif S3_ACL_MARKER_GUID in marker_props: print '\tACL:\t\t%s' % marker_props[S3_ACL_MARKER_GUID] else: print( '\tACL:\t\t\tACCESS DENIED. Note: you need OWNER ' 'permission\n\t\t\t\ton the object to read its ACL.') return (num_objs, num_bytes)