Skip to content

Commit

Permalink
pre-commit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristobal Pio Garcia committed May 15, 2024
1 parent 41e3bff commit 0b64f8f
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions python/lsst/rubintv/production/uploaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,19 @@
import json
import logging
import os
import tempfile
import time
from abc import ABC, abstractmethod
from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import TypedDict

from abc import abstractmethod, ABC
from boto3.exceptions import S3UploadFailedError, S3TransferFailedError
from boto3.session import Session as S3_session
from boto3.exceptions import S3TransferFailedError, S3UploadFailedError
from boto3.resources.base import ServiceResource
from boto3.session import Session as S3_session
from botocore.config import Config
from botocore.exceptions import ClientError, BotoCoreError
from dataclasses import dataclass
from datetime import datetime
from enum import Enum
import tempfile
from botocore.exceptions import ClientError
from botocore.exceptions import BotoCoreError, ClientError
from lsst.summit.utils.utils import dayObsIntToString, getSite
from typing_extensions import Optional, override

Expand Down Expand Up @@ -284,7 +279,7 @@ class MultiUploader:

def __init__(self):
# TODO: thread the remote upload
self.localUploader = createLocalS3UploaderForSite()
self.localUploader = createS3UploaderForSite(UploaderType.LOCAL)
localOk = self.localUploader.checkAccess()
if not localOk:
raise RuntimeError("Failed to connect to local S3 bucket")
Expand All @@ -294,7 +289,7 @@ def __init__(self):
except ValueError:
self.remoteUploader = None

remoteRequired = getSite() in ['summit', 'tucson', 'base']
remoteRequired = getSite() in ["summit", "tucson", "base"]
if remoteRequired and not self.hasRemote:
raise RuntimeError("Failed to create remote S3 uploader")
elif remoteRequired and self.hasRemote:
Expand Down Expand Up @@ -520,7 +515,7 @@ def uploadPerSeqNumPlot(

return uploadAs

def checkAccess(self, tempFilePrefix: str | None = 'connection_test') -> bool:
def checkAccess(self, tempFilePrefix: str | None = "connection_test") -> bool:
"""Checks the read, write, and delete access to the S3 bucket.
This method uploads a test file to the S3 bucket, downloads it,
Expand All @@ -541,8 +536,8 @@ def checkAccess(self, tempFilePrefix: str | None = 'connection_test') -> bool:
``True`` if all operations succeed, ``False`` otherwise.
"""
testContent = b"Connection Test"
dateStr = datetime.now().strftime('%Y%m%d_%H%M%S')
fileName = f'test/{tempFilePrefix}_{dateStr}_file.txt'
dateStr = datetime.now().strftime("%Y%m%d_%H%M%S")
fileName = f"test/{tempFilePrefix}_{dateStr}_file.txt"
with tempfile.NamedTemporaryFile() as testFile:
testFile.write(testContent)
testFile.flush()
Expand All @@ -555,7 +550,7 @@ def checkAccess(self, tempFilePrefix: str | None = 'connection_test') -> bool:
with tempfile.NamedTemporaryFile() as fixedFile:
try:
self._s3Bucket.download_file(fileName, fixedFile.name)
with open(fixedFile.name, 'rb') as downloadedFile:
with open(fixedFile.name, "rb") as downloadedFile:
downloadedContent = downloadedFile.read()
if downloadedContent != testContent:
self._log.error("Read Access failed")
Expand Down

0 comments on commit 0b64f8f

Please sign in to comment.