Add Deno version detection and caching support
Introduces functions to detect Deno version directly and with caching in ytsage_deno.py and ytsage_utils.py. Updates the About dialog to display Deno status, version, and path if available. Also extends version cache refresh logic to include Deno.
This commit is contained in:
@@ -462,6 +462,50 @@ def get_deno_path() -> Path:
|
||||
return "deno" # type: ignore[return-value]
|
||||
|
||||
|
||||
def get_deno_version_direct(deno_path=None) -> str:
|
||||
"""
|
||||
Get Deno version directly without caching.
|
||||
|
||||
Args:
|
||||
deno_path: Optional path to Deno binary. If None, uses get_deno_path()
|
||||
|
||||
Returns:
|
||||
str: Version string or error message
|
||||
"""
|
||||
try:
|
||||
if deno_path is None:
|
||||
deno_path = get_deno_path()
|
||||
|
||||
if not deno_path or deno_path == "deno":
|
||||
return "Not found"
|
||||
|
||||
result = subprocess.run(
|
||||
[str(deno_path), "--version"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
creationflags=SUBPROCESS_CREATIONFLAGS
|
||||
)
|
||||
|
||||
if result.returncode == 0:
|
||||
# Deno outputs: "deno 1.38.0 (release, x86_64-pc-windows-msvc)"
|
||||
# Extract version from first line
|
||||
lines = result.stdout.strip().split("\n")
|
||||
if lines:
|
||||
first_line = lines[0]
|
||||
# Extract version number (e.g., "1.38.0" from "deno 1.38.0 ...")
|
||||
parts = first_line.split()
|
||||
if len(parts) >= 2 and parts[0] == "deno":
|
||||
return parts[1]
|
||||
return first_line.strip()
|
||||
return "Unknown version"
|
||||
else:
|
||||
return "Error getting version"
|
||||
except Exception as e:
|
||||
logger.exception(f"Error getting Deno version: {e}")
|
||||
return "Error getting version"
|
||||
|
||||
|
||||
def setup_deno(parent_widget=None):
|
||||
"""
|
||||
Show the Deno setup dialog and handle the result.
|
||||
|
||||
@@ -45,6 +45,7 @@ except ImportError:
|
||||
_version_cache = {
|
||||
"ytdlp": {"version": None, "path": None, "last_check": 0, "path_mtime": 0},
|
||||
"ffmpeg": {"version": None, "path": None, "last_check": 0, "path_mtime": 0},
|
||||
"deno": {"version": None, "path": None, "last_check": 0, "path_mtime": 0},
|
||||
}
|
||||
|
||||
# Cache expiry time in seconds (5 minutes)
|
||||
@@ -173,8 +174,34 @@ def get_ffmpeg_version_cached() -> str:
|
||||
return "Error getting version"
|
||||
|
||||
|
||||
def get_deno_version_cached() -> str:
|
||||
"""Get Deno version with caching support."""
|
||||
try:
|
||||
from src.core.ytsage_deno import get_deno_path
|
||||
|
||||
current_path = get_deno_path()
|
||||
|
||||
# Check if we need to refresh cache
|
||||
if not should_refresh_cache("deno", current_path):
|
||||
cached_version = _version_cache["deno"].get("version")
|
||||
if cached_version:
|
||||
return cached_version
|
||||
|
||||
# Get fresh version info
|
||||
from src.core.ytsage_deno import get_deno_version_direct
|
||||
version_info = get_deno_version_direct(current_path)
|
||||
|
||||
# Update cache
|
||||
update_version_cache("deno", version_info, current_path)
|
||||
|
||||
return version_info
|
||||
except Exception as e:
|
||||
logger.exception(f"Error getting cached Deno version: {e}")
|
||||
return "Error getting version"
|
||||
|
||||
|
||||
def refresh_version_cache(force=False) -> bool:
|
||||
"""Manually refresh version cache for both tools."""
|
||||
"""Manually refresh version cache for all tools."""
|
||||
try:
|
||||
# Refresh yt-dlp
|
||||
current_path = get_yt_dlp_path()
|
||||
@@ -185,6 +212,12 @@ def refresh_version_cache(force=False) -> bool:
|
||||
version_info = get_ffmpeg_version_direct()
|
||||
update_version_cache("ffmpeg", version_info, "ffmpeg", force_save=True)
|
||||
|
||||
# Refresh Deno
|
||||
from src.core.ytsage_deno import get_deno_path, get_deno_version_direct
|
||||
deno_path = get_deno_path()
|
||||
version_info = get_deno_version_direct(deno_path)
|
||||
update_version_cache("deno", version_info, deno_path, force_save=True)
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.exception(f"Error refreshing version cache: {e}")
|
||||
@@ -201,6 +234,11 @@ def get_ffmpeg_version() -> str:
|
||||
return get_ffmpeg_version_cached()
|
||||
|
||||
|
||||
def get_deno_version() -> str:
|
||||
"""Get the version of Deno (uses cached version for performance)."""
|
||||
return get_deno_version_cached()
|
||||
|
||||
|
||||
def get_ytdlp_version_direct(yt_dlp_path=None) -> str:
|
||||
"""Get yt-dlp version directly without caching."""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user