From 1dc78c87fc47cd74a761c54c0e752dad743d035d Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Tue, 23 May 2023 23:10:37 +0300 Subject: [PATCH] black --- frigate/config.py | 4 +++- frigate/http.py | 7 +++++-- frigate/record/cleanup.py | 7 +++---- frigate/record/maintainer.py | 4 +++- frigate/record/util.py | 2 +- frigate/storage.py | 19 +++++++++---------- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/frigate/config.py b/frigate/config.py index 273773ca2..4fdc7f995 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -523,7 +523,9 @@ class SnapshotsConfig(FrigateBaseModel): class StorageS3Config(FrigateBaseModel): enabled: bool = Field(default=False, title="S3 enabled.") - archive: bool = Field(default=False, title="Archive expired records to S3 instead of delete") + archive: bool = Field( + default=False, title="Archive expired records to S3 instead of delete" + ) access_key_id: str = Field(default="", title="AWS_ACCESS_KEY_ID") secret_access_key: str = Field(default="", title="AWS_SECRET_ACCESS_KEY") bucket_name: str = Field(default="", title="Bucket name") diff --git a/frigate/http.py b/frigate/http.py index 0e6feb8c7..867651766 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -1323,7 +1323,10 @@ def recordings(camera_name): def recording_clip(camera_name, start_ts, end_ts): download = request.args.get("download", type=bool) - if current_app.frigate_config.storage.s3.enabled or current_app.frigate_config.storage.s3.archive: + if ( + current_app.frigate_config.storage.s3.enabled + or current_app.frigate_config.storage.s3.archive + ): s3 = StorageS3(current_app.frigate_config) recordings = ( @@ -1342,7 +1345,7 @@ def recording_clip(camera_name, start_ts, end_ts): for clip in recordings: if recordings.storage == "s3": clip.path = s3.download_file_from_s3(clip.path) - + playlist_lines.append(f"file '{clip.path}'") # if this is the starting clip, add an inpoint if clip.start_time < start_ts: diff --git a/frigate/record/cleanup.py b/frigate/record/cleanup.py index 3211385a1..68e42af0d 100644 --- a/frigate/record/cleanup.py +++ b/frigate/record/cleanup.py @@ -153,7 +153,6 @@ class RecordingCleanup(threading.Thread): else: Path(recording.path).unlink(missing_ok=True) deleted_recordings.add(recording.id) - # delete timeline entries relevant to this recording segment Timeline.delete().where( @@ -174,9 +173,9 @@ class RecordingCleanup(threading.Thread): ).execute() for recording in moved_recordings: - Recordings.update({Recordings.storage: "s3", Recordings.path: recording["path"]}).where( - Recordings.id == recording["id"] - ).execute() + Recordings.update( + {Recordings.storage: "s3", Recordings.path: recording["path"]} + ).where(Recordings.id == recording["id"]).execute() logger.debug(f"End camera: {camera}.") diff --git a/frigate/record/maintainer.py b/frigate/record/maintainer.py index 0a074b87a..2a0505627 100644 --- a/frigate/record/maintainer.py +++ b/frigate/record/maintainer.py @@ -347,7 +347,9 @@ class RecordingMaintainer(threading.Thread): file_path = s3path storage = "s3" else: - logger.error(f"Unable to upload recording segment {file_path} to s3, fallback to local") + logger.error( + f"Unable to upload recording segment {file_path} to s3, fallback to local" + ) logger.error(e) Recordings.create( diff --git a/frigate/record/util.py b/frigate/record/util.py index 9737c5968..7bbfb236d 100644 --- a/frigate/record/util.py +++ b/frigate/record/util.py @@ -8,6 +8,7 @@ from frigate.config import FrigateConfig logger = logging.getLogger(__name__) + def remove_empty_directories(directory: str) -> None: # list all directories recursively and sort them by path, # longest first @@ -22,4 +23,3 @@ def remove_empty_directories(directory: str) -> None: continue if len(os.listdir(path)) == 0: os.rmdir(path) - diff --git a/frigate/storage.py b/frigate/storage.py index 66ee9fe52..24a0f7848 100644 --- a/frigate/storage.py +++ b/frigate/storage.py @@ -28,21 +28,22 @@ class StorageS3: def __init__(self, config: FrigateConfig) -> None: self.config = config if self.config.storage.s3.enabled or self.config.storage.s3.archive: - if self.config.storage.s3.endpoint_url.startswith('http://'): + if self.config.storage.s3.endpoint_url.startswith("http://"): try: session = boto_session() - session.set_config_variable('s3', + session.set_config_variable( + "s3", { - 'use_ssl': False, - 'verify': False, - } + "use_ssl": False, + "verify": False, + }, ) self.s3_client = session.create_client( "s3", aws_access_key_id=self.config.storage.s3.access_key_id, aws_secret_access_key=self.config.storage.s3.secret_access_key, endpoint_url=self.config.storage.s3.endpoint_url, - config=Config(signature_version=UNSIGNED) + config=Config(signature_version=UNSIGNED), ) except (BotoCoreError, ClientError) as error: logger.error(f"Failed to create S3 client: {error}") @@ -58,7 +59,7 @@ class StorageS3: except (BotoCoreError, ClientError) as error: logger.error(f"Failed to create S3 client: {error}") return None - + self.s3_bucket = self.config.storage.s3.bucket_name self.s3_path = self.config.storage.s3.path @@ -66,9 +67,7 @@ class StorageS3: try: s3_filename = self.s3_path + "/" + os.path.relpath(file_path, RECORD_DIR) self.s3_client.upload_file(file_path, self.s3_bucket, s3_filename) - logger.debug( - f"Uploading {file_path} to S3 {s3_filename}" - ) + logger.debug(f"Uploading {file_path} to S3 {s3_filename}") except Exception as e: logger.error( f"Error occurred while uploading {file_path} to S3 {s3_filename}: {e}"