From 16af2875e05d7b59a7f7d24137950f7f673337fc Mon Sep 17 00:00:00 2001 From: Piclaw Date: Mon, 25 May 2026 15:20:48 -0700 Subject: [PATCH] Add Shell.run_raspi_config() that no-ops on non-Raspberry-Pi-OS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit raspi-config is only shipped (and only honored) on Raspberry Pi OS, so installer scripts that shell out to `raspi-config nonint ...` to toggle SPI/I2C, set overscan, change boot behaviour, etc. fail silently on DietPi, Ubuntu, and other Debian-based distros — the binary isn't there and the configuration tweak it stood for never happens. Add a small helper, Shell.run_raspi_config(args, ...), that: * Returns immediately (True, or "" when return_output=True) when is_raspberry_pi_os() is False, so callers that ignore the return value short-circuit cleanly and callers that .strip() the output still get a usable string. * On Raspberry Pi OS, forwards to run_command() with the same suppress_message / return_output / run_as_user kwargs. Also switch the existing Shell.set_window_manager() raspi-config call to use the new helper so it behaves the same way on non-Pi-OS hosts (previously it would have raised RuntimeError after failing to find the binary). The intent is for downstream installer scripts (adafruit-pitft.py, raspi-blinka.py, raspi-spi-reassign.py, joy-bonnet.py, retrogame.py, pitft-fbcp.py, ...) to switch from `shell.run_command("sudo raspi-config nonint ...")` to `shell.run_raspi_config(...)` and inherit the non-Pi-OS skip for free. --- adafruit_shell.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/adafruit_shell.py b/adafruit_shell.py index 9128938..65f4551 100644 --- a/adafruit_shell.py +++ b/adafruit_shell.py @@ -893,6 +893,30 @@ def check_kernel_userspace_mismatch(self, attempt_fix=True, fix_with_x11=False): else: raise RuntimeError("Unable to continue while mismatch is present.") + def run_raspi_config(self, args, suppress_message=False, return_output=False, run_as_user=None): + """ + Run a ``raspi-config nonint ...`` command, but only on Raspberry Pi OS. + + ``raspi-config`` is only shipped (and only honored) on Raspberry Pi OS; + on other distros (DietPi, Ubuntu, etc.) the binary is absent and the + tweak would not apply anyway. On non-Pi-OS systems this method is a + no-op that returns ``True`` (or ``""`` when ``return_output=True``) + so existing call sites continue to work without producing misleading + "command not found" output. + + ``args`` is the part after ``raspi-config nonint`` (e.g. ``"do_spi 0"``). + ``suppress_message``, ``return_output``, and ``run_as_user`` are + forwarded to :meth:`run_command`. + """ + if not self.is_raspberry_pi_os(): + return "" if return_output else True + return self.run_command( + "raspi-config nonint " + args, + suppress_message=suppress_message, + return_output=return_output, + run_as_user=run_as_user, + ) + def set_window_manager(self, manager): """ Call raspi-config to set a new window manager @@ -907,9 +931,7 @@ def set_window_manager(self, manager): raise RuntimeError("labwc is not installed") print(f"Using {manager} as the window manager") - if not self.run_command( - "sudo raspi-config nonint do_wayland " + WINDOW_MANAGERS[manager.lower()] - ): + if not self.run_raspi_config("do_wayland " + WINDOW_MANAGERS[manager.lower()]): raise RuntimeError("Unable to change window manager") def get_window_manager(self):