installer: add --local (on-printer) mode; fix G29 hijack on commented stock macro - #3
Draft
sammcj wants to merge 2 commits into
Draft
installer: add --local (on-printer) mode; fix G29 hijack on commented stock macro#3sammcj wants to merge 2 commits into
sammcj wants to merge 2 commits into
Conversation
… stock macro install.sh can't run on the printer itself - its buildroot Python has no working pip/venv (ensurepip fails), so re-applying KAMP after a Creality firmware update meant reaching for a PC. Add a --local mode that runs the installer directly on the printer with no SSH/paramiko/venv: - paramiko is imported lazily inside connect() (guarded by TYPE_CHECKING for hints); run/read_remote/write_remote gained local branches (subprocess + direct file I/O). copy_file and every patch step route through these, so the whole flow works unchanged locally. --host is required only without --local. Also fix an AttributeError in the G29 hijack: the old re.search(r'^\[gcode_macro G29\]...').group(0) crashed when the stock [gcode_macro G29] is commented out (as on the K2 Pro). New idempotent _hijack_macro() helper handles hijacked/active/commented/absent states, matches the header whitespace-tolerantly (so it can never emit a duplicate active section), and inserts the template literally (backslash-safe). Note: an absent BED_MESH_CALIBRATE_START_PRINT is now appended a no-op hijack (previously left alone); harmless and consistent with intent. Docs: README + INSTALL_K2 describe the --local re-apply-after-update flow. Tested end-to-end on a K2 Pro (Python 3.9.12, no paramiko): --local --dry-run completes all steps and is idempotent on an already-installed printer.
Author
|
Thought I'd raise this as a DRAFT for comments first @grant0013, I created this off the back of having several Python issues after applying the most recent two K2 Pro firmware updates. Thoughts? |
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.
What
Two installer changes so KAMP-K2 can be re-applied on the printer after a Creality firmware update:
--localmode - runinstall_k2.pydirectly on the printer, no SSH/paramiko/venv.G29hijack crash when the stock[gcode_macro G29]ships commented out (K2 Pro).Why
printer.cfg/gcode_macro.cfg, so KAMP has to be re-applied after each one.install.shcan't run on the printer - its buildroot Python fails atensurepip, so there was no clean on-printer path.G29ships commented (# [gcode_macro G29]). The old hijack ranre.search(r"^\[gcode_macro G29\]...").group(0)on it;re.searchreturnedNone→AttributeError, aborting the install.Changes
connect()(remote--hostpath only, guarded byTYPE_CHECKINGfor hints).run/read_remote/write_remotegained a local branch;copy_fileand every patch step route through them, so the whole flow works unchanged locally.--hostis required only when--localis absent._hijack_macro()forG29+BED_MESH_CALIBRATE_START_PRINT: handles hijacked / active / commented / absent, matches the header whitespace-tolerantly (so it can never emit a duplicate active section that stops Klipper booting), and inserts the template literally (backslash-safe).README.md+docs/INSTALL_K2.mddocument the--localre-apply-after-update flow.Testing
python3 install_k2.py --local --dry-runcompletes every step and is idempotent on an already-installed printer._hijack_macrochecked against a real stock K2 Progcode_macro.cfg(commentedG29+ inertBED_MESH_CALIBRATE_START_PRINT): exactly one active section per macro, re-run is a no-op, and tab / double-space headers don't duplicate.--host(SSH) path behaviourally unchanged.Notes
BED_MESH_CALIBRATE_START_PRINTis now appended a no-op hijack (previously left alone) - harmless and consistent with the hijack's intent.