feat: brother printer checker

This commit is contained in:
Krzysztof kuhy Rudnicki 2026-02-06 21:00:40 +01:00
parent 16e5a47321
commit 449a01420a
4 changed files with 66 additions and 7 deletions

View File

@ -45,6 +45,15 @@ BROWSER_PATTERNS = frozenset([
"opera",
"microsoft-edge",
"ungoogled-chromium",
"thorium",
])
# Electron apps that should NOT be treated as browsers
# These use Chromium under the hood but are not web browsers
ELECTRON_IGNORE = frozenset([
"electron",
"code", # VS Code
"chrome_crashpad", # Crashpad handler used by all Electron apps
])
# Patterns to ignore (browser helpers that aren't the main browser)
@ -52,6 +61,7 @@ IGNORE_PATTERNS = frozenset([
"crashhandler",
"update",
"helper",
"crashpad",
])
@ -115,13 +125,14 @@ def is_steam_running(processes: Set[str]) -> bool:
def is_browser_running(processes: Set[str]) -> bool:
"""Check if any browser is running."""
for proc in processes:
# Skip ignored patterns
# Skip Electron apps and ignored patterns
if proc in ELECTRON_IGNORE:
continue
if any(ign in proc for ign in IGNORE_PATTERNS):
continue
# Check browser patterns
for pattern in BROWSER_PATTERNS:
if pattern in proc:
return True
# Use exact match to avoid false positives from Electron apps
if proc in BROWSER_PATTERNS:
return True
return False

View File

@ -57,4 +57,3 @@ youtube
google-chrome
chromium
ungoogled-chromium
thorium

View File

@ -1,4 +1,5 @@
# Exact package names that should bypass the block even if matching a keyword.
thorium-browser-bin
minizip
miniupnpc
haskell-generically

View File

@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Check Brother laser printer consumable/maintenance status.
# Thin wrapper that ensures dependencies are present, then runs the
# Python implementation in ~/testsAndMisc/python_pkg/brother_printer.
#
# Usage:
# ./check_brother_printer.sh # auto-detect USB or network
# ./check_brother_printer.sh <printer_ip> # force network/SNMP mode
set -euo pipefail
PYTHON_PKG_DIR="${HOME}/testsAndMisc/python_pkg"
BROTHER_MODULE="brother_printer"
# ── Ensure dependencies ─────────────────────────────────────────────
check_dependency() {
local cmd="$1" pkg="$2"
if ! command -v "$cmd" &>/dev/null; then
echo "Installing $pkg..."
sudo pacman -S --noconfirm --needed "$pkg"
fi
}
check_dependency python3 python
check_dependency lsusb usbutils
# net-snmp is optional (only needed for network mode)
if [[ -n "${1:-}" ]] && ! command -v snmpwalk &>/dev/null; then
echo "Installing net-snmp (needed for network mode)..."
sudo pacman -S --noconfirm --needed net-snmp
fi
# ── Verify the Python module exists ──────────────────────────────────
if [[ ! -f "${PYTHON_PKG_DIR}/${BROTHER_MODULE}/check_brother_printer.py" ]]; then
echo "Error: Python module not found at ${PYTHON_PKG_DIR}/${BROTHER_MODULE}/" >&2
exit 1
fi
# ── Run (with sudo for USB access) ──────────────────────────────────
if [[ $EUID -ne 0 ]]; then
exec sudo bash -c "cd '$PYTHON_PKG_DIR' && python3 -m '$BROTHER_MODULE' $*"
fi
cd "$PYTHON_PKG_DIR"
exec python3 -m "$BROTHER_MODULE" "$@"