def _get_container_iterator(self, cloud_url, recursion_level): """For recursing into and retrieving the contents of a container. Args: cloud_url (storage_url.CloudUrl): Container URL for recursing into. recursion_level (int): Determines if iterator should keep recursing. Returns: _BaseFormatWrapper generator. """ # End URL with '/*', so WildcardIterator won't filter out its contents. new_url_string = cloud_url.versionless_url_string if cloud_url.versionless_url_string[-1] != cloud_url.delimiter: new_url_string += cloud_url.delimiter new_cloud_url = storage_url.storage_url_from_string(new_url_string + '*') fields_scope = _translate_display_detail_to_fields_scope( self._display_detail, is_bucket_listing=False) iterator = wildcard_iterator.CloudWildcardIterator( new_cloud_url, all_versions=self._all_versions, error_on_missing_key=False, fields_scope=fields_scope) return self._recursion_helper(iterator, recursion_level)
def execute(self, callback=None): """Recursively create wildcard iterators to print all relevant items.""" fields_scope = _translate_display_detail_to_fields_scope( self._display_detail, is_bucket_listing=self._cloud_url.is_provider()) resources = plurality_checkable_iterator.PluralityCheckableIterator( wildcard_iterator.CloudWildcardIterator( self._cloud_url, fields_scope=fields_scope)) if resources.is_empty(): raise errors.InvalidUrlError('One or more URLs matched no objects.') if self._cloud_url.is_provider(): # Received a provider URL ("gs://"). List bucket names with no formatting. resources_wrappers = self._recursion_helper(resources, recursion_level=0) # "**" overrides recursive flag. elif self._recursion_flag and '**' not in self._cloud_url.url_string: resources_wrappers = self._recursion_helper(resources, float('inf')) elif not resources.is_plural() and resources.peek().is_container(): # One container was returned by the query, in which case we show # its contents. resources_wrappers = self._get_container_iterator( resources.peek().storage_url, recursion_level=0) else: resources_wrappers = self._recursion_helper(resources, recursion_level=1) if self._display_detail == DisplayDetail.FULL: # TODO(b/169795589): We may display something other than JSON for FULL, # and make JSON its own DisplayDetail option. self._print_json_list(resources_wrappers) else: self._print_row_list(resources_wrappers) if callback: callback()
def execute(self, task_status_queue=None): """Recursively create wildcard iterators to print all relevant items.""" # List task does not need to report status information. del task_status_queue fields_scope = _translate_display_detail_to_fields_scope( self._display_detail, is_bucket_listing=self._cloud_url.is_provider()) resources = plurality_checkable_iterator.PluralityCheckableIterator( wildcard_iterator.CloudWildcardIterator( self._cloud_url, all_versions=self._all_versions, error_on_missing_key=False, fields_scope=fields_scope, get_bucket_metadata=self._buckets_flag)) if resources.is_empty(): raise errors.InvalidUrlError( 'One or more URLs matched no objects.') if self._only_display_buckets: # Received a provider URL ("gs://") -> List all buckets. # Received buckets flag and bucket URL -> List matching buckets, ignoring # recursion. resources_wrappers = self._recursion_helper(resources, recursion_level=0) elif self._recursion_flag and '**' not in self._cloud_url.url_string: # "**" overrides recursive flag. resources_wrappers = self._recursion_helper( resources, float('inf')) elif not resources.is_plural() and resources.peek().is_container(): # One container was returned by the query, in which case we show # its contents. resources_wrappers = self._get_container_iterator( resources.peek().storage_url, recursion_level=0) else: resources_wrappers = self._recursion_helper(resources, recursion_level=1) if self._display_detail == DisplayDetail.JSON: self._print_json_list(resources_wrappers) else: self._print_row_list(resources_wrappers)