forked from Github/frigate
Add isort and ruff linter (#6575)
* Add isort and ruff linter Both linters are pretty common among modern python code bases. The isort tool provides stable sorting and grouping, as well as pruning of unused imports. Ruff is a modern linter, that is very fast due to being written in rust. It can detect many common issues in a python codebase. Removes the pylint dev requirement, since ruff replaces it. * treewide: fix issues detected by ruff * treewide: fix bare except clauses * .devcontainer: Set up isort * treewide: optimize imports * treewide: apply black * treewide: make regex patterns raw strings This is necessary for escape sequences to be properly recognized.
This commit is contained in:
@@ -5,12 +5,12 @@ import itertools
|
||||
import logging
|
||||
import os
|
||||
import threading
|
||||
from multiprocessing.synchronize import Event as MpEvent
|
||||
from pathlib import Path
|
||||
|
||||
from peewee import DoesNotExist
|
||||
from multiprocessing.synchronize import Event as MpEvent
|
||||
|
||||
from frigate.config import RetainModeEnum, FrigateConfig
|
||||
from frigate.config import FrigateConfig, RetainModeEnum
|
||||
from frigate.const import RECORD_DIR, SECONDS_IN_DAY
|
||||
from frigate.models import Event, Recordings, Timeline
|
||||
from frigate.record.util import remove_empty_directories
|
||||
@@ -225,7 +225,7 @@ class RecordingCleanup(threading.Thread):
|
||||
|
||||
recordings_to_delete = []
|
||||
for recording in recordings.objects().iterator():
|
||||
if not recording.path in files_on_disk:
|
||||
if recording.path not in files_on_disk:
|
||||
recordings_to_delete.append(recording.id)
|
||||
|
||||
logger.debug(
|
||||
@@ -247,7 +247,7 @@ class RecordingCleanup(threading.Thread):
|
||||
# Expire tmp clips every minute, recordings and clean directories every hour.
|
||||
for counter in itertools.cycle(range(self.config.record.expire_interval)):
|
||||
if self.stop_event.wait(60):
|
||||
logger.info(f"Exiting recording cleanup...")
|
||||
logger.info("Exiting recording cleanup...")
|
||||
break
|
||||
self.clean_tmp_clips()
|
||||
|
||||
|
||||
@@ -9,14 +9,14 @@ import random
|
||||
import string
|
||||
import subprocess as sp
|
||||
import threading
|
||||
import psutil
|
||||
|
||||
from collections import defaultdict
|
||||
from multiprocessing.synchronize import Event as MpEvent
|
||||
from pathlib import Path
|
||||
from typing import Any, Tuple
|
||||
|
||||
from frigate.config import RetainModeEnum, FrigateConfig
|
||||
import psutil
|
||||
|
||||
from frigate.config import FrigateConfig, RetainModeEnum
|
||||
from frigate.const import CACHE_DIR, MAX_SEGMENT_DURATION, RECORD_DIR
|
||||
from frigate.models import Event, Recordings
|
||||
from frigate.types import RecordMetricsTypes
|
||||
@@ -63,7 +63,7 @@ class RecordingMaintainer(threading.Thread):
|
||||
for nt in flist:
|
||||
if nt.path.startswith(CACHE_DIR):
|
||||
files_in_use.append(nt.path.split("/")[-1])
|
||||
except:
|
||||
except psutil.Error:
|
||||
continue
|
||||
|
||||
# group recordings by camera
|
||||
@@ -115,7 +115,7 @@ class RecordingMaintainer(threading.Thread):
|
||||
Event.select()
|
||||
.where(
|
||||
Event.camera == camera,
|
||||
(Event.end_time == None)
|
||||
(Event.end_time is None)
|
||||
| (Event.end_time >= recordings[0]["start_time"].timestamp()),
|
||||
Event.has_clip,
|
||||
)
|
||||
@@ -127,7 +127,7 @@ class RecordingMaintainer(threading.Thread):
|
||||
|
||||
# Just delete files if recordings are turned off
|
||||
if (
|
||||
not camera in self.config.cameras
|
||||
camera not in self.config.cameras
|
||||
or not self.process_info[camera]["record_enabled"].value
|
||||
):
|
||||
Path(cache_path).unlink(missing_ok=True)
|
||||
@@ -394,4 +394,4 @@ class RecordingMaintainer(threading.Thread):
|
||||
duration = datetime.datetime.now().timestamp() - run_start
|
||||
wait_time = max(0, 5 - duration)
|
||||
|
||||
logger.info(f"Exiting recording maintenance...")
|
||||
logger.info("Exiting recording maintenance...")
|
||||
|
||||
@@ -4,12 +4,11 @@ import logging
|
||||
import multiprocessing as mp
|
||||
import signal
|
||||
import threading
|
||||
|
||||
from setproctitle import setproctitle
|
||||
from types import FrameType
|
||||
from typing import Optional
|
||||
|
||||
from playhouse.sqliteq import SqliteQueueDatabase
|
||||
from setproctitle import setproctitle
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.models import Event, Recordings, Timeline
|
||||
|
||||
Reference in New Issue
Block a user