testsAndMisc/python_pkg/brother_printer/run.sh
Krzysztof kuhy Rudnicki c4d5631054
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
fix(brother_printer): truthful probe note, pyusb auto-install, stuck-job detection
The CUPS-fallback note blamed a missing pyusb when the probe was really
skipped because CUPS owned the printer. It now names the real reason.
run.sh installs python-pyusb for the system python3 that sudo runs.

A paper misfeed blocks the usb:// backend while CUPS keeps saying
"processing", and cancel leaves that backend hung so the queue never
recovers. The report now flags a job whose page counter is frozen for
15 s, and a backend of a cancelled job, with a y/N offer to SIGKILL it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaBRWtXXWCs3K3yPHSruUC
2026-10-12 16:23:48 +02:00

34 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Depends on pyusb (USB port-status probe when CUPS owns the printer) and runs
# as root for USB hardware queries and CUPS management.
#
# Imports are absolute (python_pkg.brother_printer.*), so the monorepo root must
# be importable. sudo's env_reset drops an exported PYTHONPATH, hence passing it
# as a sudo VAR=value argument instead.
#
# Usage: ./run.sh # auto-detect
# ./run.sh <printer_ip> # network/SNMP mode
# The tool runs under the system python3 (sudo secure_path), so pyusb must come
# from the distro package, not a venv.
ensure_pyusb() {
/usr/bin/python3 -c 'import usb.core' 2>/dev/null && return 0
if ! command -v pacman >/dev/null; then
echo "pyusb missing and pacman not found; install python-pyusb for system python3." >&2
exit 1
fi
echo "Installing python-pyusb..."
sudo pacman -S --needed --noconfirm python-pyusb
}
ensure_pyusb
if [[ $EUID -ne 0 ]]; then
exec sudo PYTHONPATH="$REPO_ROOT" python3 -m python_pkg.brother_printer "$@"
fi
exec env PYTHONPATH="$REPO_ROOT" python3 -m python_pkg.brother_printer "$@"