Add Shell.append_if_missing() helper#39
Merged
makermelissa merged 1 commit intoJun 16, 2026
Merged
Conversation
Adds the common grep-or-append idiom (grep -qxF line file || echo line >> file) as a reusable method, complementing reconfig(). The installer scripts repeat this pattern constantly for /etc/modules, blacklist, and config.txt entries. Uses re.escape so lines with regex metacharacters match literally.
makermelissa
approved these changes
Jun 16, 2026
makermelissa
left a comment
Collaborator
There was a problem hiding this comment.
This is similar to reconfig, but it won't update an existing string.
makermelissa-piclaw
added a commit
to makermelissa-piclaw/Raspberry-Pi-Installer-Scripts
that referenced
this pull request
Jun 16, 2026
Drop the local append_if_missing helper now that it's available in the shared library (adafruit/Adafruit_Python_Shell#39).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Shell.append_if_missing(file, line)— the common "add a line only if it isn't already there" idiom that the installer scripts repeat constantly for/etc/modules, modprobe blacklists, andconfig.txtentries.It's the Python equivalent of:
Complements the existing
reconfig()(which is uncomment-or-append for a regex pattern).append_if_missingis for the simpler exact-line case where you just want to guarantee a literal line is present without disturbing anything else.Uses
re.escapeso lines containing regex metacharacters (e.g.dtoverlay=i2s-mmap) are matched literally rather than as patterns.Context
Suggested by @makermelissa on adafruit/Raspberry-Pi-Installer-Scripts#398, where several converted installers each define a private copy of this helper. Landing it here lets those scripts share one implementation.
Testing
ruff format+ruff check+reuse lint(pre-commit) all pass.