Skip to content

Commit

Permalink
Merge 24.1.12 into 25.0-release branch (#1020)
Browse files Browse the repository at this point in the history
* [AWS S3] Copy file (#1016)

* Update VERSION to 24.1.12

* modify permission for extract eeg bids archive to be executable (#1018)

* aws-s3 copy-file optional delete (#1019)

---------

Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mail.mcgill.ca>
  • Loading branch information
cmadjar and laemtl authored Oct 13, 2023
1 parent f8e313c commit f0457a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Empty file modified python/extract_eeg_bids_archive.py
100644 → 100755
Empty file.
29 changes: 29 additions & 0 deletions python/lib/aws_s3.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,35 @@ def delete_file(self, s3_object_name):
except Exception as err:
raise Exception(f"{s3_object_name} download failure = {format(err)}")

def copy_file(self, src_s3_object_name, dst_s3_object_name, delete = False):
"""
Function to copy a s3 file or directory.
:param src_s3_object_name: name of the source s3 file or directory
:type src_s3_object_name: str
:param dst_s3_object_name: name of the destination s3 file or directory
:type dst_s3_object_name: str
:param delete: whether to delete the source file after the copy
:type delete: bool
"""

print(f"Copying {src_s3_object_name} to {dst_s3_object_name}")

try:
(src_s3_bucket_name, src_s3_bucket, src_s3_file_name) = self.get_s3_object_path_part(src_s3_object_name)
(dst_s3_bucket_name, dst_s3_bucket, dst_s3_file_name) = self.get_s3_object_path_part(dst_s3_object_name)
for obj in src_s3_bucket.objects.filter(Prefix=src_s3_file_name):
subcontent = obj.key.replace(src_s3_file_name, "")
dst_s3_bucket.Object(
dst_s3_file_name + subcontent
).copy_from(
CopySource=f'{obj.bucket_name}/{obj.key}'
)
if delete:
src_s3_bucket.Object(obj.key).delete()
except Exception as err:
raise Exception(f"{src_s3_object_name} => {dst_s3_object_name} copy failure = {format(err)}")

def get_s3_object_path_part(self, s3_object_name):
"""
Function to dissect a s3 file to extract the file prefix and the bucket name
Expand Down

0 comments on commit f0457a4

Please sign in to comment.