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 datetime
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
import subprocess as sp
|
import os
|
||||||
import threading
|
import threading
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -183,12 +183,14 @@ class RecordingCleanup(threading.Thread):
|
|||||||
return
|
return
|
||||||
|
|
||||||
logger.debug(f"Oldest recording in the db: {oldest_timestamp}")
|
logger.debug(f"Oldest recording in the db: {oldest_timestamp}")
|
||||||
process = sp.run(
|
|
||||||
["find", RECORD_DIR, "-type", "f", "!", "-newermt", f"@{oldest_timestamp}"],
|
files_to_check = []
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
for root, _, files in os.walk(RECORD_DIR):
|
||||||
)
|
for file in files:
|
||||||
files_to_check = process.stdout.splitlines()
|
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:
|
for f in files_to_check:
|
||||||
p = Path(f)
|
p = Path(f)
|
||||||
@ -207,12 +209,10 @@ class RecordingCleanup(threading.Thread):
|
|||||||
recordings: Recordings = Recordings.select()
|
recordings: Recordings = Recordings.select()
|
||||||
|
|
||||||
# get all recordings files on disk
|
# get all recordings files on disk
|
||||||
process = sp.run(
|
files_on_disk = []
|
||||||
["find", RECORD_DIR, "-type", "f"],
|
for root, _, files in os.walk(RECORD_DIR):
|
||||||
capture_output=True,
|
for file in files:
|
||||||
text=True,
|
files_on_disk.append(os.path.join(root, file))
|
||||||
)
|
|
||||||
files_on_disk = process.stdout.splitlines()
|
|
||||||
|
|
||||||
recordings_to_delete = []
|
recordings_to_delete = []
|
||||||
for recording in recordings.objects().iterator():
|
for recording in recordings.objects().iterator():
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user