1 Commits

Author SHA1 Message Date
pixeebot[bot]
e632f3a7f0 Convert Eager Logging to Lazy Logging 2025-04-19 03:06:42 +00:00
7 changed files with 22 additions and 24 deletions

View File

@@ -5,7 +5,6 @@ import sys
import os import os
from pathlib import Path from pathlib import Path
from typing import Dict, Any, Optional from typing import Dict, Any, Optional
from security import safe_command
# Configure logging # Configure logging
logging.basicConfig( logging.basicConfig(
@@ -167,7 +166,8 @@ class FFmpeg:
"""Get FFmpeg version""" """Get FFmpeg version"""
try: try:
import subprocess import subprocess
result = safe_command.run(subprocess.run, [str(self.ffmpeg_path), "-version"], result = subprocess.run(
[str(self.ffmpeg_path), "-version"],
capture_output=True, capture_output=True,
text=True, text=True,
timeout=5 timeout=5

View File

@@ -19,7 +19,6 @@ import lzma
# try: # try:
# Try relative imports first # Try relative imports first
from exceptions import DownloadError from exceptions import DownloadError
from security import safe_command
# except ImportError: # except ImportError:
# Fall back to absolute imports if relative imports fail # Fall back to absolute imports if relative imports fail
@@ -353,7 +352,8 @@ class FFmpegDownloader:
# Test FFmpeg functionality with enhanced error handling # Test FFmpeg functionality with enhanced error handling
try: try:
result = safe_command.run(subprocess.run, [str(self.ffmpeg_path), "-version"], result = subprocess.run(
[str(self.ffmpeg_path), "-version"],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
timeout=5, timeout=5,
@@ -370,7 +370,8 @@ class FFmpegDownloader:
# Test FFprobe functionality with enhanced error handling # Test FFprobe functionality with enhanced error handling
try: try:
result = safe_command.run(subprocess.run, [str(self.ffprobe_path), "-version"], result = subprocess.run(
[str(self.ffprobe_path), "-version"],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
timeout=5, timeout=5,

View File

@@ -7,7 +7,6 @@ import platform
import re import re
from typing import Dict, List, Tuple from typing import Dict, List, Tuple
from pathlib import Path from pathlib import Path
from security import safe_command
logger = logging.getLogger("VideoArchiver") logger = logging.getLogger("VideoArchiver")
@@ -77,7 +76,7 @@ class GPUDetector:
try: try:
# Use PowerShell to get GPU info # Use PowerShell to get GPU info
cmd = ["powershell", "-Command", "Get-WmiObject Win32_VideoController | Select-Object Name"] cmd = ["powershell", "-Command", "Get-WmiObject Win32_VideoController | Select-Object Name"]
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10) result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
if result.returncode == 0: if result.returncode == 0:
output = result.stdout.lower() output = result.stdout.lower()
@@ -154,7 +153,7 @@ class GPUDetector:
try: try:
cmd = ["system_profiler", "SPDisplaysDataType"] cmd = ["system_profiler", "SPDisplaysDataType"]
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10) result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
if result.returncode == 0: if result.returncode == 0:
output = result.stdout.lower() output = result.stdout.lower()
@@ -174,7 +173,7 @@ class GPUDetector:
try: try:
# Check FFmpeg encoders # Check FFmpeg encoders
cmd = [str(self.ffmpeg_path), "-hide_banner", "-encoders"] cmd = [str(self.ffmpeg_path), "-hide_banner", "-encoders"]
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10) result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
if result.returncode == 0: if result.returncode == 0:
output = result.stdout.lower() output = result.stdout.lower()
@@ -251,7 +250,7 @@ class GPUDetector:
elif system == "windows": elif system == "windows":
cmd = ["powershell", "-Command", "Get-WmiObject Win32_VideoController | Select-Object Name"] cmd = ["powershell", "-Command", "Get-WmiObject Win32_VideoController | Select-Object Name"]
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10) result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
if result.returncode == 0: if result.returncode == 0:
for line in result.stdout.splitlines(): for line in result.stdout.splitlines():
@@ -266,7 +265,7 @@ class GPUDetector:
elif system == "darwin": elif system == "darwin":
cmd = ["system_profiler", "SPDisplaysDataType"] cmd = ["system_profiler", "SPDisplaysDataType"]
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True, timeout=10) result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
if result.returncode == 0: if result.returncode == 0:
current_gpu = None current_gpu = None

View File

@@ -5,7 +5,6 @@ import psutil # type: ignore
import subprocess import subprocess
import time import time
from typing import Set, Optional from typing import Set, Optional
from security import safe_command
logger = logging.getLogger("FFmpegProcessManager") logger = logging.getLogger("FFmpegProcessManager")
@@ -91,7 +90,8 @@ class ProcessManager:
""" """
process = None process = None
try: try:
process = safe_command.run(subprocess.Popen, command, process = subprocess.Popen(
command,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True text=True

View File

@@ -9,7 +9,6 @@ from contextlib import contextmanager
import tempfile import tempfile
import shutil import shutil
import json import json
from security import safe_command
logger = logging.getLogger("VideoArchiver") logger = logging.getLogger("VideoArchiver")
@@ -127,7 +126,8 @@ class VideoAnalyzer:
] ]
logger.debug(f"Running ffprobe command: {' '.join(cmd)}") logger.debug(f"Running ffprobe command: {' '.join(cmd)}")
result = safe_command.run(subprocess.run, cmd, result = subprocess.run(
cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True, text=True,
@@ -193,7 +193,8 @@ class VideoAnalyzer:
] ]
logger.debug(f"Running dark scene analysis: {' '.join(sample_cmd)}") logger.debug(f"Running dark scene analysis: {' '.join(sample_cmd)}")
result = safe_command.run(subprocess.run, sample_cmd, result = subprocess.run(
sample_cmd,
capture_output=True, capture_output=True,
text=True, text=True,
timeout=60 # Add timeout timeout=60 # Add timeout

View File

@@ -341,14 +341,11 @@ class QueueCleaner:
metrics_manager.update_cleanup_time() metrics_manager.update_cleanup_time()
logger.info( logger.info(
f"Cleanup completed ({mode.value}):\n" + "%s%s%s", f"Cleanup completed ({mode.value}):\n", "\n".join(
"\n".join(
f"- {phase.value}: {count} items" f"- {phase.value}: {count} items"
for phase, count in items_cleaned.items() for phase, count in items_cleaned.items()
if count > 0 if count > 0
) + ), f"\nTotal duration: {duration:.2f}s")
f"\nTotal duration: {duration:.2f}s"
)
except Exception as e: except Exception as e:
logger.error(f"Error during cleanup: {str(e)}") logger.error(f"Error during cleanup: {str(e)}")

View File

@@ -11,7 +11,6 @@ from pathlib import Path
from utils.exceptions import VideoVerificationError from utils.exceptions import VideoVerificationError
from utils.file_deletion import SecureFileDeleter from utils.file_deletion import SecureFileDeleter
from security import safe_command
logger = logging.getLogger("VideoArchiver") logger = logging.getLogger("VideoArchiver")
@@ -65,7 +64,8 @@ class FileOperations:
file_path, file_path,
] ]
result = safe_command.run(subprocess.run, cmd, result = subprocess.run(
cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True, text=True,
@@ -120,7 +120,7 @@ class FileOperations:
"-show_format", "-show_format",
file_path, file_path,
] ]
result = safe_command.run(subprocess.run, cmd, capture_output=True, text=True) result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0: if result.returncode != 0:
raise Exception(f"FFprobe failed: {result.stderr}") raise Exception(f"FFprobe failed: {result.stderr}")