Skip to content

Commit

Permalink
Replacing project_file_root() method with file_root().
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrystinne committed Oct 25, 2023
1 parent c979168 commit 9ea07df
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions physionet-django/project/cloud/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def put_bucket_logging(s3, bucket_name, target_bucket, target_prefix):
)


def send_files_to_s3(folder_path, s3_prefix, bucket_name):
def send_files_to_s3(folder_path, s3_prefix, bucket_name, project):
"""
Upload files from a local folder to an AWS S3 bucket with
a specified prefix.
Expand Down Expand Up @@ -362,6 +362,21 @@ def send_files_to_s3(folder_path, s3_prefix, bucket_name):
Key=s3_key,
)

# If project has a ZIP file, upload it as well
if project.compressed_storage_size:
zip_name = project.zip_name()
zip_file_path = os.path.join(project.project_file_root(), zip_name)
if project.access_policy == AccessPolicy.OPEN:
s3_key = os.path.join(f"{project.slug}/", zip_name)
else:
s3_key = zip_name

s3.upload_file(
Filename=zip_file_path,
Bucket=bucket_name,
Key=s3_key,
)


def get_aws_accounts_for_dataset(dataset_name):
"""
Expand Down Expand Up @@ -635,14 +650,14 @@ def upload_project_to_S3(project):
update_bucket_policy(project, bucket_name)

# upload files to bucket
folder_path = project.project_file_root()

folder_path = project.file_root()
# set the prefix only for the projects
# in the open data bucket
s3_prefix = ""
if project.access_policy == AccessPolicy.OPEN:
s3_prefix = f"{project.slug}/"
send_files_to_s3(folder_path, s3_prefix, bucket_name)
s3_prefix = f"{project.slug}/{project.version}/"
else:
s3_prefix = f"{project.version}/"
send_files_to_s3(folder_path, s3_prefix, bucket_name, project)

put_bucket_logging(
s3, bucket_name, settings.S3_SERVER_ACCESS_LOGS, bucket_name + "/logs/"
Expand Down

0 comments on commit 9ea07df

Please sign in to comment.