mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 02:35:22 +03:00
Refactor recording cleanup script to use os module instead of subprocess
This commit is contained in:
parent
2e549514a5
commit
4dc3f7fa9c
@ -3,7 +3,7 @@
|
||||
import datetime
|
||||
import itertools
|
||||
import logging
|
||||
import subprocess as sp
|
||||
import os
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
@ -183,12 +183,14 @@ class RecordingCleanup(threading.Thread):
|
||||
return
|
||||
|
||||
logger.debug(f"Oldest recording in the db: {oldest_timestamp}")
|
||||
process = sp.run(
|
||||
["find", RECORD_DIR, "-type", "f", "!", "-newermt", f"@{oldest_timestamp}"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
files_to_check = process.stdout.splitlines()
|
||||
|
||||
files_to_check = []
|
||||
|
||||
for root, _, files in os.walk(RECORD_DIR):
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
if os.path.getmtime(file_path) < oldest_timestamp:
|
||||
files_to_check.append(file_path)
|
||||
|
||||
for f in files_to_check:
|
||||
p = Path(f)
|
||||
@ -207,12 +209,10 @@ class RecordingCleanup(threading.Thread):
|
||||
recordings: Recordings = Recordings.select()
|
||||
|
||||
# get all recordings files on disk
|
||||
process = sp.run(
|
||||
["find", RECORD_DIR, "-type", "f"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
files_on_disk = process.stdout.splitlines()
|
||||
files_on_disk = []
|
||||
for root, _, files in os.walk(RECORD_DIR):
|
||||
for file in files:
|
||||
files_on_disk.append(os.path.join(root, file))
|
||||
|
||||
recordings_to_delete = []
|
||||
for recording in recordings.objects().iterator():
|
||||
|
||||
Loading…
Reference in New Issue
Block a user