You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/08/20 12:25:04 UTC

[GitHub] [airflow] EmadMokhtar commented on issue #10426: Multiple prefixes in GoogleCloudStorageListOperator and GoogleCloudStorageDeleteOperator

EmadMokhtar commented on issue #10426:
URL: https://github.com/apache/airflow/issues/10426#issuecomment-677633259


   # Initial implementation
   
   I implement it like this in my project
   
   
   ``` python
       def execute(self, context):
           hook = GoogleCloudStorageHook(
               google_cloud_storage_conn_id=self.google_cloud_storage_conn_id,
               delegate_to=self.delegate_to
           )
   
           if self.objects:
               objects = self.objects
           else:
               objects = []
               for prefix in self.prefixes:
                   prefix_objects = hook.list(bucket=self.bucket_name,
                                              prefix=prefix)
                   objects.extend(prefix_objects)
                   self.log.info(prefix_objects)
   
           self.log.info("Deleting %s objects from %s",
                         len(objects), self.bucket_name)
           for object_name in objects:
               hook.delete(bucket=self.bucket_name,
                           object=object_name)
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org