mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-06-19 19:18:38 +00:00
Compare commits
7 Commits
bc027c921d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d297dd6217 | ||
|
|
974d7ea57a | ||
|
|
ab0cfd2362 | ||
|
|
d22d0a3754 | ||
|
|
5beef0aa01 | ||
|
|
cf28a8c0d5 | ||
|
|
a06682981c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,6 +8,7 @@ config/config_secrets.json
|
|||||||
config/config.json
|
config/config.json
|
||||||
config/config.json.backup
|
config/config.json.backup
|
||||||
config/wifi_config.json
|
config/wifi_config.json
|
||||||
|
config/uninstalled_plugins.json
|
||||||
credentials.json
|
credentials.json
|
||||||
token.pickle
|
token.pickle
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ on_error() {
|
|||||||
echo "✗ An error occurred during: $CURRENT_STEP (line $line_no, exit $exit_code)" >&2
|
echo "✗ An error occurred during: $CURRENT_STEP (line $line_no, exit $exit_code)" >&2
|
||||||
if [ -n "${LOG_FILE:-}" ]; then
|
if [ -n "${LOG_FILE:-}" ]; then
|
||||||
echo "See the log for details: $LOG_FILE" >&2
|
echo "See the log for details: $LOG_FILE" >&2
|
||||||
echo "-- Last 50 lines from log --" >&2
|
echo "-- Last 100 lines from log --" >&2
|
||||||
tail -n 50 "$LOG_FILE" >&2 || true
|
tail -n 100 "$LOG_FILE" >&2 || true
|
||||||
fi
|
fi
|
||||||
echo "\nCommon fixes:" >&2
|
echo "\nCommon fixes:" >&2
|
||||||
echo "- Ensure the Pi is online (try: ping -c1 8.8.8.8)." >&2
|
echo "- Ensure the Pi is online (try: ping -c1 8.8.8.8)." >&2
|
||||||
@@ -202,8 +202,33 @@ retry() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
apt_update() { retry apt update; }
|
# Wait for another apt/dpkg process (commonly unattended-upgrades running
|
||||||
apt_install() { retry apt install -y "$@"; }
|
# shortly after first boot) to release its lock before we try apt ourselves.
|
||||||
|
# Without this, apt_update/apt_install can fail outright in the first couple
|
||||||
|
# minutes after a fresh Pi OS boot with a generic "Command failed after 3
|
||||||
|
# attempts" error.
|
||||||
|
wait_for_apt_lock() {
|
||||||
|
command -v flock >/dev/null 2>&1 || return 0
|
||||||
|
local lock_file="/var/lib/dpkg/lock-frontend"
|
||||||
|
local max_wait=180
|
||||||
|
local waited=0
|
||||||
|
local printed=0
|
||||||
|
while ! flock -n "$lock_file" -c true 2>/dev/null; do
|
||||||
|
if [ "$printed" -eq 0 ]; then
|
||||||
|
echo "⚠ Waiting for another apt/dpkg process to finish (e.g. unattended-upgrades on first boot)..."
|
||||||
|
printed=1
|
||||||
|
fi
|
||||||
|
if [ "$waited" -ge "$max_wait" ]; then
|
||||||
|
echo "⚠ Still waiting after ${max_wait}s; proceeding anyway."
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
waited=$((waited+5))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
apt_update() { wait_for_apt_lock; retry apt update; }
|
||||||
|
apt_install() { wait_for_apt_lock; retry apt install -y "$@"; }
|
||||||
apt_remove() { apt-get remove -y "$@" || true; }
|
apt_remove() { apt-get remove -y "$@" || true; }
|
||||||
|
|
||||||
check_network() {
|
check_network() {
|
||||||
@@ -222,6 +247,22 @@ check_network() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_disk_space() {
|
||||||
|
command -v df >/dev/null 2>&1 || return 0
|
||||||
|
local available_mb
|
||||||
|
available_mb=$(df -m "$PROJECT_ROOT_DIR" | awk 'NR==2{print $4}')
|
||||||
|
available_mb=${available_mb:-0}
|
||||||
|
if [ "$available_mb" -lt 500 ]; then
|
||||||
|
echo "✗ ERROR: Insufficient disk space: ${available_mb}MB available (need at least 500MB)"
|
||||||
|
echo " Free up space first, e.g.: sudo apt clean && sudo apt autoremove"
|
||||||
|
exit 1
|
||||||
|
elif [ "$available_mb" -lt 1024 ]; then
|
||||||
|
echo "⚠ Limited disk space: ${available_mb}MB available (recommend at least 1GB for the rpi-rgb-led-matrix build in Step 6)"
|
||||||
|
else
|
||||||
|
echo "✓ Disk space sufficient: ${available_mb}MB available"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "This script will perform the following steps:"
|
echo "This script will perform the following steps:"
|
||||||
echo "1. Install system dependencies"
|
echo "1. Install system dependencies"
|
||||||
@@ -271,8 +312,9 @@ CURRENT_STEP="Install system dependencies"
|
|||||||
echo "Step 1: Installing system dependencies..."
|
echo "Step 1: Installing system dependencies..."
|
||||||
echo "----------------------------------------"
|
echo "----------------------------------------"
|
||||||
|
|
||||||
# Ensure network is available before APT operations
|
# Pre-flight checks before APT operations
|
||||||
check_network
|
check_network
|
||||||
|
check_disk_space
|
||||||
|
|
||||||
# Update package list
|
# Update package list
|
||||||
apt_update
|
apt_update
|
||||||
@@ -822,14 +864,14 @@ else
|
|||||||
# Try to initialize submodule if .gitmodules exists
|
# Try to initialize submodule if .gitmodules exists
|
||||||
if [ -f "$PROJECT_ROOT_DIR/.gitmodules" ] && grep -q "rpi-rgb-led-matrix" "$PROJECT_ROOT_DIR/.gitmodules"; then
|
if [ -f "$PROJECT_ROOT_DIR/.gitmodules" ] && grep -q "rpi-rgb-led-matrix" "$PROJECT_ROOT_DIR/.gitmodules"; then
|
||||||
echo "Initializing rpi-rgb-led-matrix submodule..."
|
echo "Initializing rpi-rgb-led-matrix submodule..."
|
||||||
if ! git submodule update --init --recursive rpi-rgb-led-matrix-master 2>&1; then
|
if ! retry git submodule update --init --recursive rpi-rgb-led-matrix-master; then
|
||||||
echo "⚠ Submodule init failed, cloning directly from GitHub..."
|
echo "⚠ Submodule init failed, cloning directly from GitHub..."
|
||||||
git clone https://github.com/hzeller/rpi-rgb-led-matrix.git rpi-rgb-led-matrix-master
|
retry git clone https://github.com/hzeller/rpi-rgb-led-matrix.git rpi-rgb-led-matrix-master
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Fallback: clone directly if submodule not configured
|
# Fallback: clone directly if submodule not configured
|
||||||
echo "Submodule not configured, cloning directly from GitHub..."
|
echo "Submodule not configured, cloning directly from GitHub..."
|
||||||
git clone https://github.com/hzeller/rpi-rgb-led-matrix.git rpi-rgb-led-matrix-master
|
retry git clone https://github.com/hzeller/rpi-rgb-led-matrix.git rpi-rgb-led-matrix-master
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -841,9 +883,9 @@ else
|
|||||||
cd "$PROJECT_ROOT_DIR"
|
cd "$PROJECT_ROOT_DIR"
|
||||||
rm -rf rpi-rgb-led-matrix-master
|
rm -rf rpi-rgb-led-matrix-master
|
||||||
if [ -f "$PROJECT_ROOT_DIR/.gitmodules" ] && grep -q "rpi-rgb-led-matrix" "$PROJECT_ROOT_DIR/.gitmodules"; then
|
if [ -f "$PROJECT_ROOT_DIR/.gitmodules" ] && grep -q "rpi-rgb-led-matrix" "$PROJECT_ROOT_DIR/.gitmodules"; then
|
||||||
git submodule update --init --recursive rpi-rgb-led-matrix-master
|
retry git submodule update --init --recursive rpi-rgb-led-matrix-master
|
||||||
else
|
else
|
||||||
git clone https://github.com/hzeller/rpi-rgb-led-matrix.git rpi-rgb-led-matrix-master
|
retry git clone https://github.com/hzeller/rpi-rgb-led-matrix.git rpi-rgb-led-matrix-master
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -851,13 +893,24 @@ else
|
|||||||
echo "Installing rpi-rgb-led-matrix Python package (scikit-build-core + cmake)..."
|
echo "Installing rpi-rgb-led-matrix Python package (scikit-build-core + cmake)..."
|
||||||
echo " Build deps required: python-dev-is-python3 cmake"
|
echo " Build deps required: python-dev-is-python3 cmake"
|
||||||
echo " This compiles C++ — may take 2-5 minutes on Pi 4/5..."
|
echo " This compiles C++ — may take 2-5 minutes on Pi 4/5..."
|
||||||
if ! python3 -m pip install --break-system-packages .; then
|
BUILD_OUTPUT=$(mktemp)
|
||||||
|
BUILD_SUCCESS=false
|
||||||
|
if python3 -m pip install --break-system-packages . > "$BUILD_OUTPUT" 2>&1; then
|
||||||
|
BUILD_SUCCESS=true
|
||||||
|
fi
|
||||||
|
cat "$BUILD_OUTPUT" >> "$LOG_FILE"
|
||||||
|
if [ "$BUILD_SUCCESS" != true ]; then
|
||||||
echo "✗ Failed to install rpi-rgb-led-matrix Python package"
|
echo "✗ Failed to install rpi-rgb-led-matrix Python package"
|
||||||
echo " Ensure build tools are installed:"
|
echo " Ensure build tools are installed:"
|
||||||
echo " sudo apt install -y python-dev-is-python3 cmake build-essential"
|
echo " sudo apt install -y python-dev-is-python3 cmake build-essential"
|
||||||
|
echo ""
|
||||||
|
echo "-- Last 50 lines of build output --"
|
||||||
|
tail -n 50 "$BUILD_OUTPUT"
|
||||||
|
rm -f "$BUILD_OUTPUT"
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
rm -f "$BUILD_OUTPUT"
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
else
|
else
|
||||||
echo "✗ rpi-rgb-led-matrix-master directory not found at $PROJECT_ROOT_DIR"
|
echo "✗ rpi-rgb-led-matrix-master directory not found at $PROJECT_ROOT_DIR"
|
||||||
@@ -912,7 +965,9 @@ else
|
|||||||
# Try to install dependencies using the smart installer if available
|
# Try to install dependencies using the smart installer if available
|
||||||
if [ -f "$PROJECT_ROOT_DIR/scripts/install_dependencies_apt.py" ]; then
|
if [ -f "$PROJECT_ROOT_DIR/scripts/install_dependencies_apt.py" ]; then
|
||||||
echo "Using smart dependency installer..."
|
echo "Using smart dependency installer..."
|
||||||
python3 "$PROJECT_ROOT_DIR/scripts/install_dependencies_apt.py"
|
# -u: unbuffered stdout/stderr so output is captured in $LOG_FILE in
|
||||||
|
# real time and in order relative to this script's own echo statements
|
||||||
|
python3 -u "$PROJECT_ROOT_DIR/scripts/install_dependencies_apt.py"
|
||||||
else
|
else
|
||||||
echo "Using pip to install dependencies..."
|
echo "Using pip to install dependencies..."
|
||||||
if [ -f "$PROJECT_ROOT_DIR/requirements_web_v2.txt" ]; then
|
if [ -f "$PROJECT_ROOT_DIR/requirements_web_v2.txt" ]; then
|
||||||
|
|||||||
@@ -340,8 +340,13 @@ main() {
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Execute with proper error handling and non-interactive mode
|
# Execute with proper error handling and non-interactive mode
|
||||||
# Temporarily disable errexit to capture exit code instead of exiting immediately
|
# Temporarily disable errexit AND the ERR trap to capture exit code instead of
|
||||||
|
# exiting immediately. `set +e` alone does not suppress the ERR trap, so without
|
||||||
|
# `trap '' ERR` a non-zero exit from first_time_install.sh would trigger on_error
|
||||||
|
# here with the generic "Main installation" message instead of the detailed
|
||||||
|
# if/else handling below.
|
||||||
set +e
|
set +e
|
||||||
|
trap '' ERR
|
||||||
|
|
||||||
# Check /tmp permissions - only fix if actually wrong (common in automated scenarios)
|
# Check /tmp permissions - only fix if actually wrong (common in automated scenarios)
|
||||||
# When running manually, /tmp usually has correct permissions (1777)
|
# When running manually, /tmp usually has correct permissions (1777)
|
||||||
@@ -370,6 +375,7 @@ main() {
|
|||||||
sudo -E env TMPDIR=/tmp LEDMATRIX_ASSUME_YES=1 bash ./first_time_install.sh -y </dev/null
|
sudo -E env TMPDIR=/tmp LEDMATRIX_ASSUME_YES=1 bash ./first_time_install.sh -y </dev/null
|
||||||
fi
|
fi
|
||||||
INSTALL_EXIT_CODE=$?
|
INSTALL_EXIT_CODE=$?
|
||||||
|
trap 'on_error $LINENO' ERR # Re-enable ERR trap
|
||||||
set -e # Re-enable errexit
|
set -e # Re-enable errexit
|
||||||
|
|
||||||
if [ $INSTALL_EXIT_CODE -eq 0 ]; then
|
if [ $INSTALL_EXIT_CODE -eq 0 ]; then
|
||||||
|
|||||||
@@ -6,12 +6,39 @@ then falls back to pip with --break-system-packages
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
import warnings
|
import warnings
|
||||||
|
from collections import deque
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
# How many trailing lines of a failed command's output to keep for the
|
||||||
|
# end-of-run failure summary. Keeps the root cause near the end of the log,
|
||||||
|
# which is where first_time_install.sh's error handler tails from.
|
||||||
|
ERROR_TAIL_LINES = 15
|
||||||
|
|
||||||
|
|
||||||
|
def _run(cmd):
|
||||||
|
"""Run a command, streaming combined stdout/stderr to a temp file.
|
||||||
|
|
||||||
|
Returns (success, output) instead of raising, so callers can report
|
||||||
|
*why* a command failed rather than just that it failed. `output` is
|
||||||
|
bounded to the last ERROR_TAIL_LINES lines so failures from very
|
||||||
|
chatty commands (e.g. pip build logs) don't get buffered in memory.
|
||||||
|
"""
|
||||||
|
with tempfile.TemporaryFile(mode='w+b') as f:
|
||||||
|
result = subprocess.run(cmd, stdout=f, stderr=subprocess.STDOUT) # nosec B603 B607 - hardcoded apt/pip args # nosemgrep
|
||||||
|
f.seek(0)
|
||||||
|
# Stream line-by-line so only the last ERROR_TAIL_LINES are ever held
|
||||||
|
# in memory, regardless of how much output the command produced.
|
||||||
|
tail = deque(
|
||||||
|
(line.decode('utf-8', errors='replace').rstrip('\n') for line in f),
|
||||||
|
maxlen=ERROR_TAIL_LINES,
|
||||||
|
)
|
||||||
|
return result.returncode == 0, '\n'.join(tail)
|
||||||
|
|
||||||
|
|
||||||
def install_via_apt(package_name):
|
def install_via_apt(package_name):
|
||||||
"""Try to install a package via apt."""
|
"""Try to install a package via apt. Returns (success, output)."""
|
||||||
try:
|
|
||||||
# Map pip package names to apt package names
|
# Map pip package names to apt package names
|
||||||
apt_package_map = {
|
apt_package_map = {
|
||||||
'flask': 'python3-flask',
|
'flask': 'python3-flask',
|
||||||
@@ -32,20 +59,14 @@ def install_via_apt(package_name):
|
|||||||
apt_package = apt_package_map.get(package_name, f'python3-{package_name}')
|
apt_package = apt_package_map.get(package_name, f'python3-{package_name}')
|
||||||
|
|
||||||
print(f"Trying to install {apt_package} via apt...")
|
print(f"Trying to install {apt_package} via apt...")
|
||||||
subprocess.check_call([
|
success, output = _run(['sudo', 'apt', 'install', '-y', apt_package])
|
||||||
'sudo', 'apt', 'update'
|
if success:
|
||||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
||||||
|
|
||||||
subprocess.check_call([
|
|
||||||
'sudo', 'apt', 'install', '-y', apt_package
|
|
||||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
||||||
|
|
||||||
print(f"Successfully installed {apt_package} via apt")
|
print(f"Successfully installed {apt_package} via apt")
|
||||||
return True
|
return True, ""
|
||||||
|
|
||||||
|
print(f"Failed to install {apt_package} via apt, will try pip")
|
||||||
|
return False, output
|
||||||
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
print(f"Failed to install {package_name} via apt, will try pip")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def install_via_pip(package_name):
|
def install_via_pip(package_name):
|
||||||
"""Install a package via pip with --break-system-packages and --prefer-binary.
|
"""Install a package via pip with --break-system-packages and --prefer-binary.
|
||||||
@@ -54,34 +75,73 @@ def install_via_pip(package_name):
|
|||||||
Debian/Ubuntu-based systems without a virtual environment.
|
Debian/Ubuntu-based systems without a virtual environment.
|
||||||
--prefer-binary prefers pre-built wheels over source distributions to avoid
|
--prefer-binary prefers pre-built wheels over source distributions to avoid
|
||||||
exhausting /tmp space during compilation.
|
exhausting /tmp space during compilation.
|
||||||
|
--ignore-installed stops pip from trying to *uninstall* packages that were
|
||||||
|
installed by apt (e.g. python3-requests). Those Debian packages ship no
|
||||||
|
pip RECORD file, so an uninstall attempt fails with "uninstall-no-record-file"
|
||||||
|
and aborts the whole install. With --ignore-installed, pip lays the new
|
||||||
|
version down in /usr/local where it shadows the apt copy instead of removing
|
||||||
|
it. This matters when a pip dependency (google-api-python-client pulls a
|
||||||
|
newer requests) needs to upgrade an apt-managed package.
|
||||||
|
|
||||||
|
Returns (success, output).
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
print(f"Installing {package_name} via pip...")
|
print(f"Installing {package_name} via pip...")
|
||||||
subprocess.check_call([
|
success, output = _run([
|
||||||
sys.executable, '-m', 'pip', 'install', '--break-system-packages', '--prefer-binary', package_name
|
sys.executable, '-m', 'pip', 'install',
|
||||||
|
'--break-system-packages', '--prefer-binary', '--ignore-installed', package_name
|
||||||
])
|
])
|
||||||
|
if success:
|
||||||
print(f"Successfully installed {package_name} via pip")
|
print(f"Successfully installed {package_name} via pip")
|
||||||
return True
|
return True, ""
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print(f"Failed to install {package_name} via pip: {e}")
|
print(f"Failed to install {package_name} via pip (see failure summary at end of log)")
|
||||||
return False
|
return False, output
|
||||||
|
|
||||||
|
|
||||||
|
# Distribution (pip/apt) names whose importable module name differs.
|
||||||
|
IMPORT_NAME_MAP = {
|
||||||
|
'python-dateutil': 'dateutil',
|
||||||
|
'websocket-client': 'websocket',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def check_package_installed(package_name):
|
def check_package_installed(package_name):
|
||||||
"""Check if a package is already installed."""
|
"""Check if a package is already installed."""
|
||||||
|
import_name = IMPORT_NAME_MAP.get(package_name, package_name)
|
||||||
# Suppress deprecation warnings when checking if packages are installed
|
# Suppress deprecation warnings when checking if packages are installed
|
||||||
# (we're just checking, not using them)
|
# (we're just checking, not using them)
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
warnings.filterwarnings('ignore', category=DeprecationWarning)
|
||||||
try:
|
try:
|
||||||
__import__(package_name)
|
__import__(import_name)
|
||||||
return True
|
return True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def print_failure_summary(failed_packages, failure_details):
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
print("DEPENDENCY INSTALLATION FAILURES - DETAILS")
|
||||||
|
print("=" * 60)
|
||||||
|
for package in failed_packages:
|
||||||
|
print(f"\nPackage: {package}")
|
||||||
|
print("-" * 40)
|
||||||
|
output = failure_details.get(package, "").strip()
|
||||||
|
if not output:
|
||||||
|
print(" (no output captured)")
|
||||||
|
continue
|
||||||
|
for line in output.splitlines()[-ERROR_TAIL_LINES:]:
|
||||||
|
print(f" {line}")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main installation function."""
|
"""Main installation function."""
|
||||||
print("Installing dependencies for LED Matrix Web Interface V2...")
|
print("Installing dependencies for LED Matrix Web Interface V2...")
|
||||||
|
|
||||||
|
print("Refreshing apt package index...")
|
||||||
|
_run(['sudo', 'apt', 'update']) # best-effort; individual installs surface their own errors
|
||||||
|
|
||||||
# List of required packages
|
# List of required packages
|
||||||
required_packages = [
|
required_packages = [
|
||||||
'flask',
|
'flask',
|
||||||
@@ -100,6 +160,7 @@ def main():
|
|||||||
]
|
]
|
||||||
|
|
||||||
failed_packages = []
|
failed_packages = []
|
||||||
|
failure_details = {}
|
||||||
|
|
||||||
for package in required_packages:
|
for package in required_packages:
|
||||||
if check_package_installed(package):
|
if check_package_installed(package):
|
||||||
@@ -107,9 +168,12 @@ def main():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Try apt first, then pip
|
# Try apt first, then pip
|
||||||
if not install_via_apt(package):
|
ok, apt_output = install_via_apt(package)
|
||||||
if not install_via_pip(package):
|
if not ok:
|
||||||
|
ok, pip_output = install_via_pip(package)
|
||||||
|
if not ok:
|
||||||
failed_packages.append(package)
|
failed_packages.append(package)
|
||||||
|
failure_details[package] = pip_output or apt_output
|
||||||
|
|
||||||
# Install packages that don't have apt equivalents
|
# Install packages that don't have apt equivalents
|
||||||
special_packages = [
|
special_packages = [
|
||||||
@@ -124,8 +188,10 @@ def main():
|
|||||||
]
|
]
|
||||||
|
|
||||||
for package in special_packages:
|
for package in special_packages:
|
||||||
if not install_via_pip(package):
|
ok, pip_output = install_via_pip(package)
|
||||||
|
if not ok:
|
||||||
failed_packages.append(package)
|
failed_packages.append(package)
|
||||||
|
failure_details[package] = pip_output
|
||||||
|
|
||||||
# Install rgbmatrix module from local source (optional - may already be installed in Step 6)
|
# Install rgbmatrix module from local source (optional - may already be installed in Step 6)
|
||||||
# Check if already installed first
|
# Check if already installed first
|
||||||
@@ -133,7 +199,6 @@ def main():
|
|||||||
print("rgbmatrix module already installed, skipping...")
|
print("rgbmatrix module already installed, skipping...")
|
||||||
else:
|
else:
|
||||||
print("Installing rgbmatrix module from local source...")
|
print("Installing rgbmatrix module from local source...")
|
||||||
try:
|
|
||||||
# Get project root (parent of scripts directory)
|
# Get project root (parent of scripts directory)
|
||||||
PROJECT_ROOT = Path(__file__).parent.parent
|
PROJECT_ROOT = Path(__file__).parent.parent
|
||||||
rgbmatrix_path = PROJECT_ROOT / 'rpi-rgb-led-matrix-master' / 'bindings' / 'python'
|
rgbmatrix_path = PROJECT_ROOT / 'rpi-rgb-led-matrix-master' / 'bindings' / 'python'
|
||||||
@@ -143,26 +208,27 @@ def main():
|
|||||||
if setup_py.exists():
|
if setup_py.exists():
|
||||||
# Try installing - use regular install, not editable mode
|
# Try installing - use regular install, not editable mode
|
||||||
# This is optional for web interface and should already be installed in Step 6
|
# This is optional for web interface and should already be installed in Step 6
|
||||||
subprocess.check_call([
|
ok, output = _run([sys.executable, '-m', 'pip', 'install', '--break-system-packages', '--ignore-installed', str(rgbmatrix_path)])
|
||||||
sys.executable, '-m', 'pip', 'install', '--break-system-packages', str(rgbmatrix_path)
|
if ok:
|
||||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
||||||
print("rgbmatrix module installed successfully")
|
print("rgbmatrix module installed successfully")
|
||||||
|
else:
|
||||||
|
# Don't fail the whole installation - rgbmatrix is optional for web interface
|
||||||
|
# and should be installed in Step 6 of first_time_install.sh
|
||||||
|
print("Warning: Failed to install rgbmatrix module:")
|
||||||
|
for line in output.strip().splitlines()[-ERROR_TAIL_LINES:]:
|
||||||
|
print(f" {line}")
|
||||||
|
print(" This is normal if rgbmatrix hasn't been built yet (Step 6).")
|
||||||
|
print(" The web interface will work without it.")
|
||||||
else:
|
else:
|
||||||
print("Warning: rgbmatrix setup.py not found, module may need to be built first")
|
print("Warning: rgbmatrix setup.py not found, module may need to be built first")
|
||||||
print(" This is normal if Step 6 hasn't completed yet.")
|
print(" This is normal if Step 6 hasn't completed yet.")
|
||||||
else:
|
else:
|
||||||
print("Warning: rgbmatrix source not found (this is normal if Step 6 hasn't run yet)")
|
print("Warning: rgbmatrix source not found (this is normal if Step 6 hasn't run yet)")
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
# Don't fail the whole installation - rgbmatrix is optional for web interface
|
|
||||||
# and should be installed in Step 6 of first_time_install.sh
|
|
||||||
print(f"Warning: Failed to install rgbmatrix module: {e}")
|
|
||||||
print(" This is normal if rgbmatrix hasn't been built yet (Step 6).")
|
|
||||||
print(" The web interface will work without it.")
|
|
||||||
# Don't add to failed_packages since it's optional
|
|
||||||
|
|
||||||
if failed_packages:
|
if failed_packages:
|
||||||
print(f"\nFailed to install the following packages: {failed_packages}")
|
print(f"\nFailed to install the following packages: {failed_packages}")
|
||||||
print("You may need to install them manually or check your system configuration.")
|
print("You may need to install them manually or check your system configuration.")
|
||||||
|
print_failure_summary(failed_packages, failure_details)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
print("\nAll dependencies installed successfully!")
|
print("\nAll dependencies installed successfully!")
|
||||||
|
|||||||
@@ -1505,30 +1505,68 @@ class DisplayController:
|
|||||||
logger.info("Live priority ended - resuming rotation at %s", self.current_display_mode)
|
logger.info("Live priority ended - resuming rotation at %s", self.current_display_mode)
|
||||||
self._live_resume_index = None
|
self._live_resume_index = None
|
||||||
|
|
||||||
def _check_live_priority(self):
|
def _collect_live_modes(self):
|
||||||
"""
|
"""Return every currently live-priority mode, in registration order.
|
||||||
Check all plugins for live priority content.
|
|
||||||
Returns the mode that should be displayed if live content is found, None otherwise.
|
Scans all registered plugin modes; for each plugin that has live
|
||||||
|
priority *and* live content, collects the specific live mode(s) it
|
||||||
|
reports via get_live_modes() (only those actually registered), falling
|
||||||
|
back to the scanned mode name when it ends in '_live'. Deduplicated,
|
||||||
|
preserving order. A plugin registered under several mode keys (the
|
||||||
|
sports plugins register one per league) contributes each live mode once.
|
||||||
"""
|
"""
|
||||||
|
live = []
|
||||||
|
seen = set()
|
||||||
for mode_name, plugin_instance in self.plugin_modes.items():
|
for mode_name, plugin_instance in self.plugin_modes.items():
|
||||||
if hasattr(plugin_instance, 'has_live_priority') and hasattr(plugin_instance, 'has_live_content'):
|
if not (hasattr(plugin_instance, 'has_live_priority')
|
||||||
|
and hasattr(plugin_instance, 'has_live_content')):
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
if plugin_instance.has_live_priority() and plugin_instance.has_live_content():
|
if not (plugin_instance.has_live_priority()
|
||||||
# Get the specific live mode from the plugin if available
|
and plugin_instance.has_live_content()):
|
||||||
|
continue
|
||||||
|
resolved = []
|
||||||
if hasattr(plugin_instance, 'get_live_modes'):
|
if hasattr(plugin_instance, 'get_live_modes'):
|
||||||
live_modes = plugin_instance.get_live_modes()
|
for suggested_mode in (plugin_instance.get_live_modes() or []):
|
||||||
if live_modes and len(live_modes) > 0:
|
|
||||||
# Verify the mode actually exists before returning it
|
|
||||||
for suggested_mode in live_modes:
|
|
||||||
if suggested_mode in self.plugin_modes:
|
if suggested_mode in self.plugin_modes:
|
||||||
return suggested_mode
|
resolved.append(suggested_mode)
|
||||||
# If suggested modes don't exist, fall through to check current mode
|
if not resolved and mode_name.endswith('_live'):
|
||||||
# Fallback: if this mode ends with _live, return it
|
resolved.append(mode_name)
|
||||||
if mode_name.endswith('_live'):
|
for m in resolved:
|
||||||
return mode_name
|
if m not in seen:
|
||||||
|
seen.add(m)
|
||||||
|
live.append(m)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("Error checking live priority for %s: %s", mode_name, e)
|
logger.warning("Error checking live priority for %s: %s", mode_name, e)
|
||||||
|
return live
|
||||||
|
|
||||||
|
def _check_live_priority(self, advance=False):
|
||||||
|
"""Return the live-priority mode to display, or None if nothing is live.
|
||||||
|
|
||||||
|
When several plugins report live content at once (e.g. a baseball game
|
||||||
|
and a soccer match), this round-robins between them so the display
|
||||||
|
alternates each dwell instead of pinning to whichever plugin is first in
|
||||||
|
registration order.
|
||||||
|
|
||||||
|
advance=False (default): a non-advancing peek — returns the live mode
|
||||||
|
already on screen if it is still live, otherwise the first live mode.
|
||||||
|
Used by the Vegas coordinator and the vegas-active check, which only
|
||||||
|
need to know whether *any* game is live (and must not spin the cursor).
|
||||||
|
|
||||||
|
advance=True: the rotation pick — returns the live mode *after* the one
|
||||||
|
currently shown, so each dwell advances to the next live game. The
|
||||||
|
currently-displayed mode is the cursor, so this stays correct as games
|
||||||
|
start and end (no separate index to keep in sync).
|
||||||
|
"""
|
||||||
|
live_modes = self._collect_live_modes()
|
||||||
|
if not live_modes:
|
||||||
return None
|
return None
|
||||||
|
if self.current_display_mode in live_modes:
|
||||||
|
if advance:
|
||||||
|
idx = live_modes.index(self.current_display_mode)
|
||||||
|
return live_modes[(idx + 1) % len(live_modes)]
|
||||||
|
return self.current_display_mode
|
||||||
|
return live_modes[0]
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Run the display controller, switching between displays."""
|
"""Run the display controller, switching between displays."""
|
||||||
@@ -1689,9 +1727,11 @@ class DisplayController:
|
|||||||
# Display failed, clear the status and continue normally
|
# Display failed, clear the status and continue normally
|
||||||
wifi_status_data = None
|
wifi_status_data = None
|
||||||
|
|
||||||
# Check for live priority content and switch to it immediately
|
# Check for live priority content and switch to it immediately.
|
||||||
|
# advance=True so multiple simultaneously-live games take turns
|
||||||
|
# (round-robin) instead of pinning to the first plugin.
|
||||||
if not self.on_demand_active and not wifi_status_data:
|
if not self.on_demand_active and not wifi_status_data:
|
||||||
live_priority_mode = self._check_live_priority()
|
live_priority_mode = self._check_live_priority(advance=True)
|
||||||
self._apply_live_priority(live_priority_mode)
|
self._apply_live_priority(live_priority_mode)
|
||||||
|
|
||||||
# Vegas scroll mode - continuous ticker across all plugins
|
# Vegas scroll mode - continuous ticker across all plugins
|
||||||
@@ -2186,6 +2226,23 @@ class DisplayController:
|
|||||||
loop_completed = True
|
loop_completed = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# LOAD-BEARING: if current_display_mode changed mid-loop (on-demand
|
||||||
|
# activation, live priority, etc.), restart the main loop now instead
|
||||||
|
# of falling into the "honour minimum duration" sleep below. That sleep
|
||||||
|
# can run for up to the *previous* mode's full display_duration (default
|
||||||
|
# 30s) and doesn't poll on-demand requests or re-check the mode, so a
|
||||||
|
# freshly-requested mode switch would sit invisible for up to 30s — or
|
||||||
|
# get clobbered by a queued stop request — before ever rendering.
|
||||||
|
#
|
||||||
|
# This guard was added in #298 (live priority interrupting long display
|
||||||
|
# durations) and was accidentally dropped in #330 as collateral damage of
|
||||||
|
# an unrelated time.monotonic() -> time.time() cleanup in the same hunk.
|
||||||
|
# Removing it again will silently reintroduce both issues. _activate_on_demand
|
||||||
|
# already sets force_change=True and clears the display, so the next loop
|
||||||
|
# iteration renders the new mode immediately.
|
||||||
|
if self.current_display_mode != active_mode:
|
||||||
|
continue
|
||||||
|
|
||||||
# Ensure we honour minimum duration when not dynamic and loop ended early
|
# Ensure we honour minimum duration when not dynamic and loop ended early
|
||||||
if (
|
if (
|
||||||
not dynamic_enabled
|
not dynamic_enabled
|
||||||
|
|||||||
@@ -322,10 +322,19 @@ class StateReconciliation:
|
|||||||
and hasattr(self.store_manager, 'was_recently_uninstalled')
|
and hasattr(self.store_manager, 'was_recently_uninstalled')
|
||||||
and self.store_manager.was_recently_uninstalled(plugin_id)
|
and self.store_manager.was_recently_uninstalled(plugin_id)
|
||||||
)
|
)
|
||||||
|
# Also refuse to resurrect a plugin the user has persistently
|
||||||
|
# uninstalled. Unlike the in-memory race guard above, this record
|
||||||
|
# survives restarts, so the user's removal sticks across updates.
|
||||||
|
persistently_uninstalled = (
|
||||||
|
self.store_manager is not None
|
||||||
|
and hasattr(self.store_manager, 'is_plugin_uninstalled')
|
||||||
|
and self.store_manager.is_plugin_uninstalled(plugin_id)
|
||||||
|
)
|
||||||
can_repair = (
|
can_repair = (
|
||||||
self.store_manager is not None
|
self.store_manager is not None
|
||||||
and not previously_unrecoverable
|
and not previously_unrecoverable
|
||||||
and not recently_uninstalled
|
and not recently_uninstalled
|
||||||
|
and not persistently_uninstalled
|
||||||
)
|
)
|
||||||
inconsistencies.append(Inconsistency(
|
inconsistencies.append(Inconsistency(
|
||||||
plugin_id=plugin_id,
|
plugin_id=plugin_id,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from both the official registry and custom GitHub repositories.
|
|||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import json
|
import json
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -19,7 +20,7 @@ import time
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Dict, Optional, Any, Tuple
|
from typing import List, Dict, Optional, Any, Tuple, Set
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
@@ -44,12 +45,23 @@ class PluginStoreManager:
|
|||||||
|
|
||||||
REGISTRY_URL = "https://raw.githubusercontent.com/ChuckBuilds/ledmatrix-plugins/main/plugins.json"
|
REGISTRY_URL = "https://raw.githubusercontent.com/ChuckBuilds/ledmatrix-plugins/main/plugins.json"
|
||||||
|
|
||||||
def __init__(self, plugins_dir: str = "plugins"):
|
# A valid plugin id is a single path component: starts alphanumeric, then
|
||||||
|
# alphanumerics / dot / dash / underscore. Used to keep the uninstall
|
||||||
|
# registry from ever turning a corrupt or hand-edited entry (e.g. "",
|
||||||
|
# "..", "../x") into a filesystem path that purge_uninstalled_plugins
|
||||||
|
# would delete — an empty id resolves to the plugins root itself.
|
||||||
|
_PLUGIN_ID_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]*$")
|
||||||
|
|
||||||
|
def __init__(self, plugins_dir: str = "plugins",
|
||||||
|
uninstalled_registry_path: Optional[str] = None):
|
||||||
"""
|
"""
|
||||||
Initialize the plugin store manager.
|
Initialize the plugin store manager.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
plugins_dir: Directory where plugins are installed
|
plugins_dir: Directory where plugins are installed
|
||||||
|
uninstalled_registry_path: Path to the JSON file recording plugins
|
||||||
|
the user has uninstalled. Defaults to
|
||||||
|
``config/uninstalled_plugins.json`` under the project root.
|
||||||
"""
|
"""
|
||||||
self.plugins_dir = Path(plugins_dir)
|
self.plugins_dir = Path(plugins_dir)
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
@@ -84,6 +96,25 @@ class PluginStoreManager:
|
|||||||
self._uninstall_tombstones: Dict[str, float] = {}
|
self._uninstall_tombstones: Dict[str, float] = {}
|
||||||
self._uninstall_tombstone_ttl = 300 # 5 minutes
|
self._uninstall_tombstone_ttl = 300 # 5 minutes
|
||||||
|
|
||||||
|
# Persistent record of plugins the user has uninstalled. Unlike the
|
||||||
|
# in-memory tombstones above (a short-lived race guard), this survives
|
||||||
|
# restarts so that a core ``git pull`` update cannot resurrect a
|
||||||
|
# built-in plugin the user removed. Built-in plugins (e.g.
|
||||||
|
# ``web-ui-info``, ``starlark-apps``) are committed into the repo under
|
||||||
|
# ``plugin-repos/``, so a plain ``git pull`` restores their files even
|
||||||
|
# after the user deleted them. ``purge_uninstalled_plugins`` re-removes
|
||||||
|
# any such resurrected directory; ``install_plugin`` clears the record
|
||||||
|
# when the user deliberately reinstalls. The file is gitignored.
|
||||||
|
if uninstalled_registry_path is not None:
|
||||||
|
self._uninstalled_registry_path = Path(uninstalled_registry_path)
|
||||||
|
else:
|
||||||
|
self._uninstalled_registry_path = (
|
||||||
|
Path(__file__).parent.parent.parent / "config" / "uninstalled_plugins.json"
|
||||||
|
)
|
||||||
|
# Serializes read-modify-write of the registry file so concurrent
|
||||||
|
# install/uninstall requests can't lose updates.
|
||||||
|
self._uninstalled_registry_lock = threading.Lock()
|
||||||
|
|
||||||
# Cache for _get_local_git_info: {plugin_path_str: (signature, data)}
|
# Cache for _get_local_git_info: {plugin_path_str: (signature, data)}
|
||||||
# where ``signature`` is a tuple of (head_mtime, resolved_ref_mtime,
|
# where ``signature`` is a tuple of (head_mtime, resolved_ref_mtime,
|
||||||
# head_contents) so a fast-forward update to the current branch
|
# head_contents) so a fast-forward update to the current branch
|
||||||
@@ -143,6 +174,135 @@ class PluginStoreManager:
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _is_valid_plugin_id(self, plugin_id: Any) -> bool:
|
||||||
|
"""Return True if ``plugin_id`` is a safe single-component plugin id.
|
||||||
|
|
||||||
|
Rejects empty strings, anything with a path separator, and traversal
|
||||||
|
sequences like ``..`` so a registry entry can never escape (or target
|
||||||
|
the root of) ``self.plugins_dir`` during a purge.
|
||||||
|
"""
|
||||||
|
return isinstance(plugin_id, str) and bool(self._PLUGIN_ID_RE.match(plugin_id))
|
||||||
|
|
||||||
|
def _read_uninstalled_registry(self) -> Set[str]:
|
||||||
|
"""Read the persistent set of uninstalled plugin IDs.
|
||||||
|
|
||||||
|
Returns an empty set if the file is missing, unreadable, or corrupt —
|
||||||
|
a broken registry must never block normal plugin operations. Invalid
|
||||||
|
ids are dropped here so callers never turn them into paths.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if not self._uninstalled_registry_path.exists():
|
||||||
|
return set()
|
||||||
|
with open(self._uninstalled_registry_path, 'r', encoding='utf-8') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
if not isinstance(data, list):
|
||||||
|
self.logger.warning(
|
||||||
|
"Uninstalled-plugin registry at %s is not a list; ignoring it",
|
||||||
|
self._uninstalled_registry_path,
|
||||||
|
)
|
||||||
|
return set()
|
||||||
|
valid: Set[str] = set()
|
||||||
|
for pid in data:
|
||||||
|
if self._is_valid_plugin_id(pid):
|
||||||
|
valid.add(pid)
|
||||||
|
else:
|
||||||
|
self.logger.warning(
|
||||||
|
"Ignoring invalid plugin id in uninstall registry: %r", pid
|
||||||
|
)
|
||||||
|
return valid
|
||||||
|
except (OSError, ValueError) as e:
|
||||||
|
self.logger.warning(
|
||||||
|
"Could not read uninstalled-plugin registry at %s: %s",
|
||||||
|
self._uninstalled_registry_path, e,
|
||||||
|
)
|
||||||
|
return set()
|
||||||
|
|
||||||
|
def _write_uninstalled_registry(self, plugin_ids: Set[str]) -> None:
|
||||||
|
"""Persist the set of uninstalled plugin IDs (sorted, atomically)."""
|
||||||
|
path = self._uninstalled_registry_path
|
||||||
|
try:
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
tmp_path = path.with_suffix(path.suffix + ".tmp")
|
||||||
|
with open(tmp_path, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(sorted(plugin_ids), f, indent=2)
|
||||||
|
os.replace(tmp_path, path)
|
||||||
|
except OSError as e:
|
||||||
|
self.logger.error(
|
||||||
|
"Failed to write uninstalled-plugin registry at %s: %s", path, e
|
||||||
|
)
|
||||||
|
|
||||||
|
def record_uninstalled_plugin(self, plugin_id: str) -> None:
|
||||||
|
"""Persistently record that the user uninstalled ``plugin_id``.
|
||||||
|
|
||||||
|
Survives restarts so a core update cannot resurrect the plugin.
|
||||||
|
"""
|
||||||
|
if not self._is_valid_plugin_id(plugin_id):
|
||||||
|
self.logger.error("Refusing to record invalid plugin id: %r", plugin_id)
|
||||||
|
return
|
||||||
|
with self._uninstalled_registry_lock:
|
||||||
|
recorded = self._read_uninstalled_registry()
|
||||||
|
if plugin_id not in recorded:
|
||||||
|
recorded.add(plugin_id)
|
||||||
|
self._write_uninstalled_registry(recorded)
|
||||||
|
self.logger.info("Recorded %s as uninstalled (persistent)", plugin_id)
|
||||||
|
|
||||||
|
def forget_uninstalled_plugin(self, *plugin_ids: str) -> None:
|
||||||
|
"""Drop ``plugin_ids`` from the persistent uninstall registry.
|
||||||
|
|
||||||
|
Called when a plugin is deliberately (re)installed so future updates
|
||||||
|
keep it.
|
||||||
|
"""
|
||||||
|
with self._uninstalled_registry_lock:
|
||||||
|
recorded = self._read_uninstalled_registry()
|
||||||
|
to_remove = {pid for pid in plugin_ids if pid in recorded}
|
||||||
|
if to_remove:
|
||||||
|
self._write_uninstalled_registry(recorded - to_remove)
|
||||||
|
self.logger.info(
|
||||||
|
"Cleared uninstall record for %s", ", ".join(sorted(to_remove))
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_uninstalled_plugins(self) -> Set[str]:
|
||||||
|
"""Return the persistent set of user-uninstalled plugin IDs."""
|
||||||
|
return self._read_uninstalled_registry()
|
||||||
|
|
||||||
|
def is_plugin_uninstalled(self, plugin_id: str) -> bool:
|
||||||
|
"""Return True if ``plugin_id`` is in the persistent uninstall registry."""
|
||||||
|
return plugin_id in self._read_uninstalled_registry()
|
||||||
|
|
||||||
|
def purge_uninstalled_plugins(self) -> List[str]:
|
||||||
|
"""Remove on-disk directories for plugins the user has uninstalled.
|
||||||
|
|
||||||
|
Built-in plugins committed into the repo are restored on disk by a
|
||||||
|
core ``git pull``; this re-removes any that the user previously
|
||||||
|
uninstalled. The registry entries are kept so the purge is idempotent
|
||||||
|
across every future update (until the user reinstalls). Returns the
|
||||||
|
list of plugin IDs whose directories were actually removed.
|
||||||
|
"""
|
||||||
|
removed: List[str] = []
|
||||||
|
plugins_root = self.plugins_dir.resolve()
|
||||||
|
for plugin_id in sorted(self._read_uninstalled_registry()):
|
||||||
|
plugin_path = self.plugins_dir / plugin_id
|
||||||
|
# Defense in depth: ids are already validated on read, but never
|
||||||
|
# remove anything that isn't a direct child of the plugins root.
|
||||||
|
resolved = plugin_path.resolve()
|
||||||
|
if resolved == plugins_root or resolved.parent != plugins_root:
|
||||||
|
self.logger.error(
|
||||||
|
"Refusing to purge unsafe plugin path for id %r", plugin_id
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
if not plugin_path.exists():
|
||||||
|
continue
|
||||||
|
self.logger.info(
|
||||||
|
"Purging resurrected uninstalled plugin: %s", plugin_id
|
||||||
|
)
|
||||||
|
if self._safe_remove_directory(plugin_path):
|
||||||
|
removed.append(plugin_id)
|
||||||
|
else:
|
||||||
|
self.logger.error(
|
||||||
|
"Failed to purge resurrected plugin directory: %s", plugin_path
|
||||||
|
)
|
||||||
|
return removed
|
||||||
|
|
||||||
def _load_github_token(self) -> Optional[str]:
|
def _load_github_token(self) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
Load GitHub API token from config_secrets.json if available.
|
Load GitHub API token from config_secrets.json if available.
|
||||||
@@ -1024,6 +1184,10 @@ class PluginStoreManager:
|
|||||||
branch_info = f" (branch: {branch})" if branch else " (latest branch head)"
|
branch_info = f" (branch: {branch})" if branch else " (latest branch head)"
|
||||||
self.logger.info(f"Installing plugin: {plugin_id}{branch_info}")
|
self.logger.info(f"Installing plugin: {plugin_id}{branch_info}")
|
||||||
|
|
||||||
|
# Remember the originally-requested id so we can clear its uninstall
|
||||||
|
# record on success even if the manifest renames the directory below.
|
||||||
|
requested_id = plugin_id
|
||||||
|
|
||||||
plugin_info = self.get_plugin_info(plugin_id, fetch_latest_from_github=True, force_refresh=True)
|
plugin_info = self.get_plugin_info(plugin_id, fetch_latest_from_github=True, force_refresh=True)
|
||||||
if not plugin_info:
|
if not plugin_info:
|
||||||
self.logger.error(f"Plugin not found in registry: {plugin_id}")
|
self.logger.error(f"Plugin not found in registry: {plugin_id}")
|
||||||
@@ -1162,6 +1326,9 @@ class PluginStoreManager:
|
|||||||
|
|
||||||
branch_display = branch_used or plugin_info.get('branch') or plugin_info.get('default_branch', 'unknown')
|
branch_display = branch_used or plugin_info.get('branch') or plugin_info.get('default_branch', 'unknown')
|
||||||
self.logger.info(f"Successfully installed plugin: {plugin_id} (branch {branch_display})")
|
self.logger.info(f"Successfully installed plugin: {plugin_id} (branch {branch_display})")
|
||||||
|
# User deliberately (re)installed this plugin — clear any persistent
|
||||||
|
# uninstall record so future core updates keep it.
|
||||||
|
self.forget_uninstalled_plugin(requested_id, plugin_id)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -214,6 +214,104 @@ class TestDisplayControllerLivePriority:
|
|||||||
assert controller.current_mode_index == 1
|
assert controller.current_mode_index == 1
|
||||||
assert controller.current_display_mode == "b"
|
assert controller.current_display_mode == "b"
|
||||||
|
|
||||||
|
# --- Round-robin between multiple simultaneous live games --------------
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _live_plugin(live_modes):
|
||||||
|
"""A mock plugin that is live and reports the given live mode names."""
|
||||||
|
p = MagicMock()
|
||||||
|
p.has_live_priority = MagicMock(return_value=True)
|
||||||
|
p.has_live_content = MagicMock(return_value=True)
|
||||||
|
p.get_live_modes = MagicMock(return_value=list(live_modes))
|
||||||
|
return p
|
||||||
|
|
||||||
|
def test_collect_live_modes_dedupes_multi_mode_plugin(self, test_display_controller):
|
||||||
|
"""A sports plugin registered under several mode keys (one per league)
|
||||||
|
contributes each live mode once, in registration order; plugins with no
|
||||||
|
live content are skipped."""
|
||||||
|
controller = test_display_controller
|
||||||
|
baseball = self._live_plugin(["baseball_live"])
|
||||||
|
soccer = self._live_plugin(["soccer_fifa.world_live"])
|
||||||
|
idle = MagicMock()
|
||||||
|
idle.has_live_priority = MagicMock(return_value=True)
|
||||||
|
idle.has_live_content = MagicMock(return_value=False)
|
||||||
|
controller.plugin_modes = {
|
||||||
|
"baseball_live": baseball,
|
||||||
|
"baseball_recent": baseball,
|
||||||
|
"soccer_fifa.world_live": soccer,
|
||||||
|
"soccer_usa.1_live": soccer,
|
||||||
|
"soccer_recent": soccer,
|
||||||
|
"clock": idle,
|
||||||
|
}
|
||||||
|
assert controller._collect_live_modes() == [
|
||||||
|
"baseball_live", "soccer_fifa.world_live"
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_round_robin_alternates_between_simultaneous_live_games(self, test_display_controller):
|
||||||
|
"""Regression: with two games live at once, the live-priority pick
|
||||||
|
round-robins each dwell instead of pinning to the first plugin in
|
||||||
|
registration order (the bug where a baseball game hid a live World Cup
|
||||||
|
match)."""
|
||||||
|
controller = test_display_controller
|
||||||
|
baseball = self._live_plugin(["baseball_live"])
|
||||||
|
soccer = self._live_plugin(["soccer_fifa.world_live"])
|
||||||
|
controller.plugin_modes = {
|
||||||
|
"baseball_live": baseball,
|
||||||
|
"soccer_fifa.world_live": soccer,
|
||||||
|
}
|
||||||
|
# First entry into live priority from an ambient mode -> first live game.
|
||||||
|
controller.current_display_mode = "clock"
|
||||||
|
assert controller._check_live_priority(advance=True) == "baseball_live"
|
||||||
|
# The controller switches to it; the next dwell advances to the other.
|
||||||
|
controller.current_display_mode = "baseball_live"
|
||||||
|
assert controller._check_live_priority(advance=True) == "soccer_fifa.world_live"
|
||||||
|
# And wraps back again.
|
||||||
|
controller.current_display_mode = "soccer_fifa.world_live"
|
||||||
|
assert controller._check_live_priority(advance=True) == "baseball_live"
|
||||||
|
|
||||||
|
def test_single_live_game_holds_without_flipping(self, test_display_controller):
|
||||||
|
"""One live game: advancing returns the same mode, so the hold is stable."""
|
||||||
|
controller = test_display_controller
|
||||||
|
controller.plugin_modes = {"baseball_live": self._live_plugin(["baseball_live"])}
|
||||||
|
controller.current_display_mode = "baseball_live"
|
||||||
|
assert controller._check_live_priority(advance=True) == "baseball_live"
|
||||||
|
|
||||||
|
def test_non_advancing_peek_does_not_rotate(self, test_display_controller):
|
||||||
|
"""The default (advance=False) peek used by the Vegas coordinator must
|
||||||
|
not spin the cursor: it returns the live mode already on screen."""
|
||||||
|
controller = test_display_controller
|
||||||
|
controller.plugin_modes = {
|
||||||
|
"baseball_live": self._live_plugin(["baseball_live"]),
|
||||||
|
"soccer_fifa.world_live": self._live_plugin(["soccer_fifa.world_live"]),
|
||||||
|
}
|
||||||
|
controller.current_display_mode = "soccer_fifa.world_live"
|
||||||
|
assert controller._check_live_priority() == "soccer_fifa.world_live"
|
||||||
|
assert controller._check_live_priority() == "soccer_fifa.world_live"
|
||||||
|
# From an ambient mode the peek reports the first live game (truthy).
|
||||||
|
controller.current_display_mode = "clock"
|
||||||
|
assert controller._check_live_priority() == "baseball_live"
|
||||||
|
|
||||||
|
def test_no_live_content_returns_none(self, test_display_controller):
|
||||||
|
controller = test_display_controller
|
||||||
|
idle = MagicMock()
|
||||||
|
idle.has_live_priority = MagicMock(return_value=True)
|
||||||
|
idle.has_live_content = MagicMock(return_value=False)
|
||||||
|
controller.plugin_modes = {"clock": idle}
|
||||||
|
controller.current_display_mode = "clock"
|
||||||
|
assert controller._check_live_priority(advance=True) is None
|
||||||
|
|
||||||
|
def test_fallback_to_mode_name_when_get_live_modes_unhelpful(self, test_display_controller):
|
||||||
|
"""A live plugin whose get_live_modes returns nothing registered falls
|
||||||
|
back to its own '_live' mode name (legacy behavior preserved)."""
|
||||||
|
controller = test_display_controller
|
||||||
|
legacy = MagicMock()
|
||||||
|
legacy.has_live_priority = MagicMock(return_value=True)
|
||||||
|
legacy.has_live_content = MagicMock(return_value=True)
|
||||||
|
legacy.get_live_modes = MagicMock(return_value=["unregistered_mode"])
|
||||||
|
controller.plugin_modes = {"hockey_live": legacy}
|
||||||
|
controller.current_display_mode = "clock"
|
||||||
|
assert controller._check_live_priority(advance=True) == "hockey_live"
|
||||||
|
|
||||||
|
|
||||||
class TestDisplayControllerDynamicDuration:
|
class TestDisplayControllerDynamicDuration:
|
||||||
"""Test dynamic duration handling."""
|
"""Test dynamic duration handling."""
|
||||||
|
|||||||
@@ -43,6 +43,115 @@ class TestUninstallTombstone(unittest.TestCase):
|
|||||||
self.assertNotIn("foo", self.sm._uninstall_tombstones)
|
self.assertNotIn("foo", self.sm._uninstall_tombstones)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPersistentUninstallRegistry(unittest.TestCase):
|
||||||
|
"""Regression tests for the persistent uninstall registry that stops a
|
||||||
|
core `git pull` update from resurrecting built-in plugins the user
|
||||||
|
removed (plugins committed under plugin-repos/)."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self._tmp = TemporaryDirectory()
|
||||||
|
self.addCleanup(self._tmp.cleanup)
|
||||||
|
self.plugins_dir = Path(self._tmp.name) / "plugin-repos"
|
||||||
|
self.plugins_dir.mkdir()
|
||||||
|
self.registry_path = Path(self._tmp.name) / "config" / "uninstalled_plugins.json"
|
||||||
|
self.sm = PluginStoreManager(
|
||||||
|
plugins_dir=str(self.plugins_dir),
|
||||||
|
uninstalled_registry_path=str(self.registry_path),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _make_plugin_dir(self, plugin_id):
|
||||||
|
"""Simulate a built-in plugin restored on disk (e.g. by git pull)."""
|
||||||
|
d = self.plugins_dir / plugin_id
|
||||||
|
d.mkdir(parents=True)
|
||||||
|
(d / "manifest.json").write_text('{"id": "%s"}' % plugin_id)
|
||||||
|
return d
|
||||||
|
|
||||||
|
def test_unrecorded_plugin_is_not_uninstalled(self):
|
||||||
|
self.assertFalse(self.sm.is_plugin_uninstalled("web-ui-info"))
|
||||||
|
self.assertEqual(self.sm.get_uninstalled_plugins(), set())
|
||||||
|
|
||||||
|
def test_record_persists_across_instances(self):
|
||||||
|
self.sm.record_uninstalled_plugin("web-ui-info")
|
||||||
|
self.assertTrue(self.registry_path.exists())
|
||||||
|
# A fresh manager (simulating a service restart after update) still sees it.
|
||||||
|
fresh = PluginStoreManager(
|
||||||
|
plugins_dir=str(self.plugins_dir),
|
||||||
|
uninstalled_registry_path=str(self.registry_path),
|
||||||
|
)
|
||||||
|
self.assertTrue(fresh.is_plugin_uninstalled("web-ui-info"))
|
||||||
|
|
||||||
|
def test_forget_clears_record(self):
|
||||||
|
self.sm.record_uninstalled_plugin("web-ui-info")
|
||||||
|
self.sm.forget_uninstalled_plugin("web-ui-info")
|
||||||
|
self.assertFalse(self.sm.is_plugin_uninstalled("web-ui-info"))
|
||||||
|
|
||||||
|
def test_purge_removes_resurrected_plugin(self):
|
||||||
|
# The bug: user removed web-ui-info, then a git pull restored its
|
||||||
|
# committed files. Recorded uninstall + purge must re-remove it.
|
||||||
|
self._make_plugin_dir("web-ui-info")
|
||||||
|
self.sm.record_uninstalled_plugin("web-ui-info")
|
||||||
|
self.assertTrue((self.plugins_dir / "web-ui-info").exists())
|
||||||
|
|
||||||
|
removed = self.sm.purge_uninstalled_plugins()
|
||||||
|
|
||||||
|
self.assertEqual(removed, ["web-ui-info"])
|
||||||
|
self.assertFalse((self.plugins_dir / "web-ui-info").exists())
|
||||||
|
# Record is kept so the purge stays idempotent across future updates.
|
||||||
|
self.assertTrue(self.sm.is_plugin_uninstalled("web-ui-info"))
|
||||||
|
|
||||||
|
def test_purge_leaves_non_uninstalled_plugins_alone(self):
|
||||||
|
self._make_plugin_dir("baseball-scoreboard") # present, not recorded
|
||||||
|
self._make_plugin_dir("web-ui-info")
|
||||||
|
self.sm.record_uninstalled_plugin("web-ui-info")
|
||||||
|
|
||||||
|
self.sm.purge_uninstalled_plugins()
|
||||||
|
|
||||||
|
self.assertTrue((self.plugins_dir / "baseball-scoreboard").exists())
|
||||||
|
self.assertFalse((self.plugins_dir / "web-ui-info").exists())
|
||||||
|
|
||||||
|
def test_purge_noop_when_plugin_absent(self):
|
||||||
|
# Recorded but never restored on disk — nothing to remove.
|
||||||
|
self.sm.record_uninstalled_plugin("web-ui-info")
|
||||||
|
self.assertEqual(self.sm.purge_uninstalled_plugins(), [])
|
||||||
|
|
||||||
|
def test_corrupt_registry_is_ignored(self):
|
||||||
|
self.registry_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
self.registry_path.write_text("{ not valid json")
|
||||||
|
self.assertEqual(self.sm.get_uninstalled_plugins(), set())
|
||||||
|
self.assertFalse(self.sm.is_plugin_uninstalled("web-ui-info"))
|
||||||
|
|
||||||
|
def _write_raw_registry(self, value):
|
||||||
|
self.registry_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
import json as _json
|
||||||
|
self.registry_path.write_text(_json.dumps(value))
|
||||||
|
|
||||||
|
def test_empty_id_does_not_wipe_plugins_root(self):
|
||||||
|
# An empty id resolves to plugins_dir itself; purge must never delete it.
|
||||||
|
self._make_plugin_dir("baseball-scoreboard")
|
||||||
|
self._write_raw_registry([""])
|
||||||
|
|
||||||
|
removed = self.sm.purge_uninstalled_plugins()
|
||||||
|
|
||||||
|
self.assertEqual(removed, [])
|
||||||
|
self.assertTrue(self.plugins_dir.exists())
|
||||||
|
self.assertTrue((self.plugins_dir / "baseball-scoreboard").exists())
|
||||||
|
# Invalid id is filtered out entirely.
|
||||||
|
self.assertEqual(self.sm.get_uninstalled_plugins(), set())
|
||||||
|
|
||||||
|
def test_traversal_ids_are_ignored(self):
|
||||||
|
for bad in ["..", "../evil", "a/b", "."]:
|
||||||
|
with self.subTest(bad=bad):
|
||||||
|
self.assertFalse(self.sm._is_valid_plugin_id(bad))
|
||||||
|
self._write_raw_registry(["../evil", "..", "web-ui-info"])
|
||||||
|
# Only the safe id survives the read.
|
||||||
|
self.assertEqual(self.sm.get_uninstalled_plugins(), {"web-ui-info"})
|
||||||
|
|
||||||
|
def test_record_rejects_invalid_id(self):
|
||||||
|
self.sm.record_uninstalled_plugin("")
|
||||||
|
self.sm.record_uninstalled_plugin("../escape")
|
||||||
|
self.assertEqual(self.sm.get_uninstalled_plugins(), set())
|
||||||
|
|
||||||
|
|
||||||
class TestGitInfoCache(unittest.TestCase):
|
class TestGitInfoCache(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self._tmp = TemporaryDirectory()
|
self._tmp = TemporaryDirectory()
|
||||||
|
|||||||
93
test/web_interface/test_dotted_league_keys.py
Normal file
93
test/web_interface/test_dotted_league_keys.py
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
"""
|
||||||
|
Regression test for saving plugin config fields whose schema keys contain dots
|
||||||
|
(e.g. soccer league keys like "fifa.world", "eng.1", "usa.1").
|
||||||
|
|
||||||
|
Bug: the web config form posts form-data with dotted paths such as
|
||||||
|
"leagues.fifa.world.enabled". The helpers that resolve those paths split on every
|
||||||
|
dot, so the dotted league key "fifa.world" was mistaken for nested "fifa" ->
|
||||||
|
"world" objects. Per-league edits (enable, favorite_teams, nested booleans) were
|
||||||
|
written to a fabricated "leagues.fifa.world" branch while the real league object
|
||||||
|
was never updated, so the save silently dropped the change and the saved config
|
||||||
|
came out byte-identical.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from web_interface.blueprints.api_v3 import (
|
||||||
|
_get_schema_property,
|
||||||
|
_set_nested_value,
|
||||||
|
_parse_form_value_with_schema,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
SCHEMA = {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"leagues": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"fifa.world": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"enabled": {"type": "boolean"},
|
||||||
|
"favorite_teams": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {"type": "string"},
|
||||||
|
},
|
||||||
|
"display_modes": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {"live": {"type": "boolean"}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestDottedLeagueKeys(unittest.TestCase):
|
||||||
|
def test_schema_lookup_resolves_dotted_league_key(self):
|
||||||
|
prop = _get_schema_property(SCHEMA, "leagues.fifa.world.favorite_teams")
|
||||||
|
self.assertIsNotNone(prop, "dotted league key path should resolve")
|
||||||
|
self.assertEqual(prop.get("type"), "array")
|
||||||
|
|
||||||
|
def test_schema_lookup_resolves_nested_object_beneath_dotted_key(self):
|
||||||
|
live = _get_schema_property(SCHEMA, "leagues.fifa.world.display_modes.live")
|
||||||
|
self.assertIsNotNone(live)
|
||||||
|
self.assertEqual(live.get("type"), "boolean")
|
||||||
|
|
||||||
|
def test_parse_typed_value_for_dotted_key(self):
|
||||||
|
# Comma-separated text input "USA" must become an array, not the raw string.
|
||||||
|
parsed = _parse_form_value_with_schema(
|
||||||
|
"USA", "leagues.fifa.world.favorite_teams", SCHEMA
|
||||||
|
)
|
||||||
|
self.assertEqual(parsed, ["USA"])
|
||||||
|
|
||||||
|
def test_set_value_updates_real_league_not_fabricated_branch(self):
|
||||||
|
config = {"leagues": {"fifa.world": {"enabled": False, "favorite_teams": []}}}
|
||||||
|
_set_nested_value(config, "leagues.fifa.world.enabled", True)
|
||||||
|
_set_nested_value(config, "leagues.fifa.world.favorite_teams", ["USA"])
|
||||||
|
|
||||||
|
self.assertTrue(config["leagues"]["fifa.world"]["enabled"])
|
||||||
|
self.assertEqual(config["leagues"]["fifa.world"]["favorite_teams"], ["USA"])
|
||||||
|
# The real league must be updated and no fabricated "fifa" branch created.
|
||||||
|
self.assertNotIn("fifa", config["leagues"])
|
||||||
|
|
||||||
|
def test_set_value_into_missing_leaf_lands_in_real_league(self):
|
||||||
|
# A leaf that does not exist yet still resolves into the real dotted league.
|
||||||
|
config = {"leagues": {"fifa.world": {"enabled": False}}}
|
||||||
|
_set_nested_value(config, "leagues.fifa.world.display_modes.live", True)
|
||||||
|
self.assertTrue(
|
||||||
|
config["leagues"]["fifa.world"]["display_modes"]["live"]
|
||||||
|
)
|
||||||
|
self.assertNotIn("fifa", config["leagues"])
|
||||||
|
|
||||||
|
def test_plain_nested_paths_still_work(self):
|
||||||
|
config = {}
|
||||||
|
_set_nested_value(config, "customization.text.font", "small")
|
||||||
|
self.assertEqual(config["customization"]["text"]["font"], "small")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -79,6 +79,21 @@ plugin_manager = PluginManager(
|
|||||||
cache_manager=None # Not needed for web interface
|
cache_manager=None # Not needed for web interface
|
||||||
)
|
)
|
||||||
plugin_store_manager = PluginStoreManager(plugins_dir=str(plugins_dir))
|
plugin_store_manager = PluginStoreManager(plugins_dir=str(plugins_dir))
|
||||||
|
# A core `git pull` update (or any checkout) restores built-in plugins
|
||||||
|
# committed under plugin-repos/, even ones the user uninstalled. Re-remove any
|
||||||
|
# the user previously uninstalled at startup so a manual update on the Pi
|
||||||
|
# doesn't resurrect them.
|
||||||
|
try:
|
||||||
|
_purged = plugin_store_manager.purge_uninstalled_plugins()
|
||||||
|
if _purged:
|
||||||
|
logging.getLogger(__name__).info(
|
||||||
|
"Re-removed %d uninstalled plugin(s) restored since last run: %s",
|
||||||
|
len(_purged), ", ".join(_purged),
|
||||||
|
)
|
||||||
|
except (OSError, RuntimeError) as _purge_err:
|
||||||
|
logging.getLogger(__name__).warning(
|
||||||
|
"Startup plugin purge failed: %s", _purge_err
|
||||||
|
)
|
||||||
saved_repositories_manager = SavedRepositoriesManager()
|
saved_repositories_manager = SavedRepositoriesManager()
|
||||||
|
|
||||||
# Initialize schema manager
|
# Initialize schema manager
|
||||||
|
|||||||
@@ -1559,6 +1559,20 @@ def execute_system_action():
|
|||||||
pull_message = f"Code updated successfully. Local changes were automatically stashed.{stash_info}"
|
pull_message = f"Code updated successfully. Local changes were automatically stashed.{stash_info}"
|
||||||
if result.stdout and "Already up to date" not in result.stdout:
|
if result.stdout and "Already up to date" not in result.stdout:
|
||||||
pull_message = f"Code updated successfully.{stash_info}"
|
pull_message = f"Code updated successfully.{stash_info}"
|
||||||
|
# A `git pull` restores built-in plugins (committed under
|
||||||
|
# plugin-repos/) even if the user uninstalled them. Re-remove
|
||||||
|
# any the user previously uninstalled so the update doesn't
|
||||||
|
# resurrect them.
|
||||||
|
if api_v3.plugin_store_manager:
|
||||||
|
try:
|
||||||
|
purged = api_v3.plugin_store_manager.purge_uninstalled_plugins()
|
||||||
|
if purged:
|
||||||
|
logger.info(
|
||||||
|
"Re-removed %d uninstalled plugin(s) restored by update: %s",
|
||||||
|
len(purged), ", ".join(purged),
|
||||||
|
)
|
||||||
|
except (OSError, RuntimeError) as purge_err:
|
||||||
|
logger.warning("Post-update plugin purge failed: %s", purge_err)
|
||||||
else:
|
else:
|
||||||
logger.warning("git pull failed (returncode=%d): %s", result.returncode, result.stderr)
|
logger.warning("git pull failed (returncode=%d): %s", result.returncode, result.stderr)
|
||||||
pull_message = "Update failed; check logs for details"
|
pull_message = "Update failed; check logs for details"
|
||||||
@@ -2933,6 +2947,13 @@ def _do_transactional_uninstall(plugin_id, preserve_config):
|
|||||||
api_v3.schema_manager.invalidate_cache(plugin_id)
|
api_v3.schema_manager.invalidate_cache(plugin_id)
|
||||||
if api_v3.plugin_state_manager:
|
if api_v3.plugin_state_manager:
|
||||||
api_v3.plugin_state_manager.remove_plugin_state(plugin_id)
|
api_v3.plugin_state_manager.remove_plugin_state(plugin_id)
|
||||||
|
# Persistently record the uninstall so a later core `git pull` update
|
||||||
|
# cannot resurrect a built-in plugin (committed under plugin-repos/) that
|
||||||
|
# the user removed. Best-effort: never fail the uninstall over this.
|
||||||
|
try:
|
||||||
|
api_v3.plugin_store_manager.record_uninstalled_plugin(plugin_id)
|
||||||
|
except Exception as record_err:
|
||||||
|
logger.warning("Could not record uninstall for %s: %s", plugin_id, record_err)
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
|
||||||
@@ -3537,21 +3558,29 @@ def _get_schema_property(schema, key_path):
|
|||||||
|
|
||||||
parts = key_path.split('.')
|
parts = key_path.split('.')
|
||||||
current = schema['properties']
|
current = schema['properties']
|
||||||
|
i = 0
|
||||||
|
|
||||||
for i, part in enumerate(parts):
|
while i < len(parts):
|
||||||
if part not in current:
|
# Try progressively longer candidates, longest first, so schema keys that
|
||||||
return None
|
# themselves contain dots (e.g. league keys like "fifa.world") are matched
|
||||||
|
# instead of being mistaken for nested "fifa" -> "world" objects.
|
||||||
prop = current[part]
|
matched = False
|
||||||
|
for j in range(len(parts), i, -1):
|
||||||
# If this is the last part, return the property
|
candidate = '.'.join(parts[i:j])
|
||||||
if i == len(parts) - 1:
|
if isinstance(current, dict) and candidate in current:
|
||||||
|
prop = current[candidate]
|
||||||
|
# Consumed all remaining parts — this is the target property.
|
||||||
|
if j == len(parts):
|
||||||
return prop
|
return prop
|
||||||
|
# Navigate deeper through an object with properties.
|
||||||
# If this is an object with properties, navigate deeper
|
|
||||||
if isinstance(prop, dict) and 'properties' in prop:
|
if isinstance(prop, dict) and 'properties' in prop:
|
||||||
current = prop['properties']
|
current = prop['properties']
|
||||||
else:
|
i = j
|
||||||
|
matched = True
|
||||||
|
break
|
||||||
|
# Matched a non-object before consuming the path — can't go deeper.
|
||||||
|
return None
|
||||||
|
if not matched:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@@ -3724,10 +3753,45 @@ def _parse_form_value_with_schema(value, key_path, schema):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_key_segments(key_path, config):
|
||||||
|
"""Split a dot-notation path into segments, greedily preserving keys that
|
||||||
|
themselves contain dots (e.g. league keys like "fifa.world").
|
||||||
|
|
||||||
|
At each level the longest candidate that matches a key already present in the
|
||||||
|
config wins; otherwise the path splits on the next dot (the normal
|
||||||
|
nested-create case). Because dotted keys such as ``leagues."fifa.world"``
|
||||||
|
always exist in the saved config being updated, this routes the value to the
|
||||||
|
real league object instead of fabricating a ``leagues.fifa.world`` tree.
|
||||||
|
"""
|
||||||
|
parts = key_path.split('.')
|
||||||
|
segments = []
|
||||||
|
node = config
|
||||||
|
i = 0
|
||||||
|
while i < len(parts):
|
||||||
|
matched = False
|
||||||
|
if isinstance(node, dict):
|
||||||
|
for j in range(len(parts), i, -1):
|
||||||
|
candidate = '.'.join(parts[i:j])
|
||||||
|
if candidate in node:
|
||||||
|
segments.append(candidate)
|
||||||
|
node = node[candidate]
|
||||||
|
i = j
|
||||||
|
matched = True
|
||||||
|
break
|
||||||
|
if not matched:
|
||||||
|
part = parts[i]
|
||||||
|
segments.append(part)
|
||||||
|
node = node.get(part) if isinstance(node, dict) else None
|
||||||
|
i += 1
|
||||||
|
return segments
|
||||||
|
|
||||||
|
|
||||||
def _set_nested_value(config, key_path, value):
|
def _set_nested_value(config, key_path, value):
|
||||||
"""
|
"""
|
||||||
Set a value in a nested dict using dot notation path.
|
Set a value in a nested dict using dot notation path.
|
||||||
Handles existing nested dicts correctly by merging instead of replacing.
|
Handles existing nested dicts correctly by merging instead of replacing.
|
||||||
|
Keys containing dots (e.g. league keys like "fifa.world") are preserved when
|
||||||
|
they already exist in the config rather than being split into nested objects.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
config: The config dict to modify
|
config: The config dict to modify
|
||||||
@@ -3738,21 +3802,21 @@ def _set_nested_value(config, key_path, value):
|
|||||||
if value is _SKIP_FIELD:
|
if value is _SKIP_FIELD:
|
||||||
return
|
return
|
||||||
|
|
||||||
parts = key_path.split('.')
|
segments = _resolve_key_segments(key_path, config)
|
||||||
current = config
|
current = config
|
||||||
|
|
||||||
# Navigate/create intermediate dicts
|
# Navigate/create intermediate dicts
|
||||||
for i, part in enumerate(parts[:-1]):
|
for seg in segments[:-1]:
|
||||||
if part not in current:
|
if seg not in current:
|
||||||
current[part] = {}
|
current[seg] = {}
|
||||||
elif not isinstance(current[part], dict):
|
elif not isinstance(current[seg], dict):
|
||||||
# If the existing value is not a dict, replace it with a dict
|
# If the existing value is not a dict, replace it with a dict
|
||||||
current[part] = {}
|
current[seg] = {}
|
||||||
current = current[part]
|
current = current[seg]
|
||||||
|
|
||||||
# Set the final value (don't overwrite with empty dict if value is None and we want to preserve structure)
|
# Set the final value (don't overwrite with empty dict if value is None and we want to preserve structure)
|
||||||
if value is not None or parts[-1] not in current:
|
if value is not None or segments[-1] not in current:
|
||||||
current[parts[-1]] = value
|
current[segments[-1]] = value
|
||||||
|
|
||||||
|
|
||||||
def _set_missing_booleans_to_false(config, schema_props, form_keys, prefix='', config_node=None):
|
def _set_missing_booleans_to_false(config, schema_props, form_keys, prefix='', config_node=None):
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
name="chain_length"
|
name="chain_length"
|
||||||
value="{{ main_config.display.hardware.chain_length or 2 }}"
|
value="{{ main_config.display.hardware.chain_length or 2 }}"
|
||||||
min="1"
|
min="1"
|
||||||
max="8"
|
max="24"
|
||||||
class="form-control">
|
class="form-control">
|
||||||
<p class="mt-1 text-sm text-gray-600">Number of LED panels chained together</p>
|
<p class="mt-1 text-sm text-gray-600">Number of LED panels chained together</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user