@@ -164,6 +164,19 @@ def update_product(self, path: pathlib.Path, ptype):
164164 #data['stac_discovery']['id'] = new_product_id
165165 self .meta_attrs .append (data )
166166
167+ def unzip_if_needed (self , path : pathlib .Path ) -> None :
168+ # Check if the file has a .zip extension
169+ if path .suffix .lower () == ".zip" and path .is_file ():
170+ extract_dir = path .parent / path .stem # create folder with same name
171+ extract_dir .mkdir (exist_ok = True )
172+
173+ # Unzip the file
174+ with zipfile .ZipFile (path , 'r' ) as zip_ref :
175+ zip_ref .extractall (extract_dir )
176+
177+ return extract_dir
178+ return path
179+
167180 def upload_to_s3 (self , path : pathlib .Path , ptype ):
168181 """To be added. Should update products to a given s3 storage."""
169182 bucket_path = [out ['path' ] for out in self .payload_data ["I/O" ]["output_products" ] if ptype == out ['id' ]][0 ].split ("/" )
@@ -173,6 +186,8 @@ def upload_to_s3(self, path: pathlib.Path, ptype):
173186 bucket_path [2 ],
174187 "/" .join (bucket_path [3 :]),
175188 )
189+ path = self .unzip_if_needed (path )
190+ s3_config .files = [path ]
176191 logger .info ("S3 config: %s %s %s" , [str (path .absolute ().resolve ())], bucket_path [2 ], "/" .join (bucket_path [3 :]))
177192 handler = S3StorageHandler (
178193 os .environ ["S3_ACCESSKEY" ],
@@ -266,7 +281,7 @@ def update_product_name(self, path: pathlib.Path, crc: str):
266281
267282if __name__ == "__main__" :
268283 parser = argparse .ArgumentParser (description = "Starts the DPR processor mockup" )
269- default_payload_file = "src/DPR/ payload.yaml"
284+ default_payload_file = "payload.yaml"
270285 parser .add_argument (
271286 "-p" ,
272287 "--payload" ,
0 commit comments