Skip to content

Commit 100ef7d

Browse files
committed
Upload .zarr instead of .zip
1 parent cd97670 commit 100ef7d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/DPR/DPR_processor_mock.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

267282
if __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",

src/DPR/common/s3_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def files_to_be_uploaded(self, paths):
238238
"""
239239
list_with_files = []
240240
for local in paths:
241-
path = local.strip()
241+
path = str(local).strip()
242242
# check if it is a file
243243
self.logger.debug("path = %s", path)
244244
if os.path.isfile(path):
@@ -493,7 +493,6 @@ def put_files_to_s3(self, config: Any) -> list:
493493
self.logger.debug("locals = %s", locals())
494494

495495
collection_files = self.files_to_be_uploaded(config.files)
496-
497496
try:
498497
self.check_bucket_access(config.bucket)
499498
except RuntimeError:

0 commit comments

Comments
 (0)