Skip to content

Commit

Permalink
Move imports to the top of module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrystinne committed Sep 28, 2023
1 parent 4b35757 commit 703e407
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
23 changes: 11 additions & 12 deletions physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@
from console import forms, utility, services
from console.forms import ProjectFilterForm, UserFilterForm
from console import views
from project.cloud.s3 import create_s3_bucket
from project.cloud.s3 import (
create_s3_bucket,
upload_project_to_S3,
get_bucket_name,
check_s3_bucket_exists,
update_bucket_policy,
)

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -764,6 +770,7 @@ def send_files_to_gcp(pid):
project.gcp.sent_zip = True
project.gcp.save()


@associated_task(PublishedProject, "pid", read_only=True)
@background()
def send_files_to_aws(pid):
Expand All @@ -784,8 +791,6 @@ def send_files_to_aws(pid):
- Verify that AWS credentials and configurations are correctly set
up for the S3 client.
"""
from project.cloud.s3 import upload_project_to_S3

project = PublishedProject.objects.get(id=pid)
upload_project_to_S3(project)

Expand Down Expand Up @@ -816,12 +821,6 @@ def update_aws_bucket_policy(pid):
- The 'updated_policy' variable indicates whether the policy was
updated successfully.
"""
from project.cloud.s3 import (
get_bucket_name,
check_s3_bucket_exists,
update_bucket_policy,
)

updated_policy = False
project = PublishedProject.objects.get(id=pid)
exists = check_s3_bucket_exists(project)
Expand Down Expand Up @@ -889,9 +888,9 @@ def manage_published_project(request, project_slug, version):
- Create GCP bucket and send files
"""
from project.cloud.s3 import (
get_bucket_name_and_prefix,
check_s3_bucket_with_prefix_exists,
has_aws_credentials,
get_bucket_name_and_prefix,
check_s3_bucket_with_prefix_exists,
has_aws_credentials,
missing_S3_open_data_info
)
try:
Expand Down
13 changes: 4 additions & 9 deletions physionet-django/project/cloud/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import json
from django.conf import settings
from project.models import PublishedProject, AccessPolicy

from user.models import User
from project.authorization.access import can_view_project_files

# Manage AWS buckets and objects
def missing_S3_open_data_info(project):
Expand Down Expand Up @@ -107,10 +108,7 @@ def get_bucket_name(project):
"""
bucket_name = None

if (
project.access_policy == AccessPolicy.OPEN and
has_S3_open_data_bucket_name()
):
if project.access_policy == AccessPolicy.OPEN and has_S3_open_data_bucket_name():
bucket_name = settings.OPEN_ACCESS_DATA_BUCKET_NAME
elif (
project.access_policy == AccessPolicy.RESTRICTED
Expand Down Expand Up @@ -308,7 +306,7 @@ def check_s3_bucket_exists(project):
try:
s3.head_bucket(Bucket=bucket_name)
return True
except botocore.exceptions.ClientError as e:
except botocore.exceptions.ClientError:
return False


Expand Down Expand Up @@ -436,9 +434,6 @@ def get_aws_accounts_for_dataset(dataset_name):
- Users with the appropriate permissions and AWS account IDs
are included in the result list.
"""
from user.models import User
from project.authorization.access import can_view_project_files

aws_accounts = []

published_projects = PublishedProject.objects.all()
Expand Down

0 comments on commit 703e407

Please sign in to comment.