From 0b64f8f1c27c47bb03594e37390254a0bb0475b4 Mon Sep 17 00:00:00 2001 From: Cristobal Pio Garcia Date: Wed, 15 May 2024 03:19:05 -0700 Subject: [PATCH] pre-commit changes --- python/lsst/rubintv/production/uploaders.py | 25 +++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/python/lsst/rubintv/production/uploaders.py b/python/lsst/rubintv/production/uploaders.py index a38c0a4e5..2f0029af9 100644 --- a/python/lsst/rubintv/production/uploaders.py +++ b/python/lsst/rubintv/production/uploaders.py @@ -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 @@ -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") @@ -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: @@ -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, @@ -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() @@ -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")