From 9e0d7f218190511bed9b02e1b4440dbdce3d61c1 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 13:45:05 -0400 Subject: [PATCH 01/81] printcfg v3.9.0 DEV This release will move SET_MATERIAL and SET_NOZZLE to user_config This will allow them to be customized by the user They have also been added to SET_DEFAULTS, allowing them to be executed as part of the START_PRINT process. --- README.md | 2 +- moonraker-printcfg.conf | 2 +- print_debug.cfg | 2 +- print_extras.cfg | 2 +- print_macros.cfg | 81 +------------------------- profiles/README.md | 2 +- profiles/default/config.cfg | 90 ++++++++++++++++++++++++++++- profiles/default/variables.cfg | 4 +- profiles/hephaestus/config.cfg | 90 ++++++++++++++++++++++++++++- profiles/hephaestus/patch_notes.txt | 6 ++ profiles/hephaestus/variables.cfg | 4 +- scripts/install.sh | 2 +- scripts/setup.sh | 2 +- 13 files changed, 198 insertions(+), 91 deletions(-) diff --git a/README.md b/README.md index 9d11f59..ebd8814 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ diff --git a/moonraker-printcfg.conf b/moonraker-printcfg.conf index 8532857..0ca19ae 100644 --- a/moonraker-printcfg.conf +++ b/moonraker-printcfg.conf @@ -1,6 +1,6 @@ ##################################### ## Printcfg Moonraker ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### ## Manage updates for Rootiest printcfg Suite for Klipper diff --git a/print_debug.cfg b/print_debug.cfg index bbd4527..24ac385 100644 --- a/print_debug.cfg +++ b/print_debug.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Debugging ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### ## This file contains optional macros diff --git a/print_extras.cfg b/print_extras.cfg index 518b85e..9ca5c6d 100644 --- a/print_extras.cfg +++ b/print_extras.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Extras ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### ## This file contains optional config diff --git a/print_macros.cfg b/print_macros.cfg index 0df3f7e..1290b32 100644 --- a/print_macros.cfg +++ b/print_macros.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Macros ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### ################################ @@ -622,6 +622,8 @@ gcode: {% if printcfg.end_speed_factor == True %} ; if end speed factor is enabled, reset it M220 S{printcfg.default_speed_factor} ; reset speed factor {% endif %} + SET_NOZZLE ; set nozzle-specific settings + SET_MATERIAL ; set material-specific settings {% endif %} @@ -1415,83 +1417,6 @@ gcode: {% endif %} {% endif %} -################################ -######### SET_CONFIGS ########## -################################ -## SET_MATERIAL -## Set Material-specific Configs -## -## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: -## SET_MATERIAL MATERIAL='{filament_type[initial_extruder]}' -## -## Add this immediately after your start_print line of the start gcode in Cura: -## SET_MATERIAL MATERIAL='{material_type}' -## -[gcode_macro SET_MATERIAL] -description: Set values based on material type -variable_material: '' -gcode: - {% set MATERIAL = params.MATERIAL|default('ABS')|string %} ; Get material type from slicer - SET_GCODE_VARIABLE MACRO=SET_MATERIAL VARIABLE=material VALUE='"{MATERIAL}"' ; Save the material type to a variable - {% if MATERIAL == 'PLA' %} ; If material type is PLA - #BED_MESH_PROFILE LOAD="pla_mesh" ; Load bed mesh - #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings - #SET_GCODE_OFFSET Z=0 ; Set z_offset - #SET_VELOCITY_LIMIT VELOCITY=100 ACCEL=2000 ; Set max speed/acceleration - #SET_INPUT_SHAPER SHAPER_FREQ_X=58.6 SHAPER_FREQ_Y=34.2 SHAPER_TYPE_X=mzv SHAPER_TYPE_Y=mzv ; Set input_shaper - {% elif MATERIAL == 'ABS' %} ; If material type is ABS - #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh - #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings - #SET_GCODE_OFFSET Z=0 ; Set z_offset - {% elif MATERIAL == 'ABS+' %} ; If material type is ABS - #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh - #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings - #SET_GCODE_OFFSET Z=0 ; Set z_offset - {% elif MATERIAL == 'PLA+' %} ; If material type is ABS - #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh - #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings - #SET_GCODE_OFFSET Z=0 ; Set z_offset - {% elif MATERIAL == 'PETG' %} ; If material type is ABS - #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh - #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings - #SET_GCODE_OFFSET Z=0 ; Set z_offset - {% elif MATERIAL == 'TPU' %} ; If material type is ABS - #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh - #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings - #SET_GCODE_OFFSET Z=0 ; Set z_offset - {% elif MATERIAL == 'PC' %} ; If material type is ABS - #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh - #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings - #SET_GCODE_OFFSET Z=0 ; Set z_offset - {%else %} ; If any other material type - #BED_MESH_PROFILE LOAD="default" ; Load bed mesh - #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings - #SET_GCODE_OFFSET Z=0 ; Set z_offset - {% endif %} - -## SET_NOZZLE -## Set nozzle-specific Configs -## -## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: -## SET_NOZZLE NOZZLE='{nozzle_diameter[initial_extruder]}' -## -## Add this immediately after your start_print line of the start gcode in Cura: -## SET_NOZZLE NOZZLE='{machine_nozzle_size}' -## -[gcode_macro SET_NOZZLE] -description: Set values based on nozzle diameter -variable_nozzle: 0 -gcode: - {% set NOZZLE = params.NOZZLE|default(0.4)|float %} ; Get nozzle diameter from slicer - SET_GCODE_VARIABLE MACRO=SET_NOZZLE VARIABLE=nozzle VALUE={NOZZLE} ; Save the nozzle diameter to a variable - {% if NOZZLE == 0.4 %} ; If nozzle diameter is 0.4 - SET_PRESSURE_ADVANCE ADVANCE=0.040 SMOOTH_TIME=0.040 ; Set pressure_advance settings - {% elif NOZZLE == 0.6 %} ; If nozzle diameter is 0.6 - SET_PRESSURE_ADVANCE ADVANCE=0.010 SMOOTH_TIME=0.040 ; Set pressure_advance settings - {%else %} ; If any other nozzle diameter - #SET_GCODE_OFFSET Z=0 ; Set z_offset - {% endif %} - ################################ ######## AUDIO ALERTS ########## diff --git a/profiles/README.md b/profiles/README.md index d5a69e0..7b0253a 100644 --- a/profiles/README.md +++ b/profiles/README.md @@ -20,7 +20,7 @@ # Preset Profiles diff --git a/profiles/default/config.cfg b/profiles/default/config.cfg index 2f1c2cd..4a4f95d 100644 --- a/profiles/default/config.cfg +++ b/profiles/default/config.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Configuration ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### ##################################### ## Default Profile ## @@ -171,3 +171,91 @@ gcode: SET_PIN PIN=_beeper VALUE={L} CYCLE_TIME={F} ;Play tone G4 P{P} ;tone duration SET_PIN PIN=_beeper VALUE=0 + +################################ +######### SET_CONFIGS ########## +################################ +## SET_MATERIAL +## Set Material-specific Configs +## +## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: +## SET_MATERIAL MATERIAL='{filament_type[initial_extruder]}' +## +## Add this immediately after your start_print line of the start gcode in Cura: +## SET_MATERIAL MATERIAL='{material_type}' +## +[gcode_macro SET_MATERIAL] +description: Set values based on material type +variable_material: '' +gcode: + {% set MATERIAL = params.MATERIAL|default('ABS')|string %} ; Get material type from slicer + SET_GCODE_VARIABLE MACRO=SET_MATERIAL VARIABLE=material VALUE='"{MATERIAL}"' ; Save the material type to a variable + {% if MATERIAL == 'PLA' %} ; If material type is PLA + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="pla_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + #SET_VELOCITY_LIMIT VELOCITY=100 ACCEL=2000 ; Set max speed/acceleration + #SET_INPUT_SHAPER SHAPER_FREQ_X=58.6 SHAPER_FREQ_Y=34.2 SHAPER_TYPE_X=mzv SHAPER_TYPE_Y=mzv ; Set input_shaper + {% elif MATERIAL == 'ABS' %} ; If material type is ABS + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'ASA' %} ; If material type is ASA + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="asa_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'ABS+' %} ; If material type is ABS+ + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="abs_plus_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PLA+' %} ; If material type is PLA+ + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="pla_plus_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PETG' %} ; If material type is PETG + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="petg_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'TPU' %} ; If material type is TPU + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="tpu_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PC' %} ; If material type is PC + #BED_MESH_PROFILE LOAD="pc_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {%else %} ; If any other material type + #BED_MESH_PROFILE LOAD="default" ; Load default bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% endif %} + +## SET_NOZZLE +## Set nozzle-specific Configs +## +## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: +## SET_NOZZLE NOZZLE='{nozzle_diameter[initial_extruder]}' +## +## Add this immediately after your start_print line of the start gcode in Cura: +## SET_NOZZLE NOZZLE='{machine_nozzle_size}' +## +[gcode_macro SET_NOZZLE] +description: Set values based on nozzle diameter +variable_nozzle: 0 +gcode: + {% set NOZZLE = params.NOZZLE|default(0.4)|float %} ; Get nozzle diameter from slicer + SET_GCODE_VARIABLE MACRO=SET_NOZZLE VARIABLE=nozzle VALUE={NOZZLE} ; Save the nozzle diameter to a variable + {% if NOZZLE == 0.4 %} ; If nozzle diameter is 0.4 + #SET_PRESSURE_ADVANCE ADVANCE=0.040 SMOOTH_TIME=0.040 ; Set pressure_advance settings + {% elif NOZZLE == 0.6 %} ; If nozzle diameter is 0.6 + #SET_PRESSURE_ADVANCE ADVANCE=0.010 SMOOTH_TIME=0.040 ; Set pressure_advance settings + {%else %} ; If any other nozzle diameter + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% endif %} diff --git a/profiles/default/variables.cfg b/profiles/default/variables.cfg index 784d379..2dc8331 100644 --- a/profiles/default/variables.cfg +++ b/profiles/default/variables.cfg @@ -17,7 +17,7 @@ ##################################### ## User Profile ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### ##################################### ## Default Profile ## @@ -36,7 +36,7 @@ ## printcfg Configuration Variables ## Variables file version -variable_version: '3.8.0' +variable_version: '3.9.0' ## Default temperatures variable_extruder_temp: 200 diff --git a/profiles/hephaestus/config.cfg b/profiles/hephaestus/config.cfg index 0aeb3cb..43d20c2 100644 --- a/profiles/hephaestus/config.cfg +++ b/profiles/hephaestus/config.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Configuration ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### ##################################### ## Hephaestus Profile ## @@ -171,3 +171,91 @@ gcode: SET_PIN PIN=_beeper VALUE={L} CYCLE_TIME={F} ;Play tone G4 P{P} ;tone duration SET_PIN PIN=_beeper VALUE=0 + +################################ +######### SET_CONFIGS ########## +################################ +## SET_MATERIAL +## Set Material-specific Configs +## +## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: +## SET_MATERIAL MATERIAL='{filament_type[initial_extruder]}' +## +## Add this immediately after your start_print line of the start gcode in Cura: +## SET_MATERIAL MATERIAL='{material_type}' +## +[gcode_macro SET_MATERIAL] +description: Set values based on material type +variable_material: '' +gcode: + {% set MATERIAL = params.MATERIAL|default('ABS')|string %} ; Get material type from slicer + SET_GCODE_VARIABLE MACRO=SET_MATERIAL VARIABLE=material VALUE='"{MATERIAL}"' ; Save the material type to a variable + {% if MATERIAL == 'PLA' %} ; If material type is PLA + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="pla_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + #SET_VELOCITY_LIMIT VELOCITY=100 ACCEL=2000 ; Set max speed/acceleration + #SET_INPUT_SHAPER SHAPER_FREQ_X=58.6 SHAPER_FREQ_Y=34.2 SHAPER_TYPE_X=mzv SHAPER_TYPE_Y=mzv ; Set input_shaper + {% elif MATERIAL == 'ABS' %} ; If material type is ABS + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'ASA' %} ; If material type is ASA + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="asa_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'ABS+' %} ; If material type is ABS+ + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="abs_plus_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PLA+' %} ; If material type is PLA+ + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="pla_plus_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PETG' %} ; If material type is PETG + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="petg_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'TPU' %} ; If material type is TPU + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="tpu_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PC' %} ; If material type is PC + #BED_MESH_PROFILE LOAD="pc_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {%else %} ; If any other material type + #BED_MESH_PROFILE LOAD="default" ; Load default bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% endif %} + +## SET_NOZZLE +## Set nozzle-specific Configs +## +## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: +## SET_NOZZLE NOZZLE='{nozzle_diameter[initial_extruder]}' +## +## Add this immediately after your start_print line of the start gcode in Cura: +## SET_NOZZLE NOZZLE='{machine_nozzle_size}' +## +[gcode_macro SET_NOZZLE] +description: Set values based on nozzle diameter +variable_nozzle: 0 +gcode: + {% set NOZZLE = params.NOZZLE|default(0.4)|float %} ; Get nozzle diameter from slicer + SET_GCODE_VARIABLE MACRO=SET_NOZZLE VARIABLE=nozzle VALUE={NOZZLE} ; Save the nozzle diameter to a variable + {% if NOZZLE == 0.4 %} ; If nozzle diameter is 0.4 + #SET_PRESSURE_ADVANCE ADVANCE=0.040 SMOOTH_TIME=0.040 ; Set pressure_advance settings + {% elif NOZZLE == 0.6 %} ; If nozzle diameter is 0.6 + #SET_PRESSURE_ADVANCE ADVANCE=0.010 SMOOTH_TIME=0.040 ; Set pressure_advance settings + {%else %} ; If any other nozzle diameter + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% endif %} diff --git a/profiles/hephaestus/patch_notes.txt b/profiles/hephaestus/patch_notes.txt index 35ff736..63c5bb4 100644 --- a/profiles/hephaestus/patch_notes.txt +++ b/profiles/hephaestus/patch_notes.txt @@ -2,3 +2,9 @@ - Moved z_hopped variable as it's only used by the backend. (non-critical) Remove: variable_z_hopped +3.9.0: + - Moved SET_MATERIAL and SET_NOZZLE to user_config.cfg + Add: + USER_CONFIG: + SET_MATERIAL + SET_NOZZLE diff --git a/profiles/hephaestus/variables.cfg b/profiles/hephaestus/variables.cfg index 6c66c41..deaf137 100644 --- a/profiles/hephaestus/variables.cfg +++ b/profiles/hephaestus/variables.cfg @@ -17,7 +17,7 @@ ##################################### ## User Profile ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### ##################################### ## Hephaestus Profile ## @@ -36,7 +36,7 @@ ## printcfg Configuration Variables ## Variables file version -variable_version: '3.8.0' +variable_version: '3.9.0' ## Default temperatures variable_extruder_temp: 240 diff --git a/scripts/install.sh b/scripts/install.sh index b8e5085..7b14bc7 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -18,7 +18,7 @@ ##################################### ## Printcfg Install Script ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### # This script will download and install the printcfg package from GitHub. diff --git a/scripts/setup.sh b/scripts/setup.sh index 3f8d014..e6eb007 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -18,7 +18,7 @@ ##################################### ## Printcfg Setup Script ## -## Version 3.8.1 2023-5-21 ## +## Version 3.9.0 2023-5-22 ## ##################################### # This script will check the user profile and update it if necessary. From b319aaafa8720aaec95849d77bcc46004a86fd38 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:00:22 -0400 Subject: [PATCH 02/81] patching feature test --- profiles/default/config.cfg | 2 + profiles/default/patches/3.9.0/config.patch | 88 +++++ profiles/default/patches/3.9.0/vars.patch | 0 profiles/default/variables.cfg | 2 + profiles/hephaestus/config.cfg | 2 + .../hephaestus/patches/3.9.0/config.patch | 88 +++++ profiles/hephaestus/patches/3.9.0/vars.patch | 0 profiles/hephaestus/variables.cfg | 2 + scripts/install.sh | 2 +- scripts/patch.sh | 318 ++++++++++++++++++ 10 files changed, 503 insertions(+), 1 deletion(-) create mode 100644 profiles/default/patches/3.9.0/config.patch create mode 100644 profiles/default/patches/3.9.0/vars.patch create mode 100644 profiles/hephaestus/patches/3.9.0/config.patch create mode 100644 profiles/hephaestus/patches/3.9.0/vars.patch create mode 100644 scripts/patch.sh diff --git a/profiles/default/config.cfg b/profiles/default/config.cfg index 4a4f95d..3b04541 100644 --- a/profiles/default/config.cfg +++ b/profiles/default/config.cfg @@ -19,6 +19,8 @@ ## Print Configuration ## ## Version 3.9.0 2023-5-22 ## ##################################### +# Profile:default +# Patch:3.9.0 ##################################### ## Default Profile ## ##################################### diff --git a/profiles/default/patches/3.9.0/config.patch b/profiles/default/patches/3.9.0/config.patch new file mode 100644 index 0000000..4287600 --- /dev/null +++ b/profiles/default/patches/3.9.0/config.patch @@ -0,0 +1,88 @@ + +################################ +######### SET_CONFIGS ########## +################################ +## SET_MATERIAL +## Set Material-specific Configs +## +## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: +## SET_MATERIAL MATERIAL='{filament_type[initial_extruder]}' +## +## Add this immediately after your start_print line of the start gcode in Cura: +## SET_MATERIAL MATERIAL='{material_type}' +## +[gcode_macro SET_MATERIAL] +description: Set values based on material type +variable_material: '' +gcode: + {% set MATERIAL = params.MATERIAL|default('ABS')|string %} ; Get material type from slicer + SET_GCODE_VARIABLE MACRO=SET_MATERIAL VARIABLE=material VALUE='"{MATERIAL}"' ; Save the material type to a variable + {% if MATERIAL == 'PLA' %} ; If material type is PLA + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="pla_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + #SET_VELOCITY_LIMIT VELOCITY=100 ACCEL=2000 ; Set max speed/acceleration + #SET_INPUT_SHAPER SHAPER_FREQ_X=58.6 SHAPER_FREQ_Y=34.2 SHAPER_TYPE_X=mzv SHAPER_TYPE_Y=mzv ; Set input_shaper + {% elif MATERIAL == 'ABS' %} ; If material type is ABS + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'ASA' %} ; If material type is ASA + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="asa_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'ABS+' %} ; If material type is ABS+ + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="abs_plus_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PLA+' %} ; If material type is PLA+ + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="pla_plus_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PETG' %} ; If material type is PETG + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="petg_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'TPU' %} ; If material type is TPU + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="tpu_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PC' %} ; If material type is PC + #BED_MESH_PROFILE LOAD="pc_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {%else %} ; If any other material type + #BED_MESH_PROFILE LOAD="default" ; Load default bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% endif %} + +## SET_NOZZLE +## Set nozzle-specific Configs +## +## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: +## SET_NOZZLE NOZZLE='{nozzle_diameter[initial_extruder]}' +## +## Add this immediately after your start_print line of the start gcode in Cura: +## SET_NOZZLE NOZZLE='{machine_nozzle_size}' +## +[gcode_macro SET_NOZZLE] +description: Set values based on nozzle diameter +variable_nozzle: 0 +gcode: + {% set NOZZLE = params.NOZZLE|default(0.4)|float %} ; Get nozzle diameter from slicer + SET_GCODE_VARIABLE MACRO=SET_NOZZLE VARIABLE=nozzle VALUE={NOZZLE} ; Save the nozzle diameter to a variable + {% if NOZZLE == 0.4 %} ; If nozzle diameter is 0.4 + #SET_PRESSURE_ADVANCE ADVANCE=0.040 SMOOTH_TIME=0.040 ; Set pressure_advance settings + {% elif NOZZLE == 0.6 %} ; If nozzle diameter is 0.6 + #SET_PRESSURE_ADVANCE ADVANCE=0.010 SMOOTH_TIME=0.040 ; Set pressure_advance settings + {%else %} ; If any other nozzle diameter + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% endif %} diff --git a/profiles/default/patches/3.9.0/vars.patch b/profiles/default/patches/3.9.0/vars.patch new file mode 100644 index 0000000..e69de29 diff --git a/profiles/default/variables.cfg b/profiles/default/variables.cfg index 2dc8331..19de450 100644 --- a/profiles/default/variables.cfg +++ b/profiles/default/variables.cfg @@ -19,6 +19,8 @@ ## User Profile ## ## Version 3.9.0 2023-5-22 ## ##################################### +# Profile:default +# Patch:3.9.0 ##################################### ## Default Profile ## ##################################### diff --git a/profiles/hephaestus/config.cfg b/profiles/hephaestus/config.cfg index 43d20c2..3bf7c9c 100644 --- a/profiles/hephaestus/config.cfg +++ b/profiles/hephaestus/config.cfg @@ -19,6 +19,8 @@ ## Print Configuration ## ## Version 3.9.0 2023-5-22 ## ##################################### +# Profile:hephaestus +# Patch:3.9.0 ##################################### ## Hephaestus Profile ## ##################################### diff --git a/profiles/hephaestus/patches/3.9.0/config.patch b/profiles/hephaestus/patches/3.9.0/config.patch new file mode 100644 index 0000000..4287600 --- /dev/null +++ b/profiles/hephaestus/patches/3.9.0/config.patch @@ -0,0 +1,88 @@ + +################################ +######### SET_CONFIGS ########## +################################ +## SET_MATERIAL +## Set Material-specific Configs +## +## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: +## SET_MATERIAL MATERIAL='{filament_type[initial_extruder]}' +## +## Add this immediately after your start_print line of the start gcode in Cura: +## SET_MATERIAL MATERIAL='{material_type}' +## +[gcode_macro SET_MATERIAL] +description: Set values based on material type +variable_material: '' +gcode: + {% set MATERIAL = params.MATERIAL|default('ABS')|string %} ; Get material type from slicer + SET_GCODE_VARIABLE MACRO=SET_MATERIAL VARIABLE=material VALUE='"{MATERIAL}"' ; Save the material type to a variable + {% if MATERIAL == 'PLA' %} ; If material type is PLA + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="pla_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + #SET_VELOCITY_LIMIT VELOCITY=100 ACCEL=2000 ; Set max speed/acceleration + #SET_INPUT_SHAPER SHAPER_FREQ_X=58.6 SHAPER_FREQ_Y=34.2 SHAPER_TYPE_X=mzv SHAPER_TYPE_Y=mzv ; Set input_shaper + {% elif MATERIAL == 'ABS' %} ; If material type is ABS + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="abs_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'ASA' %} ; If material type is ASA + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="asa_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'ABS+' %} ; If material type is ABS+ + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=1.0 ; Set nevermore_speed to max + #BED_MESH_PROFILE LOAD="abs_plus_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PLA+' %} ; If material type is PLA+ + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="pla_plus_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PETG' %} ; If material type is PETG + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="petg_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'TPU' %} ; If material type is TPU + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=nevermore_speed VALUE=0 ; Set nevermore_speed to off + #BED_MESH_PROFILE LOAD="tpu_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% elif MATERIAL == 'PC' %} ; If material type is PC + #BED_MESH_PROFILE LOAD="pc_mesh" ; Load bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {%else %} ; If any other material type + #BED_MESH_PROFILE LOAD="default" ; Load default bed mesh + #SET_PRESSURE_ADVANCE ADVANCE=0.035 SMOOTH_TIME=0.040 ; Set pressure_advance settings + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% endif %} + +## SET_NOZZLE +## Set nozzle-specific Configs +## +## Add this immediately after your start_print line of the start gcode in Prusa/SuperSlicer: +## SET_NOZZLE NOZZLE='{nozzle_diameter[initial_extruder]}' +## +## Add this immediately after your start_print line of the start gcode in Cura: +## SET_NOZZLE NOZZLE='{machine_nozzle_size}' +## +[gcode_macro SET_NOZZLE] +description: Set values based on nozzle diameter +variable_nozzle: 0 +gcode: + {% set NOZZLE = params.NOZZLE|default(0.4)|float %} ; Get nozzle diameter from slicer + SET_GCODE_VARIABLE MACRO=SET_NOZZLE VARIABLE=nozzle VALUE={NOZZLE} ; Save the nozzle diameter to a variable + {% if NOZZLE == 0.4 %} ; If nozzle diameter is 0.4 + #SET_PRESSURE_ADVANCE ADVANCE=0.040 SMOOTH_TIME=0.040 ; Set pressure_advance settings + {% elif NOZZLE == 0.6 %} ; If nozzle diameter is 0.6 + #SET_PRESSURE_ADVANCE ADVANCE=0.010 SMOOTH_TIME=0.040 ; Set pressure_advance settings + {%else %} ; If any other nozzle diameter + #SET_GCODE_OFFSET Z=0 ; Set z_offset + {% endif %} diff --git a/profiles/hephaestus/patches/3.9.0/vars.patch b/profiles/hephaestus/patches/3.9.0/vars.patch new file mode 100644 index 0000000..e69de29 diff --git a/profiles/hephaestus/variables.cfg b/profiles/hephaestus/variables.cfg index deaf137..2c3cd2f 100644 --- a/profiles/hephaestus/variables.cfg +++ b/profiles/hephaestus/variables.cfg @@ -19,6 +19,8 @@ ## User Profile ## ## Version 3.9.0 2023-5-22 ## ##################################### +# Profile:hephaestus +# Patch:3.9.0 ##################################### ## Hephaestus Profile ## ##################################### diff --git a/scripts/install.sh b/scripts/install.sh index 7b14bc7..88d963e 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -267,7 +267,7 @@ then fi # Check if printcfg is included in the printer.cfg file -if ! grep -qFx "[include printcfg/user_config.cfg]" "$printer" +if grep -qFx "[include user_config.cfg]" "$printer" then echo -e "\e[31mError: printcfg config not included in $printer\e[0m" exit 1 diff --git a/scripts/patch.sh b/scripts/patch.sh new file mode 100644 index 0000000..01b0e72 --- /dev/null +++ b/scripts/patch.sh @@ -0,0 +1,318 @@ +#!/bin/bash +# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +# +# This file is part of printcfg. +# +# printcfg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# printcfg is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printcfg. If not, see . + +##################################### +## Printcfg Patch Script ## +## Version 3.9.0 2023-5-22 ## +##################################### + +# This script will apply version patches to the user profile and user config. +# Arguments: +# $1: (optional) (default: [unused]) + +#################################################################################################### + +# Example: +# ./patch.sh 3.9.0 +# This will force the user profile to be patched for the specified version. + +# Example: +# ./patch.sh +# This will check the user profile version and patch it if necessary. + +#################################################################################################### + +# Set the dev and repo name +dev="rootiest" +repo="printcfg" +# Define the klipper config file +config=~/printer_data/config +# Define the printer.cfg and moonraker.conf files +printer=~/printer_data/config/printer.cfg +moonraker=~/printer_data/config/moonraker.conf +# Set the default profile +default_src=default +user_vars=$config/user_profile.cfg +old_user_vars=$config/$repo/user_profile.cfg +user_cfg=$config/user_config.cfg +old_user_cfg=$config/$repo/user_config.cfg +# Patterns to identify profile name and version +profile_pattern="# Profile:(.*)" # Example: # Profile: default +patch_pattern="# Patch ([0-9]+\.[0-9]+\.[0-9]+) #" # Example: # Patch 3.9.0 + +# Check if any parameters were provided +if [ $# -eq 0 ] +then + # Get the user profile version + user_vars_version=$(grep -oP '(variable_version: ).*' $user_vars) + user_vars_version=${user_vars_version#variable_version: } +else + # Set the user profile version + if [ -n "$1" ] + then + user_vars_version=$1 + fi +fi + +echo "Checking user config path..." + +# Check that user config exists +if [ ! -f $user_cfg ] +then + # Check if old user config exists + if [ -f $old_user_cfg ] + then + echo -e "\e[31mUser config location is out of date.\e[0m" + mv $old_user_cfg $user_cfg + # Verify move was successful + if [ -f $user_cfg ] + then + echo "User config moved to $config/user_config.cfg" + else + echo -e "\e[31mUser config move failed.\e[0m" + exit 1 + fi + # Check if old include line exists in printer.cfg + echo "Checking printer.cfg include line..." + if grep -qFx "[include printcfg/user_config.cfg]" "$printer" + then + echo -e "\e[31mInclude line is out of date.\e[0m" + # Remove old include line + sed -i '/\[include printcfg\/user_config.cfg\]/d' "$printer" + # Add new include line + sed -i '1s/^/[include user_config.cfg]\n/' "$printer" + # Verify include line was added + if grep -qFx "[include user_config.cfg]" "$printer" + then + echo "Include line updated." + # User config is up to date + echo -e "\e[32mUser config is now up to date.\e[0m" + else + echo -e "\e[31mInclude line update failed.\e[0m" + exit 1 + fi + else + if grep -qFx "[include user_config.cfg]" "$printer" + then + echo -e "\e[32mUser config is up to date.\e[0m" + else + echo -e "\e[31mInclude line does not exist.\e[0m" + exit 1 + fi + fi + else + echo -e "\e[31mUser config does not exist.\e[0m" + exit 1 + fi +else + # User config is up to date + echo -e "\e[32mUser config path is up to date.\e[0m" +fi + +# Check user config profile marker +echo "Checking user config: profile..." + +# Search for the profile_pattern in the user_cfg using grep +config_profile=$(grep -oP "$profile_pattern" "$user_cfg" | cut -d':' -f2) + +if [ -n "$config_profile" ]; then + echo "Profile: $config_profile" +else + echo -e "\e[31mUser config profile marker not found.\e[0m" + exit 1 +fi + +# Check user config patch version marker +echo "Checking user config: version..." + +# Search for the patch pattern in the user_cfg +line=$(grep -E "$patch_pattern" "$user_cfg") + +if [ -n "$line" ]; then + # Extract the version number using sed + config_ver=$(echo "$line" | sed -E "s/$patch_pattern/\1/") + echo "Version: $config_ver" +else + echo -e "\e[31mUser config version marker not found.\e[0m" + exit 1 +fi + +# Check user profile profile marker +echo "Checking user profile: profile..." + +# Search for the profile_pattern in the user_vars using grep +profile=$(grep -oP "$profile_pattern" "$user_vars" | cut -d':' -f2) + +if [ -n "$vars_profile" ]; then + echo "Profile: $vars_profile" +else + echo -e "\e[31mUser profile profile marker not found.\e[0m" + exit 1 +fi + +# Check user profile patch version marker +echo "Checking user profile: version..." + +# Search for the patch pattern in the user_vars +line=$(grep -E "$patch_pattern" "$user_vars") + +if [ -n "$line" ]; then + # Extract the version number using sed + vars_ver=$(echo "$line" | sed -E "s/$patch_pattern/\1/") + echo "Version: $vars_ver" +else + echo -e "\e[31mUser profile version marker not found.\e[0m" + exit 1 +fi + +# Find the latest version in the patch_notes. +echo "Checking patch notes..." + +# Search for the patch pattern in the patch_notes +patch_notes=$config/$repo/profiles/$profile/patch_notes.txt + +# Read the file line by line +while read line; do + + # Check if the line contains a version number + if [[ $line =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + + # Extract the version number + version=${line%:*} + + # Compare the version number to the current highest version number + if [[ $version -gt $highest_version ]]; then + + # Set the current highest version number to the new version number + highest_version=$version + + fi + fi + +done < "$patch_notes" + +# Print the highest version number +echo "Latest patch is: $highest_version" + +# Check if the user config version is the same as the highest version +if [ "$config_ver" == "$highest_version" ]; then + echo -e "\e[32mUser config is up to date.\e[0m" + update_config=False +else + echo -e "\e[31mUser config is out of date.\e[0m" + update_config=True +fi + +# Check if the user profile version is the same as the highest version + +if [ "$vars_ver" == "$highest_version" ]; then + echo -e "\e[32mUser profile is up to date.\e[0m" + update_profile=False +else + echo -e "\e[31mUser profile is out of date.\e[0m" + update_profile=True +fi + +if [ "$update_config" == "False" ] && [ "$update_profile" == "False" ]; then + echo -e "\e[32mUser config and profile are up to date.\e[0m" + echo -e "\e[32mNo action required.\e[0m" + exit 0 +else + echo -e "\e[31mUser config and profile are out of date.\e[0m" + # Search for patch files matching the user profile version + echo "Searching for patch files..." + vars_patch=~/$repo/profiles/$profile/patches/$highest_version/vars.cfg + config_patch=~/$repo/profiles/$profile/patches/$highest_version/config.cfg + + if [ "$update_config" == "True" ]; then + # Check if the patch file exists + if [ -f $config_patch ]; then + echo "Patch file found." + # Append the contents of the patch file to the user config + echo "Applying config patch file..." + cat $config_patch >> $user_config + echo "Config patch file applied." + # Update version number in user config + echo "Updating version number..." + # Replace the version number using sed + sed -i -E "s/$patch_pattern/$highest_version/" "$user_cfg" + # Verify that the version number has been updated + if grep -qFx "# Patch: $highest_version" "$user_cfg" + then + echo -e "\e[32mVersion number updated.\e[0m" + else + echo -e "\e[31mVersion number update failed.\e[0m" + exit 1 + fi + echo "Version number updated." + else + echo -e "\e[31mConfig patch file not found.\e[0m" + exit 1 + fi + fi + + if [ "$update_profile" == "True" ]; then + # Check if the patch file exists + if [ -f $profile_patch ]; then + echo "Patch file found." + # Append the contents of the patch file to the user config + echo "Applying profile patch file..." + cat $profile_patch >> $user_profile + echo "Profile patch file applied." + # Update version number in user profile + echo "Updating version number..." + # Replace the version number using sed + sed -i -E "s/$patch_pattern/$highest_version/" "$user_vars" + # Verify that the version number has been updated + if grep -qFx "# Patch: $highest_version" "$user_vars" + then + echo -e "\e[32mVersion number updated.\e[0m" + else + echo -e "\e[31mVersion number update failed.\e[0m" + exit 1 + fi + else + echo -e "\e[31mProfile patch file not found.\e[0m" + exit 1 + fi + fi + + # Summarize results + echo + echo "Summary:" + if [ "$update_config" == "True" ]; then + echo -e "\e[32mUser config was successfully patched.\e[0m" + echo -e "Version: $highest_version" + else + echo -e "\e[32mUser config patch was not needed.\e[0m" + echo -e "Version: $config_ver" + fi + if [ "$update_profile" == "True" ]; then + echo -e "\e[32mUser profile was successfully patched.\e[0m" + echo -e "Version: $highest_version" + else + echo -e "\e[32mUser profile patch was not needed.\e[0m" + echo -e "Version: $vars_ver" + fi + + echo + echo -e "\e[32mPatching completed successfully.\e[0m" + exit 0 + +fi + From 23d2c5236c3983e228814ee36fb3a19b0189d23b Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:07:34 -0400 Subject: [PATCH 03/81] had it backwards --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 88d963e..f93c39f 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -267,7 +267,7 @@ then fi # Check if printcfg is included in the printer.cfg file -if grep -qFx "[include user_config.cfg]" "$printer" +if ! grep -qFx "[include user_config.cfg]" "$printer" then echo -e "\e[31mError: printcfg config not included in $printer\e[0m" exit 1 From 684abb2058ef4e214ff28cf7126e1587064c0bd1 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:09:26 -0400 Subject: [PATCH 04/81] user files belong in $config not $repo --- scripts/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index f93c39f..2c07612 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -288,14 +288,14 @@ then fi # Check if user config exists -if [ ! -f ~/$repo/user_config.cfg ] +if [ ! -f $config/user_config.cfg ] then echo -e "\e[31mError: printcfg user config not found.\e[0m" exit 1 fi # Check if user profile exists -if [ ! -f ~/$repo/user_profile.cfg ] +if [ ! -f $config/user_profile.cfg ] then echo -e "\e[31mError: printcfg user profile not found.\e[0m" exit 1 From 94fd8b298dd869144da2d8c7e92d7bf974be484a Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:14:37 -0400 Subject: [PATCH 05/81] typo in version check --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 01b0e72..0c424a4 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -53,7 +53,7 @@ user_cfg=$config/user_config.cfg old_user_cfg=$config/$repo/user_config.cfg # Patterns to identify profile name and version profile_pattern="# Profile:(.*)" # Example: # Profile: default -patch_pattern="# Patch ([0-9]+\.[0-9]+\.[0-9]+) #" # Example: # Patch 3.9.0 +patch_pattern="# Patch: ([0-9]+\.[0-9]+\.[0-9]+) #" # Example: # Patch 3.9.0 # Check if any parameters were provided if [ $# -eq 0 ] From b9315d39d0aad431daeccc1cbd8941c3f5c29d7e Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:17:04 -0400 Subject: [PATCH 06/81] try to get version another way --- scripts/patch.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 0c424a4..904f903 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -145,7 +145,8 @@ line=$(grep -E "$patch_pattern" "$user_cfg") if [ -n "$line" ]; then # Extract the version number using sed - config_ver=$(echo "$line" | sed -E "s/$patch_pattern/\1/") + #config_ver=$(echo "$line" | sed -E "s/$patch_pattern/\1/") + config_ver==$(grep -oP "$patch_pattern" "$user_cfg" | cut -d':' -f2) echo "Version: $config_ver" else echo -e "\e[31mUser config version marker not found.\e[0m" @@ -173,7 +174,8 @@ line=$(grep -E "$patch_pattern" "$user_vars") if [ -n "$line" ]; then # Extract the version number using sed - vars_ver=$(echo "$line" | sed -E "s/$patch_pattern/\1/") + #vars_ver=$(echo "$line" | sed -E "s/$patch_pattern/\1/") + vars_ver==$(grep -oP "$patch_pattern" "$user_vars" | cut -d':' -f2) echo "Version: $vars_ver" else echo -e "\e[31mUser profile version marker not found.\e[0m" From f90ad8f959a39f65792aac8d5e6c2a808f71a0f7 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:17:55 -0400 Subject: [PATCH 07/81] wrong pattern --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 904f903..d2ab39f 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -53,7 +53,7 @@ user_cfg=$config/user_config.cfg old_user_cfg=$config/$repo/user_config.cfg # Patterns to identify profile name and version profile_pattern="# Profile:(.*)" # Example: # Profile: default -patch_pattern="# Patch: ([0-9]+\.[0-9]+\.[0-9]+) #" # Example: # Patch 3.9.0 +patch_pattern="# Patch: ([0-9]+\.[0-9]+\.[0-9]+)" # Example: # Patch 3.9.0 # Check if any parameters were provided if [ $# -eq 0 ] From be5607005500db82f563d3dccba0f709d4a5ed36 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:18:52 -0400 Subject: [PATCH 08/81] ok less complicated then --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index d2ab39f..b417c45 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -53,7 +53,7 @@ user_cfg=$config/user_config.cfg old_user_cfg=$config/$repo/user_config.cfg # Patterns to identify profile name and version profile_pattern="# Profile:(.*)" # Example: # Profile: default -patch_pattern="# Patch: ([0-9]+\.[0-9]+\.[0-9]+)" # Example: # Patch 3.9.0 +patch_pattern="# Patch: (.*)" # Example: # Patch 3.9.0 # Check if any parameters were provided if [ $# -eq 0 ] From 2677c8eb9bad561cb979cf8207d01fb6352c55ed Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:22:00 -0400 Subject: [PATCH 09/81] hmm maybe I made a mess --- scripts/patch.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index b417c45..5267938 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -141,12 +141,11 @@ fi echo "Checking user config: version..." # Search for the patch pattern in the user_cfg -line=$(grep -E "$patch_pattern" "$user_cfg") +config_ver==$(grep -oP "$patch_pattern" "$user_cfg" | cut -d':' -f2) -if [ -n "$line" ]; then +if [ -n "$config_patch" ]; then # Extract the version number using sed - #config_ver=$(echo "$line" | sed -E "s/$patch_pattern/\1/") - config_ver==$(grep -oP "$patch_pattern" "$user_cfg" | cut -d':' -f2) + #config_ver=$(echo "$config_patch" | sed -E "s/$patch_pattern/\1/") echo "Version: $config_ver" else echo -e "\e[31mUser config version marker not found.\e[0m" @@ -170,12 +169,11 @@ fi echo "Checking user profile: version..." # Search for the patch pattern in the user_vars -line=$(grep -E "$patch_pattern" "$user_vars") +vars_ver==$(grep -oP "$patch_pattern" "$user_vars" | cut -d':' -f2) if [ -n "$line" ]; then # Extract the version number using sed #vars_ver=$(echo "$line" | sed -E "s/$patch_pattern/\1/") - vars_ver==$(grep -oP "$patch_pattern" "$user_vars" | cut -d':' -f2) echo "Version: $vars_ver" else echo -e "\e[31mUser profile version marker not found.\e[0m" From 05136e806dfec2c4f1895b5da74a2afc535d52a6 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:25:14 -0400 Subject: [PATCH 10/81] drop the space duh --- scripts/patch.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 5267938..2fd9f38 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -52,8 +52,8 @@ old_user_vars=$config/$repo/user_profile.cfg user_cfg=$config/user_config.cfg old_user_cfg=$config/$repo/user_config.cfg # Patterns to identify profile name and version -profile_pattern="# Profile:(.*)" # Example: # Profile: default -patch_pattern="# Patch: (.*)" # Example: # Patch 3.9.0 +profile_pattern="# Profile:(.*)" +patch_pattern="# Patch:(.*)" # Check if any parameters were provided if [ $# -eq 0 ] From a2a1ea542e1d02476bc636d54953f40a6470a5f5 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:27:38 -0400 Subject: [PATCH 11/81] ok I think I got it --- scripts/patch.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 2fd9f38..4b9a7e8 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -53,7 +53,7 @@ user_cfg=$config/user_config.cfg old_user_cfg=$config/$repo/user_config.cfg # Patterns to identify profile name and version profile_pattern="# Profile:(.*)" -patch_pattern="# Patch:(.*)" +patch_pattern="# Patch:([0-9]+\.[0-9]+\.[0-9]+" # Check if any parameters were provided if [ $# -eq 0 ] @@ -143,7 +143,7 @@ echo "Checking user config: version..." # Search for the patch pattern in the user_cfg config_ver==$(grep -oP "$patch_pattern" "$user_cfg" | cut -d':' -f2) -if [ -n "$config_patch" ]; then +if [ -n "$config_ver" ]; then # Extract the version number using sed #config_ver=$(echo "$config_patch" | sed -E "s/$patch_pattern/\1/") echo "Version: $config_ver" From cdfffb4b5d2d242522571880223bdfc53f37838a Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:28:16 -0400 Subject: [PATCH 12/81] ok fuck it --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 4b9a7e8..8455828 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -53,7 +53,7 @@ user_cfg=$config/user_config.cfg old_user_cfg=$config/$repo/user_config.cfg # Patterns to identify profile name and version profile_pattern="# Profile:(.*)" -patch_pattern="# Patch:([0-9]+\.[0-9]+\.[0-9]+" +patch_pattern="# Patch:(.*)" # Check if any parameters were provided if [ $# -eq 0 ] From 9431259bdd3a4d43a6fabf52c8645301a5974c7b Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:29:25 -0400 Subject: [PATCH 13/81] ok this is the one --- scripts/patch.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 8455828..292f1f1 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -141,11 +141,10 @@ fi echo "Checking user config: version..." # Search for the patch pattern in the user_cfg -config_ver==$(grep -oP "$patch_pattern" "$user_cfg" | cut -d':' -f2) +config_ver=$(grep -oP "$patch_pattern" "$user_cfg" | cut -d':' -f2) if [ -n "$config_ver" ]; then # Extract the version number using sed - #config_ver=$(echo "$config_patch" | sed -E "s/$patch_pattern/\1/") echo "Version: $config_ver" else echo -e "\e[31mUser config version marker not found.\e[0m" @@ -171,9 +170,8 @@ echo "Checking user profile: version..." # Search for the patch pattern in the user_vars vars_ver==$(grep -oP "$patch_pattern" "$user_vars" | cut -d':' -f2) -if [ -n "$line" ]; then +if [ -n "$vars_ver" ]; then # Extract the version number using sed - #vars_ver=$(echo "$line" | sed -E "s/$patch_pattern/\1/") echo "Version: $vars_ver" else echo -e "\e[31mUser profile version marker not found.\e[0m" From 04cbb4f15873d68094d0f93e98e002555e371a4b Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:31:01 -0400 Subject: [PATCH 14/81] maybe not lol --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 292f1f1..d8e5d03 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -155,7 +155,7 @@ fi echo "Checking user profile: profile..." # Search for the profile_pattern in the user_vars using grep -profile=$(grep -oP "$profile_pattern" "$user_vars" | cut -d':' -f2) +vars_profile=$(grep -oP "$profile_pattern" "$user_vars" | cut -d':' -f2) if [ -n "$vars_profile" ]; then echo "Profile: $vars_profile" From c2e04750fbf7b2b316a54c4340946ad134280e8e Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:31:54 -0400 Subject: [PATCH 15/81] extra equals signs man --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index d8e5d03..fbeda36 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -168,7 +168,7 @@ fi echo "Checking user profile: version..." # Search for the patch pattern in the user_vars -vars_ver==$(grep -oP "$patch_pattern" "$user_vars" | cut -d':' -f2) +vars_ver=$(grep -oP "$patch_pattern" "$user_vars" | cut -d':' -f2) if [ -n "$vars_ver" ]; then # Extract the version number using sed From 710e8ace18c9075316d179742733e90b72793ce1 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:35:25 -0400 Subject: [PATCH 16/81] more double equals --- scripts/patch.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index fbeda36..5eb3d41 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -182,7 +182,7 @@ fi echo "Checking patch notes..." # Search for the patch pattern in the patch_notes -patch_notes=$config/$repo/profiles/$profile/patch_notes.txt +patch_notes=$config/$repo/profiles/$vars_profile/patch_notes.txt # Read the file line by line while read line; do @@ -208,7 +208,7 @@ done < "$patch_notes" echo "Latest patch is: $highest_version" # Check if the user config version is the same as the highest version -if [ "$config_ver" == "$highest_version" ]; then +if [ "$config_ver" = "$highest_version" ]; then echo -e "\e[32mUser config is up to date.\e[0m" update_config=False else @@ -218,7 +218,7 @@ fi # Check if the user profile version is the same as the highest version -if [ "$vars_ver" == "$highest_version" ]; then +if [ "$vars_ver" = "$highest_version" ]; then echo -e "\e[32mUser profile is up to date.\e[0m" update_profile=False else @@ -226,7 +226,7 @@ else update_profile=True fi -if [ "$update_config" == "False" ] && [ "$update_profile" == "False" ]; then +if [ "$update_config" = "False" ] && [ "$update_profile" = "False" ]; then echo -e "\e[32mUser config and profile are up to date.\e[0m" echo -e "\e[32mNo action required.\e[0m" exit 0 @@ -234,10 +234,10 @@ else echo -e "\e[31mUser config and profile are out of date.\e[0m" # Search for patch files matching the user profile version echo "Searching for patch files..." - vars_patch=~/$repo/profiles/$profile/patches/$highest_version/vars.cfg - config_patch=~/$repo/profiles/$profile/patches/$highest_version/config.cfg + vars_patch=~/$repo/profiles/$vars_profile/patches/$highest_version/vars.cfg + config_patch=~/$repo/profiles/$config_profile/patches/$highest_version/config.cfg - if [ "$update_config" == "True" ]; then + if [ "$update_config" = "True" ]; then # Check if the patch file exists if [ -f $config_patch ]; then echo "Patch file found." @@ -264,7 +264,7 @@ else fi fi - if [ "$update_profile" == "True" ]; then + if [ "$update_profile" = "True" ]; then # Check if the patch file exists if [ -f $profile_patch ]; then echo "Patch file found." @@ -293,14 +293,14 @@ else # Summarize results echo echo "Summary:" - if [ "$update_config" == "True" ]; then + if [ "$update_config" = "True" ]; then echo -e "\e[32mUser config was successfully patched.\e[0m" echo -e "Version: $highest_version" else echo -e "\e[32mUser config patch was not needed.\e[0m" echo -e "Version: $config_ver" fi - if [ "$update_profile" == "True" ]; then + if [ "$update_profile" = "True" ]; then echo -e "\e[32mUser profile was successfully patched.\e[0m" echo -e "Version: $highest_version" else From 285c91cd979163bab4a4cbd2fde908813f6ebf5f Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:36:58 -0400 Subject: [PATCH 17/81] i dunno man --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 5eb3d41..3a8b7de 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -182,7 +182,7 @@ fi echo "Checking patch notes..." # Search for the patch pattern in the patch_notes -patch_notes=$config/$repo/profiles/$vars_profile/patch_notes.txt +patch_notes=~/$repo/profiles/$vars_profile/patch_notes.txt # Read the file line by line while read line; do From c6bb912c4efde46bf5363f703d5e7c992e3b2d69 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:39:15 -0400 Subject: [PATCH 18/81] the version updating loop is broken --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 3a8b7de..7ea876b 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -182,7 +182,7 @@ fi echo "Checking patch notes..." # Search for the patch pattern in the patch_notes -patch_notes=~/$repo/profiles/$vars_profile/patch_notes.txt +patch_notes="~/$repo/profiles/$vars_profile/patch_notes.txt" # Read the file line by line while read line; do From a04ec1c491ad386e8a17c34bda0d192200ca149f Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 22 May 2023 21:44:30 -0400 Subject: [PATCH 19/81] ok this might be it --- scripts/patch.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 7ea876b..d0c9ed8 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -40,11 +40,13 @@ # Set the dev and repo name dev="rootiest" repo="printcfg" +# Get home directory +home=$(eval echo ~$USER) # Define the klipper config file -config=~/printer_data/config +config=$home/printer_data/config # Define the printer.cfg and moonraker.conf files -printer=~/printer_data/config/printer.cfg -moonraker=~/printer_data/config/moonraker.conf +printer=$home/printer_data/config/printer.cfg +moonraker=$home/printer_data/config/moonraker.conf # Set the default profile default_src=default user_vars=$config/user_profile.cfg @@ -182,7 +184,8 @@ fi echo "Checking patch notes..." # Search for the patch pattern in the patch_notes -patch_notes="~/$repo/profiles/$vars_profile/patch_notes.txt" +patch_notes="$home/$repo/profiles/$vars_profile/patch_notes.txt" + # Read the file line by line while read line; do @@ -234,8 +237,8 @@ else echo -e "\e[31mUser config and profile are out of date.\e[0m" # Search for patch files matching the user profile version echo "Searching for patch files..." - vars_patch=~/$repo/profiles/$vars_profile/patches/$highest_version/vars.cfg - config_patch=~/$repo/profiles/$config_profile/patches/$highest_version/config.cfg + vars_patch=$home/$repo/profiles/$vars_profile/patches/$highest_version/vars.cfg + config_patch=$home/$repo/profiles/$config_profile/patches/$highest_version/config.cfg if [ "$update_config" = "True" ]; then # Check if the patch file exists From 6130e332df9a5af59c9db47ae05a941a203dd739 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 01:31:10 -0400 Subject: [PATCH 20/81] dev branch --- moonraker-printcfg.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moonraker-printcfg.conf b/moonraker-printcfg.conf index 0ca19ae..473a153 100644 --- a/moonraker-printcfg.conf +++ b/moonraker-printcfg.conf @@ -7,7 +7,7 @@ [update_manager printcfg] type: git_repo channel: dev -primary_branch: master +primary_branch: dev path: ~/printcfg origin: https://github.com/rootiest/printcfg.git is_system_service: False From 25476efc3cc2e63ac93fb30e6be6a056c7f89f86 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 12:49:13 -0400 Subject: [PATCH 21/81] new search_replace and support for branches --- .vscode/settings.json | 5 +- scripts/install.sh | 130 +++++++++++++++----- scripts/patch.sh | 4 +- scripts/search_replace.py | 59 +++++++++ scripts/setup.sh | 11 +- moonraker-printcfg.conf => src/mooncfg.conf | 0 6 files changed, 171 insertions(+), 38 deletions(-) create mode 100644 scripts/search_replace.py rename moonraker-printcfg.conf => src/mooncfg.conf (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json index c2dce99..66b6b74 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "licenser.projectName": "printcfg" -} \ No newline at end of file + "licenser.projectName": "printcfg", + "python.analysis.typeCheckingMode": "basic" +} diff --git a/scripts/install.sh b/scripts/install.sh index 2c07612..b5baddd 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,18 +1,18 @@ #!/bin/bash # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) -# +# # This file is part of Hephaestus. -# +# # Hephaestus is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # Hephaestus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with Hephaestus. If not, see . @@ -24,12 +24,13 @@ # This script will download and install the printcfg package from GitHub. # Arguments: # $1: (optional) (default: default) +# $2: (optional) (default: master) #################################################################################################### # To install with the default profile open a terminal and run the following: -# curl https://raw.githubusercontent.com/rootiest/printcfg/master/scripts/install.sh | bash +# curl https://raw.githubusercontent.com/rootiest/printcfg/master/scripts/install.sh | bash # or to specify a profile: @@ -44,11 +45,14 @@ PKGLIST="git python3-pip bc" # Set the dev and repo name dev="rootiest" repo="printcfg" +branch="master" +# Get home directory +home=$(eval echo ~$USER) # Define the klipper config file -config=~/printer_data/config +config=$home/printer_data/config # Define the printer.cfg and moonraker.conf files -printer=~/printer_data/config/printer.cfg -moonraker=~/printer_data/config/moonraker.conf +printer=$config/printer.cfg +moonraker=$config/moonraker.conf # Set the default profile default_src=default @@ -62,6 +66,11 @@ else then src="$1" fi + # Set the branch + if [ -n "$2" ] + then + branch="$2" + fi fi # Welcome message @@ -101,15 +110,15 @@ if ! git ls-remote https://github.com/"$dev"/"$repo" >/dev/null; then fi # Change to the home directory -cd ~ +cd $home # Check if printcfg is already installed -if [ -d ~/$repo ]; +if [ -d $home/$repo ]; then echo -e "\e[33mprintcfg repo is already installed.\e[0m" echo "Updating printcfg repo..." # Change to the repo directory - cd ~/$repo + cd $home/$repo # Pull the latest changes git pull else @@ -117,7 +126,7 @@ else # Clone the repo git clone https://github.com/"$dev"/"$repo" # Check if the repo was cloned - if [ ! -d ~/$repo ]; then + if [ ! -d $home/$repo ]; then echo -e "\e[31mError: Repo not cloned.\e[0m" exit 1 else @@ -126,7 +135,46 @@ else fi # Change to the repo directory -cd ~/$repo +cd $home/$repo + +# Find the current branch +current_branch=$(git branch --show-current) + +# Check if the branch was provided +if [ -n "$2" ] +then + echo "Checking out branch $branch..." + # Check if the branch exists + if ! git ls-remote --heads + then + echo -e "\e[31mError: Branch $branch does not exist.\e[0m" + exit 1 + fi +else + echo "Staying on branch $current_branch..." + branch=$current_branch +fi + +# Check if the branch is already checked out +if [ "$current_branch" != "$branch" ]; then + git switch $branch + # Check if the branch was switched + if [ $? -ne 0 ]; then + echo -e "\e[31mError: Branch not switched.\e[0m" + exit 1 + else + echo -e "\e[32mBranch switched successfully.\e[0m" + pull_branch=true + fi +else + echo -e "\e[33mAlready on branch $branch.\e[0m" +fi + +# Pull the latest changes +if [ -n "$pull_branch" ]; then + echo "Pulling latest changes..." + git pull +fi ### Run any setup scripts ### @@ -162,7 +210,7 @@ fi if [ ! -f $config/user_config.cfg ] then # Check if profile config exists - if [ ! -f ~/$repo/profiles/$src/config.cfg ] + if [ ! -f $home/$repo/profiles/$src/config.cfg ] then echo -e "\e[31mError: Config Profile '$src' not found.\e[0m" echo "Using default config profile: $default_src" @@ -171,7 +219,7 @@ then # Copy user profile to config directory echo -e "\e[36mUsing config profile: $src\e[0m" echo "Creating user_config in config directory..." - cp -r ~/$repo/profiles/$src/config.cfg $config/user_config.cfg + cp -r $home/$repo/profiles/$src/config.cfg $config/user_config.cfg else echo -e "\e[32mUser config already exists.\e[0m" fi @@ -180,7 +228,7 @@ fi if [ ! -f $config/user_profile.cfg ] then # Check if profile exists - if [ ! -f ~/$repo/profiles/$src/variables.cfg ] + if [ ! -f $home/$repo/profiles/$src/variables.cfg ] then echo -e "\e[31mError: Profile '$src' not found.\e[0m" echo "Using default variables profile: $default_src" @@ -189,7 +237,7 @@ then # Copy user profile to config directory echo -e "\e[36mUsing variables profile: $src\e[0m" echo "Creating user profile in config directory..." - cp -r ~/$repo/profiles/$src/variables.cfg $config/user_profile.cfg + cp -r $home/$repo/profiles/$src/variables.cfg $config/user_profile.cfg else echo -e "\e[32mUser profile already exists.\e[0m" fi @@ -199,7 +247,7 @@ if [ ! -L $config/$repo ] then # Link printcfg to the printer config directory echo "Linking printcfg to the printer config directory..." - ln -s ~/$repo $config/printcfg + ln -s $home/$repo $config/printcfg # Check if the link was created if [ ! -L $config/$repo ] then @@ -211,16 +259,17 @@ else fi # Check if include line exists in printer.cfg -if grep -qFx "[include user_config.cfg]" "$printer" +uconfig_pattern="[include user_config.cfg]" +if grep -qFx "$uconfig_pattern" "$printer" then echo -e "\e[33mprintcfg config already included.\e[0m" else echo "Adding printcfg config to $printer..." # Add printcfg config to beginning of file - sed -i '1s/^/[include user_config.cfg]\n/' "$printer" + python3 search_replace.py "$uconfig_pattern" "$uconfig_pattern" "$printer" fi -# Check if include line exists in moonraker.conf +# Verify moonraker is installed if [ ! -f "$moonraker" ] then echo -e "\e[31mError: File '$moonraker' not found.\e[0m" @@ -228,24 +277,44 @@ then exit 1 fi -# Check if the moonraker config already contains printcfg config -if grep -qFx "[include printcfg/moonraker-printcfg.conf]" "$moonraker" +# Check if the moonraker-printcfg.conf file exists +if [ ! -f $config/moonraker-printcfg.conf ] +then + # Copy moonraker config to config directory + echo "Creating moonraker config in config directory..." + cp -r $home/$repo/src/mooncfg.conf $config/moonraker-printcfg.conf +else + echo -e "\e[32mMoonraker config already exists.\e[0m" +fi + +# Set branch in moonraker-printcfg.conf +echo "Setting branch in moonraker config..." +# Define search pattern +branch_pattern="primary_branch:" +# Set branch to current branch +python3 $home/$repo/scripts/search_replace.py $branch_pattern "$branch_pattern $branch" $config/moonraker-printcfg.conf + +# Check if the moonraker config already contains the old printcfg config +moon_pattern="[include printcfg/moonraker-printcfg.conf]" +new_moon="[include moonraker-printcfg.conf]" + +if grep -qFx "$new_moon" "$moonraker" then echo -e "\e[33mprintcfg moonraker already included.\e[0m" else echo "Adding printcfg config to $moonraker..." - # Add printcfg config to beginning of file - sed -i '1s/^/[include printcfg\/moonraker-printcfg.conf]\n/' "$moonraker" + # Add printcfg config to moonraker + python3 $home/$repo/scripts/search_replace.py $moon_pattern $new_moon $moonraker fi echo -e "\e[32mInstall complete.\e[0m" -echo +echo # Perform all checks to make sure printcfg is installed correctly echo "Checking printcfg installation..." # Check if the repo exists -if [ ! -d ~/$repo ]; then +if [ ! -d $home/$repo ]; then echo -e "\e[31mError: Repo not cloned.\e[0m" exit 1 fi @@ -267,14 +336,14 @@ then fi # Check if printcfg is included in the printer.cfg file -if ! grep -qFx "[include user_config.cfg]" "$printer" +if ! grep -qFx "$uconfig_pattern" "$printer" then echo -e "\e[31mError: printcfg config not included in $printer\e[0m" exit 1 fi # Check if the moonraker config contains printcfg config -if ! grep -qFx "[include printcfg/moonraker-printcfg.conf]" "$moonraker" +if ! grep -qFx "$new_moon" "$moonraker" then echo -e "\e[31mError: printcfg config not included in $moonraker\e[0m" exit 1 @@ -313,7 +382,7 @@ echo # Perform setup checks echo "Performing Setup Checks..." echo -source ~/$repo/scripts/setup.sh $src +source $home/$repo/scripts/setup.sh $src # Check if setup.out exists if [ -f setup.out ] @@ -335,4 +404,3 @@ systemctl restart moonraker echo echo -e "\e[32mInstallation completed successfully.\e[0m" - diff --git a/scripts/patch.sh b/scripts/patch.sh index d0c9ed8..bd9e950 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -40,6 +40,7 @@ # Set the dev and repo name dev="rootiest" repo="printcfg" +branch="master" # Get home directory home=$(eval echo ~$USER) # Define the klipper config file @@ -201,7 +202,8 @@ while read line; do # Set the current highest version number to the new version number highest_version=$version - + # Replace the line with the new highest version number + highest_version_line=$line fi fi diff --git a/scripts/search_replace.py b/scripts/search_replace.py new file mode 100644 index 0000000..83d5a3f --- /dev/null +++ b/scripts/search_replace.py @@ -0,0 +1,59 @@ +# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +# +# This file is part of printcfg. +# +# printcfg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# printcfg is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printcfg. If not, see . + +import os +import sys + +def search_and_replace(search_text, replace_text, file_name): + """Searches for the line containing the search_text and replaces the whole line with the replace_text and saves the updated file over the original. + + Args: + search_text: The text to search for. + replace_text: The text to replace the search_text with. + file_name: The name of the file to search and replace. + + Returns: + A status indicating whether the change was successful. + """ + + with open(file_name, "r") as f: + lines = f.readlines() + + found = False + for i, line in enumerate(lines): + if search_text in line: + lines[i] = replace_text + '\n' + found = True + break + + if not found: + lines.insert(0, replace_text + "\n") + + with open(file_name, "w") as f: + f.writelines(lines) + + return found + +search_text = sys.argv[1] +replace_text = sys.argv[2] +file_name = sys.argv[3] + +status = search_and_replace(search_text, replace_text, file_name) +if status: + print("The change was successful.") +else: + print("The text to search for was not found.") diff --git a/scripts/setup.sh b/scripts/setup.sh index e6eb007..cc05bcd 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -41,11 +41,14 @@ # Set the dev and repo name dev="rootiest" repo="printcfg" +branch="master" +# Get home directory +home=$(eval echo ~$USER) # Define the klipper config file -config=~/printer_data/config +config=$home/printer_data/config # Define the printer.cfg and moonraker.conf files -printer=~/printer_data/config/printer.cfg -moonraker=~/printer_data/config/moonraker.conf +printer=$home/printer_data/config/printer.cfg +moonraker=$home/printer_data/config/moonraker.conf # Set the default profile default_src=default user_vars=$config/user_profile.cfg @@ -186,7 +189,7 @@ if [ "$user_vars_version" != "$src_vars_version" ]; then echo echo "To force an update, run setup.sh with the profile you want to use and the word 'force' as arguments." echo "For example, to force an update for the default profile, run the following command:" - echo " ~/$repo/scripts/setup.sh default force" + echo " $home/$repo/scripts/setup.sh default force" echo echo -e "\033[4;31mNOTE: Forcing the update will overwrite any changes you have made to the user profile.\e[0m" echo -e "\e[33mTo avoid this: please update the user profile manually following the patch notes.\e[0m" diff --git a/moonraker-printcfg.conf b/src/mooncfg.conf similarity index 100% rename from moonraker-printcfg.conf rename to src/mooncfg.conf From 100b861e0015657b1421473137f8b54b86266a78 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 12:51:15 -0400 Subject: [PATCH 22/81] watch out for spaces in python arguments --- scripts/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index b5baddd..1a5c789 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -292,7 +292,7 @@ echo "Setting branch in moonraker config..." # Define search pattern branch_pattern="primary_branch:" # Set branch to current branch -python3 $home/$repo/scripts/search_replace.py $branch_pattern "$branch_pattern $branch" $config/moonraker-printcfg.conf +python3 $home/$repo/scripts/search_replace.py "$branch_pattern" "$branch_pattern $branch" "$config/moonraker-printcfg.conf" # Check if the moonraker config already contains the old printcfg config moon_pattern="[include printcfg/moonraker-printcfg.conf]" @@ -304,7 +304,7 @@ then else echo "Adding printcfg config to $moonraker..." # Add printcfg config to moonraker - python3 $home/$repo/scripts/search_replace.py $moon_pattern $new_moon $moonraker + python3 $home/$repo/scripts/search_replace.py "$moon_pattern" "$new_moon" "$moonraker" fi echo -e "\e[32mInstall complete.\e[0m" From 3f9baa9cd63a0fd903400cc380b169d9064c6d2e Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 12:53:12 -0400 Subject: [PATCH 23/81] try without source --- scripts/install.sh | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 1a5c789..a4572f7 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -382,15 +382,10 @@ echo # Perform setup checks echo "Performing Setup Checks..." echo -source $home/$repo/scripts/setup.sh $src -# Check if setup.out exists -if [ -f setup.out ] -then - cat setup.out -else - echo -e "\e[32mSetup checks passed.\e[0m" -fi +$home/$repo/scripts/setup.sh $src + +echo -e "\e[32mSetup checks passed.\e[0m" echo From e663bee4f3604998f2e2bb46d56c0755598ba1f2 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 12:55:00 -0400 Subject: [PATCH 24/81] executable scripting --- scripts/install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/install.sh b/scripts/install.sh index a4572f7..f1b8144 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -188,6 +188,9 @@ if [ -f setup.py ]; then python setup.py install fi +# Make all scripts in printcfg executable +chmod +x $home/$repo/scripts/*.sh + ### Install into klippers config ### # Check if config directory exists From 2eca22f6034bf7cd329f28f1297b47e331718448 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:03:37 -0400 Subject: [PATCH 25/81] use python method for patching --- scripts/patch.sh | 49 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index bd9e950..389c875 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -1,18 +1,18 @@ #!/bin/bash # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) -# +# # This file is part of printcfg. -# +# # printcfg is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # printcfg is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with printcfg. If not, see . @@ -57,6 +57,9 @@ old_user_cfg=$config/$repo/user_config.cfg # Patterns to identify profile name and version profile_pattern="# Profile:(.*)" patch_pattern="# Patch:(.*)" +uconfig_pattern_old="[include printcfg/user_config.cfg]" +uconfig_pattern_new="[include user_config.cfg]" +ver_patch="# Patch: " # Check if any parameters were provided if [ $# -eq 0 ] @@ -92,15 +95,13 @@ then fi # Check if old include line exists in printer.cfg echo "Checking printer.cfg include line..." - if grep -qFx "[include printcfg/user_config.cfg]" "$printer" + if grep -qFx "$uconfig_pattern_old" "$printer" then echo -e "\e[31mInclude line is out of date.\e[0m" - # Remove old include line - sed -i '/\[include printcfg\/user_config.cfg\]/d' "$printer" - # Add new include line - sed -i '1s/^/[include user_config.cfg]\n/' "$printer" + # Replace old include line with new include line + python3 search_replace.py "$uconfig_pattern_old" "$uconfig_pattern_new" "$printer" # Verify include line was added - if grep -qFx "[include user_config.cfg]" "$printer" + if grep -qFx "$uconfig_pattern_new" "$printer" then echo "Include line updated." # User config is up to date @@ -110,7 +111,7 @@ then exit 1 fi else - if grep -qFx "[include user_config.cfg]" "$printer" + if grep -qFx "$uconfig_pattern_new" "$printer" then echo -e "\e[32mUser config is up to date.\e[0m" else @@ -190,23 +191,23 @@ patch_notes="$home/$repo/profiles/$vars_profile/patch_notes.txt" # Read the file line by line while read line; do - + # Check if the line contains a version number if [[ $line =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - + # Extract the version number version=${line%:*} - + # Compare the version number to the current highest version number if [[ $version -gt $highest_version ]]; then - + # Set the current highest version number to the new version number highest_version=$version # Replace the line with the new highest version number highest_version_line=$line fi fi - + done < "$patch_notes" # Print the highest version number @@ -241,7 +242,7 @@ else echo "Searching for patch files..." vars_patch=$home/$repo/profiles/$vars_profile/patches/$highest_version/vars.cfg config_patch=$home/$repo/profiles/$config_profile/patches/$highest_version/config.cfg - + if [ "$update_config" = "True" ]; then # Check if the patch file exists if [ -f $config_patch ]; then @@ -253,9 +254,9 @@ else # Update version number in user config echo "Updating version number..." # Replace the version number using sed - sed -i -E "s/$patch_pattern/$highest_version/" "$user_cfg" + python3 search_replace.py "$ver_patch" "$ver_patch$highest_version" "$user_cfg" # Verify that the version number has been updated - if grep -qFx "# Patch: $highest_version" "$user_cfg" + if grep -qFx "$ver_patch$highest_version" "$user_cfg" then echo -e "\e[32mVersion number updated.\e[0m" else @@ -268,7 +269,7 @@ else exit 1 fi fi - + if [ "$update_profile" = "True" ]; then # Check if the patch file exists if [ -f $profile_patch ]; then @@ -280,9 +281,9 @@ else # Update version number in user profile echo "Updating version number..." # Replace the version number using sed - sed -i -E "s/$patch_pattern/$highest_version/" "$user_vars" + python3 search_replace.py "$ver_patch" "$ver_patch$highest_version" "$user_vars" # Verify that the version number has been updated - if grep -qFx "# Patch: $highest_version" "$user_vars" + if grep -qFx "$ver_patch$highest_version" "$user_vars" then echo -e "\e[32mVersion number updated.\e[0m" else @@ -312,10 +313,10 @@ else echo -e "\e[32mUser profile patch was not needed.\e[0m" echo -e "Version: $vars_ver" fi - + echo echo -e "\e[32mPatching completed successfully.\e[0m" exit 0 - + fi From b1659a969e776bf246114e90213e6f7d157f5e55 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:07:36 -0400 Subject: [PATCH 26/81] test --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 389c875..dc9bd80 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -134,7 +134,7 @@ echo "Checking user config: profile..." # Search for the profile_pattern in the user_cfg using grep config_profile=$(grep -oP "$profile_pattern" "$user_cfg" | cut -d':' -f2) -if [ -n "$config_profile" ]; then +if [ "$config_profile" ]; then echo "Profile: $config_profile" else echo -e "\e[31mUser config profile marker not found.\e[0m" From 907c6afe913ea8525bbb503a632bb07a60d54868 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:09:45 -0400 Subject: [PATCH 27/81] oops dummy --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index dc9bd80..389c875 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -134,7 +134,7 @@ echo "Checking user config: profile..." # Search for the profile_pattern in the user_cfg using grep config_profile=$(grep -oP "$profile_pattern" "$user_cfg" | cut -d':' -f2) -if [ "$config_profile" ]; then +if [ -n "$config_profile" ]; then echo "Profile: $config_profile" else echo -e "\e[31mUser config profile marker not found.\e[0m" From 3b1a65f88db9b79dfbcf00ed29e9f222d81e0191 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:19:05 -0400 Subject: [PATCH 28/81] re-work the patch_notes check --- scripts/patch.sh | 60 +++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 389c875..5d57b4d 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -188,27 +188,39 @@ echo "Checking patch notes..." # Search for the patch pattern in the patch_notes patch_notes="$home/$repo/profiles/$vars_profile/patch_notes.txt" - -# Read the file line by line -while read line; do - - # Check if the line contains a version number - if [[ $line =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - - # Extract the version number - version=${line%:*} - - # Compare the version number to the current highest version number - if [[ $version -gt $highest_version ]]; then - - # Set the current highest version number to the new version number - highest_version=$version - # Replace the line with the new highest version number - highest_version_line=$line +# Read the contents of the file +file_content=$(cat $patch_notes) + +# Initialize variables +highest_version="" +highest_major="" +highest_minor="" +highest_patch="" + +# Split the file content by version sections +IFS=$'\n' read -d '' -ra versions <<< "$file_content" + +# Iterate over each version section +for version in "${versions[@]}"; do + # Extract the version number from the section + if [[ $version =~ ^([0-9]+\.[0-9]+\.[0-9]+): ]]; then + current_version="${BASH_REMATCH[1]}" + + # Extract the major, minor, and patch numbers + IFS='.' read -ra version_parts <<< "$current_version" + major="${version_parts[0]}" + minor="${version_parts[1]}" + patch="${version_parts[2]}" + + # Check if the current version is higher + if [[ -z $highest_version || $major -gt $highest_major || ($major -eq $highest_major && $minor -gt $highest_minor) || ($major -eq $highest_major && $minor -eq $highest_minor && $patch -gt $highest_patch) ]]; then + highest_version="$current_version" + highest_major="$major" + highest_minor="$minor" + highest_patch="$patch" fi fi - -done < "$patch_notes" +done # Print the highest version number echo "Latest patch is: $highest_version" @@ -242,7 +254,7 @@ else echo "Searching for patch files..." vars_patch=$home/$repo/profiles/$vars_profile/patches/$highest_version/vars.cfg config_patch=$home/$repo/profiles/$config_profile/patches/$highest_version/config.cfg - + if [ "$update_config" = "True" ]; then # Check if the patch file exists if [ -f $config_patch ]; then @@ -269,7 +281,7 @@ else exit 1 fi fi - + if [ "$update_profile" = "True" ]; then # Check if the patch file exists if [ -f $profile_patch ]; then @@ -295,7 +307,7 @@ else exit 1 fi fi - + # Summarize results echo echo "Summary:" @@ -313,10 +325,10 @@ else echo -e "\e[32mUser profile patch was not needed.\e[0m" echo -e "Version: $vars_ver" fi - + echo echo -e "\e[32mPatching completed successfully.\e[0m" exit 0 - + fi From 0e4f184683b8d396f5b1bd31516209880b529221 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:28:35 -0400 Subject: [PATCH 29/81] use some more python :) --- scripts/patch.sh | 45 +++++++--------------------------------- scripts/version_patch.py | 41 ++++++++++++++++++++++++++++++++++++ src/requirements.txt | 3 +++ 3 files changed, 51 insertions(+), 38 deletions(-) create mode 100644 scripts/version_patch.py diff --git a/scripts/patch.sh b/scripts/patch.sh index 5d57b4d..c3b8ba7 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -188,39 +188,8 @@ echo "Checking patch notes..." # Search for the patch pattern in the patch_notes patch_notes="$home/$repo/profiles/$vars_profile/patch_notes.txt" -# Read the contents of the file -file_content=$(cat $patch_notes) - -# Initialize variables -highest_version="" -highest_major="" -highest_minor="" -highest_patch="" - -# Split the file content by version sections -IFS=$'\n' read -d '' -ra versions <<< "$file_content" - -# Iterate over each version section -for version in "${versions[@]}"; do - # Extract the version number from the section - if [[ $version =~ ^([0-9]+\.[0-9]+\.[0-9]+): ]]; then - current_version="${BASH_REMATCH[1]}" - - # Extract the major, minor, and patch numbers - IFS='.' read -ra version_parts <<< "$current_version" - major="${version_parts[0]}" - minor="${version_parts[1]}" - patch="${version_parts[2]}" - - # Check if the current version is higher - if [[ -z $highest_version || $major -gt $highest_major || ($major -eq $highest_major && $minor -gt $highest_minor) || ($major -eq $highest_major && $minor -eq $highest_minor && $patch -gt $highest_patch) ]]; then - highest_version="$current_version" - highest_major="$major" - highest_minor="$minor" - highest_patch="$patch" - fi - fi -done +# Read version from patch notes +highest_version=$(python3 read_patch_notes.py "$patch_notes") # Print the highest version number echo "Latest patch is: $highest_version" @@ -254,7 +223,7 @@ else echo "Searching for patch files..." vars_patch=$home/$repo/profiles/$vars_profile/patches/$highest_version/vars.cfg config_patch=$home/$repo/profiles/$config_profile/patches/$highest_version/config.cfg - + if [ "$update_config" = "True" ]; then # Check if the patch file exists if [ -f $config_patch ]; then @@ -281,7 +250,7 @@ else exit 1 fi fi - + if [ "$update_profile" = "True" ]; then # Check if the patch file exists if [ -f $profile_patch ]; then @@ -307,7 +276,7 @@ else exit 1 fi fi - + # Summarize results echo echo "Summary:" @@ -325,10 +294,10 @@ else echo -e "\e[32mUser profile patch was not needed.\e[0m" echo -e "Version: $vars_ver" fi - + echo echo -e "\e[32mPatching completed successfully.\e[0m" exit 0 - + fi diff --git a/scripts/version_patch.py b/scripts/version_patch.py new file mode 100644 index 0000000..c2a32a2 --- /dev/null +++ b/scripts/version_patch.py @@ -0,0 +1,41 @@ +# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +# +# This file is part of printcfg. +# +# printcfg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# printcfg is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printcfg. If not, see . + +import os +import sys +import re + +def find_highest_version(file_name): + highest_version = None + + with open(file_name, 'r') as file: + content = file.read() + + pattern = r'(\d+\.\d+\.\d+):' + versions = re.findall(pattern, content) + + for version in versions: + if highest_version is None or version > highest_version: + highest_version = version + + return highest_version + + +# Test the function +file_name = sys.argv[1] +highest_version = find_highest_version(file_name) +print("Highest version number:", highest_version) diff --git a/src/requirements.txt b/src/requirements.txt index e69de29..92d6213 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -0,0 +1,3 @@ +python-apt==2.2.1 +python-dateutil==2.8.2 +requests==2.30.0 \ No newline at end of file From d010cd11aedd2e1e66d041d1a7caffa5a48d2fef Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:29:46 -0400 Subject: [PATCH 30/81] oopsie --- scripts/patch.sh | 2 +- scripts/{version_patch.py => read_patch_notes.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename scripts/{version_patch.py => read_patch_notes.py} (100%) diff --git a/scripts/patch.sh b/scripts/patch.sh index c3b8ba7..c197390 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -189,7 +189,7 @@ echo "Checking patch notes..." patch_notes="$home/$repo/profiles/$vars_profile/patch_notes.txt" # Read version from patch notes -highest_version=$(python3 read_patch_notes.py "$patch_notes") +highest_version=$(python3 $home/$repo/scripts/read_patch_notes.py "$patch_notes") # Print the highest version number echo "Latest patch is: $highest_version" diff --git a/scripts/version_patch.py b/scripts/read_patch_notes.py similarity index 100% rename from scripts/version_patch.py rename to scripts/read_patch_notes.py From fe306cbf58ae9bf8332ccdd9bfb35da8c672a3ac Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:32:44 -0400 Subject: [PATCH 31/81] gotta return only the version number --- scripts/read_patch_notes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/read_patch_notes.py b/scripts/read_patch_notes.py index c2a32a2..2744e42 100644 --- a/scripts/read_patch_notes.py +++ b/scripts/read_patch_notes.py @@ -38,4 +38,4 @@ def find_highest_version(file_name): # Test the function file_name = sys.argv[1] highest_version = find_highest_version(file_name) -print("Highest version number:", highest_version) +print(highest_version) From d92096c635760f8d4c4c084b1ec1c5165e2d615f Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:34:42 -0400 Subject: [PATCH 32/81] add some debugging --- scripts/patch.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/patch.sh b/scripts/patch.sh index c197390..928eaf4 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -247,6 +247,7 @@ else echo "Version number updated." else echo -e "\e[31mConfig patch file not found.\e[0m" + echo "Patch file: $config_patch" exit 1 fi fi @@ -273,6 +274,7 @@ else fi else echo -e "\e[31mProfile patch file not found.\e[0m" + echo "Patch file: $profile_patch" exit 1 fi fi From 099c963911ef7969114d7e3d3667c8a50d14aefb Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:35:34 -0400 Subject: [PATCH 33/81] found it! --- scripts/patch.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 928eaf4..4804dc1 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -221,8 +221,8 @@ else echo -e "\e[31mUser config and profile are out of date.\e[0m" # Search for patch files matching the user profile version echo "Searching for patch files..." - vars_patch=$home/$repo/profiles/$vars_profile/patches/$highest_version/vars.cfg - config_patch=$home/$repo/profiles/$config_profile/patches/$highest_version/config.cfg + vars_patch=$home/$repo/profiles/$vars_profile/patches/$highest_version/vars.patch + config_patch=$home/$repo/profiles/$config_profile/patches/$highest_version/config.patch if [ "$update_config" = "True" ]; then # Check if the patch file exists From a5c128b5df833811606f2b5d93629124f31dd8a2 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:38:54 -0400 Subject: [PATCH 34/81] more debugging --- scripts/patch.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/patch.sh b/scripts/patch.sh index 4804dc1..08e71b5 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -230,6 +230,8 @@ else echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying config patch file..." + echo "Patch file: $config_patch" + echo "User config: $user_config" cat $config_patch >> $user_config echo "Config patch file applied." # Update version number in user config From 0a7e105bf4f147a9e9c8a88f0155ce55e3939007 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:41:24 -0400 Subject: [PATCH 35/81] got it! --- scripts/patch.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 08e71b5..5ac286a 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -230,9 +230,7 @@ else echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying config patch file..." - echo "Patch file: $config_patch" - echo "User config: $user_config" - cat $config_patch >> $user_config + cat $config_patch >> $user_cfg echo "Config patch file applied." # Update version number in user config echo "Updating version number..." @@ -260,7 +258,7 @@ else echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying profile patch file..." - cat $profile_patch >> $user_profile + cat $profile_patch >> $user_vars echo "Profile patch file applied." # Update version number in user profile echo "Updating version number..." From 27871ce66dec494968d187cac65a70908f8df787 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:43:31 -0400 Subject: [PATCH 36/81] gotta use that path --- scripts/install.sh | 2 +- scripts/patch.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index f1b8144..136710c 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -269,7 +269,7 @@ then else echo "Adding printcfg config to $printer..." # Add printcfg config to beginning of file - python3 search_replace.py "$uconfig_pattern" "$uconfig_pattern" "$printer" + python3 $home/$repo/scripts/search_replace.py "$uconfig_pattern" "$uconfig_pattern" "$printer" fi # Verify moonraker is installed diff --git a/scripts/patch.sh b/scripts/patch.sh index 5ac286a..87836df 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -99,7 +99,7 @@ then then echo -e "\e[31mInclude line is out of date.\e[0m" # Replace old include line with new include line - python3 search_replace.py "$uconfig_pattern_old" "$uconfig_pattern_new" "$printer" + python3 $home/$repo/scripts/search_replace.py "$uconfig_pattern_old" "$uconfig_pattern_new" "$printer" # Verify include line was added if grep -qFx "$uconfig_pattern_new" "$printer" then @@ -235,7 +235,7 @@ else # Update version number in user config echo "Updating version number..." # Replace the version number using sed - python3 search_replace.py "$ver_patch" "$ver_patch$highest_version" "$user_cfg" + python3 $home/$repo/scripts/search_replace.py "$ver_patch" "$ver_patch$highest_version" "$user_cfg" # Verify that the version number has been updated if grep -qFx "$ver_patch$highest_version" "$user_cfg" then @@ -263,7 +263,7 @@ else # Update version number in user profile echo "Updating version number..." # Replace the version number using sed - python3 search_replace.py "$ver_patch" "$ver_patch$highest_version" "$user_vars" + python3 $home/$repo/scripts/search_replace.py "$ver_patch" "$ver_patch$highest_version" "$user_vars" # Verify that the version number has been updated if grep -qFx "$ver_patch$highest_version" "$user_vars" then From 43bc10c0a573509505aa5b2bcd10e5e7432fb162 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:46:24 -0400 Subject: [PATCH 37/81] had an extra space --- scripts/patch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 87836df..3f9d29f 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -59,7 +59,7 @@ profile_pattern="# Profile:(.*)" patch_pattern="# Patch:(.*)" uconfig_pattern_old="[include printcfg/user_config.cfg]" uconfig_pattern_new="[include user_config.cfg]" -ver_patch="# Patch: " +ver_patch="# Patch:" # Check if any parameters were provided if [ $# -eq 0 ] From 1584afa17b86d6cd0d1f9b2f1d299f226fe1c0da Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:51:22 -0400 Subject: [PATCH 38/81] add test patch for vars --- profiles/hephaestus/patches/3.9.0/vars.patch | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/profiles/hephaestus/patches/3.9.0/vars.patch b/profiles/hephaestus/patches/3.9.0/vars.patch index e69de29..086ca95 100644 --- a/profiles/hephaestus/patches/3.9.0/vars.patch +++ b/profiles/hephaestus/patches/3.9.0/vars.patch @@ -0,0 +1,4 @@ +[delayed_gcode _DEBUG_TEST] +initial_duration: 1 +gcode: + { action_respond_info("_DEBUG_TEST") } \ No newline at end of file From 0e463a41ada9df1a7e2228e4f65aa3fa23c76349 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:53:28 -0400 Subject: [PATCH 39/81] more debugging --- scripts/patch.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/patch.sh b/scripts/patch.sh index 3f9d29f..5e74224 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -258,6 +258,8 @@ else echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying profile patch file..." + echo "Patch file: $profile_patch" + echo "User vars: $user_vars" cat $profile_patch >> $user_vars echo "Profile patch file applied." # Update version number in user profile From 392e83dd8c9c1ff2c62664bff34165796419e0d9 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 13:55:10 -0400 Subject: [PATCH 40/81] ok this might fix it --- scripts/patch.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 5e74224..9286a56 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -254,13 +254,13 @@ else if [ "$update_profile" = "True" ]; then # Check if the patch file exists - if [ -f $profile_patch ]; then + if [ -f $vars_patch ]; then echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying profile patch file..." - echo "Patch file: $profile_patch" + echo "Patch file: $vars_patch" echo "User vars: $user_vars" - cat $profile_patch >> $user_vars + cat $vars_patch >> $user_vars echo "Profile patch file applied." # Update version number in user profile echo "Updating version number..." @@ -276,7 +276,7 @@ else fi else echo -e "\e[31mProfile patch file not found.\e[0m" - echo "Patch file: $profile_patch" + echo "Patch file: $vars_patch" exit 1 fi fi From cb6d7efb16f72d34cf4a06b44af89a5e4c7e631e Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 14:01:08 -0400 Subject: [PATCH 41/81] add a new line before inserting patched code --- scripts/patch.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 9286a56..ba99392 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -230,6 +230,7 @@ else echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying config patch file..." + cat "\n" >> $user_cfg cat $config_patch >> $user_cfg echo "Config patch file applied." # Update version number in user config @@ -258,8 +259,7 @@ else echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying profile patch file..." - echo "Patch file: $vars_patch" - echo "User vars: $user_vars" + cat "\n" >> $user_vars cat $vars_patch >> $user_vars echo "Profile patch file applied." # Update version number in user profile From 254abbe4d301faa08dd411bad57185546aa7874c Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 14:03:26 -0400 Subject: [PATCH 42/81] tweaks --- profiles/hephaestus/patches/3.9.0/vars.patch | 1 + scripts/patch.sh | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/profiles/hephaestus/patches/3.9.0/vars.patch b/profiles/hephaestus/patches/3.9.0/vars.patch index 086ca95..4c400da 100644 --- a/profiles/hephaestus/patches/3.9.0/vars.patch +++ b/profiles/hephaestus/patches/3.9.0/vars.patch @@ -1,3 +1,4 @@ + [delayed_gcode _DEBUG_TEST] initial_duration: 1 gcode: diff --git a/scripts/patch.sh b/scripts/patch.sh index ba99392..134a148 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -230,7 +230,6 @@ else echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying config patch file..." - cat "\n" >> $user_cfg cat $config_patch >> $user_cfg echo "Config patch file applied." # Update version number in user config @@ -259,7 +258,6 @@ else echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying profile patch file..." - cat "\n" >> $user_vars cat $vars_patch >> $user_vars echo "Profile patch file applied." # Update version number in user profile From 01ead6d3a5f25ad5273418e2263389d94bc13e78 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 14:04:47 -0400 Subject: [PATCH 43/81] remove debugging junk --- profiles/hephaestus/patches/3.9.0/vars.patch | 5 ----- 1 file changed, 5 deletions(-) diff --git a/profiles/hephaestus/patches/3.9.0/vars.patch b/profiles/hephaestus/patches/3.9.0/vars.patch index 4c400da..e69de29 100644 --- a/profiles/hephaestus/patches/3.9.0/vars.patch +++ b/profiles/hephaestus/patches/3.9.0/vars.patch @@ -1,5 +0,0 @@ - -[delayed_gcode _DEBUG_TEST] -initial_duration: 1 -gcode: - { action_respond_info("_DEBUG_TEST") } \ No newline at end of file From fe5130aaede543c1fba12a91e4eaa8be53757921 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 14:14:59 -0400 Subject: [PATCH 44/81] attempt to perform patching as part of setup --- scripts/patch.sh | 3 +-- scripts/setup.sh | 37 ++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/scripts/patch.sh b/scripts/patch.sh index 134a148..70b6e21 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -218,8 +218,7 @@ if [ "$update_config" = "False" ] && [ "$update_profile" = "False" ]; then echo -e "\e[32mNo action required.\e[0m" exit 0 else - echo -e "\e[31mUser config and profile are out of date.\e[0m" - # Search for patch files matching the user profile version + z # Search for patch files matching the user profile version echo "Searching for patch files..." vars_patch=$home/$repo/profiles/$vars_profile/patches/$highest_version/vars.patch config_patch=$home/$repo/profiles/$config_profile/patches/$highest_version/config.patch diff --git a/scripts/setup.sh b/scripts/setup.sh index cc05bcd..a77f375 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,18 +1,18 @@ #!/bin/bash # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) -# +# # This file is part of printcfg. -# +# # printcfg is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # printcfg is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with printcfg. If not, see . @@ -187,26 +187,29 @@ if [ "$user_vars_version" != "$src_vars_version" ]; then echo echo -e "\033[1;31mVersion mismatch: [$user_vars]\e[0m" echo - echo "To force an update, run setup.sh with the profile you want to use and the word 'force' as arguments." - echo "For example, to force an update for the default profile, run the following command:" - echo " $home/$repo/scripts/setup.sh default force" + echo "Attempting to patch user profile..." echo - echo -e "\033[4;31mNOTE: Forcing the update will overwrite any changes you have made to the user profile.\e[0m" - echo -e "\e[33mTo avoid this: please update the user profile manually following the patch notes.\e[0m" - echo - echo -e "\e[31mUser profile is not up to date.\e[0m" - echo "User version: $user_vars_version" - echo "Source version: $src_vars_version" - echo - echo -e "\e[31mPlease update the user profile.\e[0m" - if [ -f $src_path/patch_notes.txt ]; then echo -e "\e[31mPatch notes:" cat $src_path/patch_notes.txt echo -e "\e[0m" fi - echo -e "\033[2;101mSetup checks failed.\e[0m" echo + sh $home/$repo/scripts/patch.sh + #echo + #echo "If patching fails:" + #echo "To force an update, run setup.sh with the profile you want to use and the word 'force' as arguments." + #echo "For example, to force an update for the default profile, run the following command:" + #echo " $home/$repo/scripts/setup.sh default force" + #echo + #echo -e "\033[4;31mNOTE: Forcing the update will overwrite any changes you have made to the user profile.\e[0m" + #echo -e "\e[33mTo avoid this: please update the user profile manually following the patch notes.\e[0m" + #echo + #echo -e "\e[31mUser profile is not up to date.\e[0m" + #echo "User version: $user_vars_version" + #echo "Source version: $src_vars_version" + #echo + #echo -e "\e[31mPlease update the user profile.\e[0m" exit 1 fi else From 3fb294563ee5fea91e9dae2fc2c0f5bcd58dd94f Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 14:50:34 -0400 Subject: [PATCH 45/81] create user service to manage updates --- scripts/install.sh | 9 ++--- scripts/patch.sh | 1 + scripts/read_patch_notes.py | 4 +++ scripts/search_replace.py | 4 +++ scripts/setup.sh | 1 + src/mooncfg.conf | 4 +-- src/printcfg.py | 37 +++++++++++++++++++++ src/setup.py | 66 +++++++++++++++++++++++++++++++++++++ 8 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 src/printcfg.py create mode 100644 src/setup.py diff --git a/scripts/install.sh b/scripts/install.sh index 136710c..0557424 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,4 +1,5 @@ #!/bin/bash + # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) # # This file is part of Hephaestus. @@ -180,12 +181,12 @@ fi # Install the dependencies if [ -f requirements.txt ]; then - pip install -r requirements.txt + pip3 install -r requirements.txt fi -# Run the setup script -if [ -f setup.py ]; then - python setup.py install +# Install the python package +if [ -f $home/$repo/src/setup.py ]; then + python3 $home/$repo/src/setup.py --install fi # Make all scripts in printcfg executable diff --git a/scripts/patch.sh b/scripts/patch.sh index 70b6e21..dd2c41f 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -1,4 +1,5 @@ #!/bin/bash + # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) # # This file is part of printcfg. diff --git a/scripts/read_patch_notes.py b/scripts/read_patch_notes.py index 2744e42..bfc474e 100644 --- a/scripts/read_patch_notes.py +++ b/scripts/read_patch_notes.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) # # This file is part of printcfg. @@ -15,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with printcfg. If not, see . +#!/usr/bin/env python3 + import os import sys import re diff --git a/scripts/search_replace.py b/scripts/search_replace.py index 83d5a3f..bfa092f 100644 --- a/scripts/search_replace.py +++ b/scripts/search_replace.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) # # This file is part of printcfg. @@ -15,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with printcfg. If not, see . +#!/usr/bin/env python3 + import os import sys diff --git a/scripts/setup.sh b/scripts/setup.sh index a77f375..0f3e0a7 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,4 +1,5 @@ #!/bin/bash + # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) # # This file is part of printcfg. diff --git a/src/mooncfg.conf b/src/mooncfg.conf index 473a153..d4e1f9f 100644 --- a/src/mooncfg.conf +++ b/src/mooncfg.conf @@ -10,8 +10,8 @@ channel: dev primary_branch: dev path: ~/printcfg origin: https://github.com/rootiest/printcfg.git -is_system_service: False +is_system_service: True install_script: scripts/install.sh -managed_services: klipper +managed_services: printcfg klipper info_tags: desc=Rootiest printcfg Suite for Klipper \ No newline at end of file diff --git a/src/printcfg.py b/src/printcfg.py new file mode 100644 index 0000000..bf974c4 --- /dev/null +++ b/src/printcfg.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +# +# This file is part of printcfg. +# +# printcfg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# printcfg is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printcfg. If not, see . + +#!/usr/bin/env python3 + +import subprocess +import os + +# Path to the shell script +SHELL_SCRIPT = "/home/pi/printcfg/scripts/setup.sh" + +# Run the shell script at startup +subprocess.Popen(["/bin/bash", SHELL_SCRIPT]) + +# Continuously run in the background +while True: + # Do any other tasks or operations here + # You can add your code logic within this loop + + # Sleep for a certain duration (e.g., 1 second) + os.system("sleep 1") diff --git a/src/setup.py b/src/setup.py new file mode 100644 index 0000000..b09e28f --- /dev/null +++ b/src/setup.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +# +# This file is part of printcfg. +# +# printcfg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# printcfg is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printcfg. If not, see . + +#!/usr/bin/env python3 +import os +import sys + +# Service name and configuration file +SERVICE_NAME = "printcfg" +SERVICE_FILE = f"{os.path.expanduser('~')}/.config/systemd/user/{SERVICE_NAME}.service" +SERVICE_PATH = f"{os.path.expanduser('~')}/{SERVICE_NAME}/src" + +# Path to the Python script +PYTHON_SCRIPT = "{SERVICE_PATH}/{SERVICE_NAME}.py" +PYTHON_EXECUTABLE = sys.executable + +if sys.argv[1] == "--install": + if not PYTHON_SCRIPT: + print("Please provide the path to the Python script as an argument.") + sys.exit(1) + + # Create the service file + service_content = f"""\ + [Unit] + Description=Print Configuration Service + + [Service] + ExecStart={PYTHON_EXECUTABLE} {PYTHON_SCRIPT} + WorkingDirectory={os.path.dirname(PYTHON_SCRIPT)} + + [Install] + WantedBy=default.target + """ + + os.makedirs(os.path.dirname(SERVICE_FILE), exist_ok=True) + with open(SERVICE_FILE, "w") as service: + service.write(service_content) + + # Reload user systemd to recognize the new service + os.system("systemctl --user daemon-reload") + + # Enable and start the service + os.system(f"systemctl --user enable {SERVICE_NAME}") + os.system(f"systemctl --user start {SERVICE_NAME}") + + # Check the status of the service + os.system(f"systemctl --user status {SERVICE_NAME}") +else: + print("Please provide the --install argument to install the service.") + From e621ca296b0ca54303b36651d57e6d30645fbf1d Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 14:56:02 -0400 Subject: [PATCH 46/81] add service setup to install script --- scripts/install.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 0557424..bef10b1 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -184,9 +184,15 @@ if [ -f requirements.txt ]; then pip3 install -r requirements.txt fi -# Install the python package -if [ -f $home/$repo/src/setup.py ]; then - python3 $home/$repo/src/setup.py --install +# Check if the service is enabled +if systemctl is-enabled "${repo}" >/dev/null 2>&1; then + echo "The ${repo} service is enabled." +else + echo "Installing the ${repo} service..." + # Install the python package + if [ -f $home/$repo/src/setup.py ]; then + python3 $home/$repo/src/setup.py --install + fi fi # Make all scripts in printcfg executable From 867b682de8d8d5b692a61bb8ba90d61912320d50 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 15:01:08 -0400 Subject: [PATCH 47/81] fix for path --- src/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup.py b/src/setup.py index b09e28f..13b6703 100644 --- a/src/setup.py +++ b/src/setup.py @@ -42,7 +42,7 @@ [Service] ExecStart={PYTHON_EXECUTABLE} {PYTHON_SCRIPT} - WorkingDirectory={os.path.dirname(PYTHON_SCRIPT)} + WorkingDirectory={os.path.dirname(SERVICE_PATH)} [Install] WantedBy=default.target From 8c92337ddd2f66e1d8b91b4c7e536a961a174b38 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 15:04:05 -0400 Subject: [PATCH 48/81] give more feedback --- scripts/install.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/install.sh b/scripts/install.sh index bef10b1..c16f228 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -180,11 +180,17 @@ fi ### Run any setup scripts ### # Install the dependencies +echo "Installing dependencies..." if [ -f requirements.txt ]; then pip3 install -r requirements.txt + echo -e "\e[32mDependencies installed successfully.\e[0m" +else + echo -e "\e[33mNo dependencies to install.\e[0m" +fi fi # Check if the service is enabled +echo "Checking if the ${repo} service is enabled..." if systemctl is-enabled "${repo}" >/dev/null 2>&1; then echo "The ${repo} service is enabled." else @@ -192,6 +198,7 @@ else # Install the python package if [ -f $home/$repo/src/setup.py ]; then python3 $home/$repo/src/setup.py --install + echo -e "\e[32m${repo} service installed successfully.\e[0m" fi fi From 062bcf27f15f2d37680b71b1f06fd1ca1fd6597a Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 15:06:56 -0400 Subject: [PATCH 49/81] extra fi in there --- scripts/install.sh | 1 - src/setup.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index c16f228..55ac774 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -187,7 +187,6 @@ if [ -f requirements.txt ]; then else echo -e "\e[33mNo dependencies to install.\e[0m" fi -fi # Check if the service is enabled echo "Checking if the ${repo} service is enabled..." diff --git a/src/setup.py b/src/setup.py index 13b6703..4db9d23 100644 --- a/src/setup.py +++ b/src/setup.py @@ -27,7 +27,7 @@ SERVICE_PATH = f"{os.path.expanduser('~')}/{SERVICE_NAME}/src" # Path to the Python script -PYTHON_SCRIPT = "{SERVICE_PATH}/{SERVICE_NAME}.py" +PYTHON_SCRIPT = f"{SERVICE_PATH}/{SERVICE_NAME}.py" PYTHON_EXECUTABLE = sys.executable if sys.argv[1] == "--install": From 9863e0658c6533b18688ddc849a78585854e729a Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 15:09:03 -0400 Subject: [PATCH 50/81] make sure we are referring to a user service --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 55ac774..46a1e62 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -190,7 +190,7 @@ fi # Check if the service is enabled echo "Checking if the ${repo} service is enabled..." -if systemctl is-enabled "${repo}" >/dev/null 2>&1; then +if systemctl --user is-enabled "${repo}" >/dev/null 2>&1; then echo "The ${repo} service is enabled." else echo "Installing the ${repo} service..." From d1140789e3b6624eb7e752685cc89a8f1fada9aa Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 15:18:36 -0400 Subject: [PATCH 51/81] make sure moonraker can control printcfg --- scripts/install.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/install.sh b/scripts/install.sh index 46a1e62..fd8328e 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -323,6 +323,27 @@ else python3 $home/$repo/scripts/search_replace.py "$moon_pattern" "$new_moon" "$moonraker" fi +# Add printcfg to moonraker.asvc +echo "Adding printcfg service to moonraker allowlist..." +# Define allowlist file +allowlist="$config/moonraker.asvc" +# Verify printcfg is in allowlist +if grep -qFx "$repo" "$allowlist" +then + echo -e "\e[33mprintcfg service already in allowlist.\e[0m" +else + echo "Adding printcfg service to moonraker allowlist..." + # Add printcfg service to moonraker allowlist + echo "$repo" >> $allowlist + if grep -qFx "$repo" "$allowlist" + then + echo -e "\e[32mprintcfg service added to allowlist successfully.\e[0m" + else + echo -e "\e[31mError: printcfg service not added to allowlist.\e[0m" + exit 1 + fi +fi + echo -e "\e[32mInstall complete.\e[0m" echo From 936306d636b62cb2d084ad726ff5c3ade964b709 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 15:23:55 -0400 Subject: [PATCH 52/81] wrong file for allowlist --- scripts/install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index fd8328e..2671688 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -49,8 +49,9 @@ repo="printcfg" branch="master" # Get home directory home=$(eval echo ~$USER) -# Define the klipper config file -config=$home/printer_data/config +# Define the klipper config paths +printer_data=$home/printer_data +config=$printer_data/config # Define the printer.cfg and moonraker.conf files printer=$config/printer.cfg moonraker=$config/moonraker.conf @@ -326,7 +327,7 @@ fi # Add printcfg to moonraker.asvc echo "Adding printcfg service to moonraker allowlist..." # Define allowlist file -allowlist="$config/moonraker.asvc" +allowlist="$printer_data/moonraker.asvc" # Verify printcfg is in allowlist if grep -qFx "$repo" "$allowlist" then From e975d3c0e48007701bb5478db838b64add598b37 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 15:28:31 -0400 Subject: [PATCH 53/81] make use of variables --- scripts/install.sh | 60 +++++++++++++++++++++++----------------------- scripts/patch.sh | 2 +- scripts/setup.sh | 4 ++-- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 2671688..673977d 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -76,8 +76,8 @@ else fi # Welcome message -echo "Welcome to the printcfg install script." -echo "This script will download and install the printcfg package from GitHub." +echo "Welcome to the $repo install script." +echo "This script will download and install the $repo package from GitHub." echo echo "Checking dependencies..." @@ -103,7 +103,7 @@ if [ -n "$need_git" ] || [ -n "$need_pip" ] || [ -n "$need_bc" ]; then else echo -e "\e[32mAll dependencies are installed.\e[0m" fi -echo "Installing printcfg..." +echo "Installing $repo..." # Check if the repo exists if ! git ls-remote https://github.com/"$dev"/"$repo" >/dev/null; then @@ -117,14 +117,14 @@ cd $home # Check if printcfg is already installed if [ -d $home/$repo ]; then - echo -e "\e[33mprintcfg repo is already installed.\e[0m" - echo "Updating printcfg repo..." + echo -e "\e[33m$repo repo is already installed.\e[0m" + echo "Updating $repo repo..." # Change to the repo directory cd $home/$repo # Pull the latest changes git pull else - echo "Installing printcfg repo..." + echo "Installing $repo repo..." # Clone the repo git clone https://github.com/"$dev"/"$repo" # Check if the repo was cloned @@ -263,8 +263,8 @@ fi if [ ! -L $config/$repo ] then # Link printcfg to the printer config directory - echo "Linking printcfg to the printer config directory..." - ln -s $home/$repo $config/printcfg + echo "Linking $repo to the printer config directory..." + ln -s $home/$repo $config/$repo # Check if the link was created if [ ! -L $config/$repo ] then @@ -272,16 +272,16 @@ then exit 1 fi else - echo -e "\e[33mprintcfg symlink already exists.\e[0m" + echo -e "\e[33m$repo symlink already exists.\e[0m" fi # Check if include line exists in printer.cfg uconfig_pattern="[include user_config.cfg]" if grep -qFx "$uconfig_pattern" "$printer" then - echo -e "\e[33mprintcfg config already included.\e[0m" + echo -e "\e[33m$repo config already included.\e[0m" else - echo "Adding printcfg config to $printer..." + echo "Adding $repo config to $printer..." # Add printcfg config to beginning of file python3 $home/$repo/scripts/search_replace.py "$uconfig_pattern" "$uconfig_pattern" "$printer" fi @@ -295,11 +295,11 @@ then fi # Check if the moonraker-printcfg.conf file exists -if [ ! -f $config/moonraker-printcfg.conf ] +if [ ! -f $config/moonraker-$repo.conf ] then # Copy moonraker config to config directory echo "Creating moonraker config in config directory..." - cp -r $home/$repo/src/mooncfg.conf $config/moonraker-printcfg.conf + cp -r $home/$repo/src/mooncfg.conf $config/moonraker-$repo.conf else echo -e "\e[32mMoonraker config already exists.\e[0m" fi @@ -309,38 +309,38 @@ echo "Setting branch in moonraker config..." # Define search pattern branch_pattern="primary_branch:" # Set branch to current branch -python3 $home/$repo/scripts/search_replace.py "$branch_pattern" "$branch_pattern $branch" "$config/moonraker-printcfg.conf" +python3 $home/$repo/scripts/search_replace.py "$branch_pattern" "$branch_pattern $branch" "$config/moonraker-$repo.conf" # Check if the moonraker config already contains the old printcfg config -moon_pattern="[include printcfg/moonraker-printcfg.conf]" -new_moon="[include moonraker-printcfg.conf]" +moon_pattern="[include $repo/moonraker-$repo.conf]" +new_moon="[include moonraker-$repo.conf]" if grep -qFx "$new_moon" "$moonraker" then - echo -e "\e[33mprintcfg moonraker already included.\e[0m" + echo -e "\e[33m$repo moonraker already included.\e[0m" else - echo "Adding printcfg config to $moonraker..." + echo "Adding $repo config to $moonraker..." # Add printcfg config to moonraker python3 $home/$repo/scripts/search_replace.py "$moon_pattern" "$new_moon" "$moonraker" fi # Add printcfg to moonraker.asvc -echo "Adding printcfg service to moonraker allowlist..." +echo "Checking for $repo service in moonraker allowlist..." # Define allowlist file allowlist="$printer_data/moonraker.asvc" # Verify printcfg is in allowlist if grep -qFx "$repo" "$allowlist" then - echo -e "\e[33mprintcfg service already in allowlist.\e[0m" + echo -e "\e[33m$repo service already in allowlist.\e[0m" else - echo "Adding printcfg service to moonraker allowlist..." + echo "Adding $repo service to moonraker allowlist..." # Add printcfg service to moonraker allowlist echo "$repo" >> $allowlist if grep -qFx "$repo" "$allowlist" then - echo -e "\e[32mprintcfg service added to allowlist successfully.\e[0m" + echo -e "\e[32m$repo service added to allowlist successfully.\e[0m" else - echo -e "\e[31mError: printcfg service not added to allowlist.\e[0m" + echo -e "\e[31mError: $repo service not added to allowlist.\e[0m" exit 1 fi fi @@ -349,7 +349,7 @@ echo -e "\e[32mInstall complete.\e[0m" echo # Perform all checks to make sure printcfg is installed correctly -echo "Checking printcfg installation..." +echo "Checking $repo installation..." # Check if the repo exists if [ ! -d $home/$repo ]; then @@ -376,40 +376,40 @@ fi # Check if printcfg is included in the printer.cfg file if ! grep -qFx "$uconfig_pattern" "$printer" then - echo -e "\e[31mError: printcfg config not included in $printer\e[0m" + echo -e "\e[31mError: $repo config not included in $printer\e[0m" exit 1 fi # Check if the moonraker config contains printcfg config if ! grep -qFx "$new_moon" "$moonraker" then - echo -e "\e[31mError: printcfg config not included in $moonraker\e[0m" + echo -e "\e[31mError: $repo config not included in $moonraker\e[0m" exit 1 fi # Check if printcfg symlink exists if [ ! -L $config/$repo ] then - echo -e "\e[31mError: printcfg symlink not created.\e[0m" + echo -e "\e[31mError: $repo symlink not created.\e[0m" exit 1 fi # Check if user config exists if [ ! -f $config/user_config.cfg ] then - echo -e "\e[31mError: printcfg user config not found.\e[0m" + echo -e "\e[31mError: $repo user config not found.\e[0m" exit 1 fi # Check if user profile exists if [ ! -f $config/user_profile.cfg ] then - echo -e "\e[31mError: printcfg user profile not found.\e[0m" + echo -e "\e[31mError: $repo user profile not found.\e[0m" exit 1 fi # Acknowledge that the installation checks passed -echo -e "\e[32mprintcfg installation checks passed.\e[0m" +echo -e "\e[32m$repo installation checks passed.\e[0m" echo # Success! diff --git a/scripts/patch.sh b/scripts/patch.sh index dd2c41f..13985fe 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -58,7 +58,7 @@ old_user_cfg=$config/$repo/user_config.cfg # Patterns to identify profile name and version profile_pattern="# Profile:(.*)" patch_pattern="# Patch:(.*)" -uconfig_pattern_old="[include printcfg/user_config.cfg]" +uconfig_pattern_old="[include $repo/user_config.cfg]" uconfig_pattern_new="[include user_config.cfg]" ver_patch="# Patch:" diff --git a/scripts/setup.sh b/scripts/setup.sh index 0f3e0a7..44315e0 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -91,11 +91,11 @@ then fi # Check if old include line exists in printer.cfg echo "Checking printer.cfg include line..." - if grep -qFx "[include printcfg/user_config.cfg]" "$printer" + if grep -qFx "[include $repo/user_config.cfg]" "$printer" then echo -e "\e[31mInclude line is out of date.\e[0m" # Remove old include line - sed -i '/\[include printcfg\/user_config.cfg\]/d' "$printer" + sed -i '/\[include $repo\/user_config.cfg\]/d' "$printer" # Add new include line sed -i '1s/^/[include user_config.cfg]\n/' "$printer" # Verify include line was added From 33255bd924a26d8e032167caac7ece6d2c634082 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 23 May 2023 15:29:31 -0400 Subject: [PATCH 54/81] don't change peromissions and break repo --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 673977d..1f52558 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -203,7 +203,7 @@ else fi # Make all scripts in printcfg executable -chmod +x $home/$repo/scripts/*.sh +#chmod +x $home/$repo/scripts/*.sh ### Install into klippers config ### From d9558ad84e9b61ccb45d512ac5005949ec6f0ce5 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 25 May 2023 13:53:13 -0400 Subject: [PATCH 55/81] Add M500/M501 to save/restore state Add P500/P501 to save/restore absolute/relative --- print_macros.cfg | 107 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/print_macros.cfg b/print_macros.cfg index 1290b32..c33a8c3 100644 --- a/print_macros.cfg +++ b/print_macros.cfg @@ -222,6 +222,7 @@ gcode: {% if printcfg.clean_probe == True %} ; if cleaning before probing {printcfg.clean_macro} ; clean nozzle {% endif %} + M400 ; ## Z-tilt or QGL {% if printcfg.z_tilt == True %} ; if using z-tilt {% if config.z_tilt is defined %} ; if z-tilt is configured @@ -1472,6 +1473,112 @@ gcode: #M{printcfg.output|int} Disabling filament sensor SET_FILAMENT_SENSOR SENSOR={SENSOR} ENABLE=0 +################################ +##### STORE_POSITION_MODE ###### +################################ +## These macros will: +## P500: Store the current position mode (absolute or relative) and extrusion mode (absolute or relative) in a variable. +## P501: Restore the position mode and extrusion mode from the variable. +## Example usage: +## # Store last position mode +## P500 +## # Change to relative position mode +## G91 +## # Restore last position mode +## P501 + +## Store last position mode +[gcode_macro P500] +variable_last_coords: 91 +vairable_last_extrude: 83 +description: Store last position mode +gcode: + ## Store last position mode + {% if printer.gcode_move.absolute_coordinates == True %} + {% set last_coords = 90 %} + {% else %} + {% set last_coords = 91 %} + {% endif %} + {% if printer.gcode_move.absolute_extrusion == True %} + {% set last_extrude = 82 %} + {% else %} + {% set last_extrude = 83 %} + {% endif %} + SET_GCODE_VARIABLE MACRO=P500 VARIABLE=last_coords VALUE={last_coords} + SET_GCODE_VARIABLE MACRO=P500 VARIABLE=last_extrude VALUE={last_extrude} + +## Restore last position mode +[gcode_macro P501] +description: Restore last position mode +gcode: + # Get stored values + {% set last_coords = printer['gcode_macro P500'].variable_last_coords %} + {% set last_extrude = printer['gcode_macro P500'].variable_last_extrude %} + ## Get current values + {% if printer.gcode_move.absolute_coordinates == True %} + {% set coords = 90 %} + {% else %} + {% set coords = 91 %} + {% endif %} + {% if printer.gcode_move.absolute_extrusion == True %} + {% set extrude = 82 %} + {% else %} + {% set extrude = 83 %} + {% endif %} + ## Restore last position mode + {% if coords != last_coords %} + {% if coords == 90 %} + G90 + {% else %} + G91 + {% endif %} + {% endif %} + {% if extrude != last_extrude %} + {% if extrude == 82 %} + M82 + {% else %} + M83 + {% endif %} + {% endif %} + +################################ +###### SAVE/RESTORE STATE ###### +################################ +## These macros will: +## M500: Save the current state of the printer (position, extrusion, feedrate, etc.) in a variable. +## M501: Restore the state of the printer from the variable. +## Example usage: +## # Save current state +## M500 +## # Change to relative position mode +## G91 +## # MOVE X 10 +## G1 X10 +## # Restore last state +## M501 + +## Save current state +[gcode_macro M500] +description: Save current state +gcode: + ## Save the current state + SAVE_GCODE_STATE NAME=M500 + +## Restore last state +[gcode_macro M501] +description: Restore last state +gcode: + ## Check for speed parameter + {% if params.SPEED is defined %} + {% set speed = params.SPEED|default(1000)|int %} + ## Restore the last state + RESTORE_GCODE_STATE NAME=M500 MOVE=1 SPEED={speed} + {% else %} + ## Restore the last state + RESTORE_GCODE_STATE NAME=M500 MOVE=1 + {% endif %} + + ################################ ########### LAYERS ############# ################################ From baf447ae46cf8b18ff2c18dc5ee346e6b9521d1b Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 25 May 2023 13:57:50 -0400 Subject: [PATCH 56/81] ok then --- print_macros.cfg | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/print_macros.cfg b/print_macros.cfg index c33a8c3..ed6dbb4 100644 --- a/print_macros.cfg +++ b/print_macros.cfg @@ -1487,10 +1487,13 @@ gcode: ## # Restore last position mode ## P501 -## Store last position mode -[gcode_macro P500] +## Stores the current position mode and extrusion mode in a variable. +[gcode_macro _position_mode] variable_last_coords: 91 vairable_last_extrude: 83 +gcode: ; No Gcode +## Store last position mode +[gcode_macro P500] description: Store last position mode gcode: ## Store last position mode @@ -1504,16 +1507,16 @@ gcode: {% else %} {% set last_extrude = 83 %} {% endif %} - SET_GCODE_VARIABLE MACRO=P500 VARIABLE=last_coords VALUE={last_coords} - SET_GCODE_VARIABLE MACRO=P500 VARIABLE=last_extrude VALUE={last_extrude} + SET_GCODE_VARIABLE MACRO=_position_mode VARIABLE=last_coords VALUE={last_coords} + SET_GCODE_VARIABLE MACRO=_position_mode VARIABLE=last_extrude VALUE={last_extrude} ## Restore last position mode [gcode_macro P501] description: Restore last position mode gcode: # Get stored values - {% set last_coords = printer['gcode_macro P500'].variable_last_coords %} - {% set last_extrude = printer['gcode_macro P500'].variable_last_extrude %} + {% set last_coords = printer['gcode_macro _position_mode'].variable_last_coords %} + {% set last_extrude = printer['gcode_macro _position_mode'].variable_last_extrude %} ## Get current values {% if printer.gcode_move.absolute_coordinates == True %} {% set coords = 90 %} From 78833405c9c286298f5df77034673d872eae8887 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 25 May 2023 14:06:53 -0400 Subject: [PATCH 57/81] typo --- print_macros.cfg | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/print_macros.cfg b/print_macros.cfg index ed6dbb4..875a508 100644 --- a/print_macros.cfg +++ b/print_macros.cfg @@ -1487,13 +1487,10 @@ gcode: ## # Restore last position mode ## P501 -## Stores the current position mode and extrusion mode in a variable. -[gcode_macro _position_mode] -variable_last_coords: 91 -vairable_last_extrude: 83 -gcode: ; No Gcode ## Store last position mode [gcode_macro P500] +variable_last_coords: 91 +variable_last_extrude: 83 description: Store last position mode gcode: ## Store last position mode @@ -1507,16 +1504,16 @@ gcode: {% else %} {% set last_extrude = 83 %} {% endif %} - SET_GCODE_VARIABLE MACRO=_position_mode VARIABLE=last_coords VALUE={last_coords} - SET_GCODE_VARIABLE MACRO=_position_mode VARIABLE=last_extrude VALUE={last_extrude} + SET_GCODE_VARIABLE MACRO=P500 VARIABLE=last_coords VALUE={last_coords} + SET_GCODE_VARIABLE MACRO=P500 VARIABLE=last_extrude VALUE={last_extrude} ## Restore last position mode [gcode_macro P501] description: Restore last position mode gcode: # Get stored values - {% set last_coords = printer['gcode_macro _position_mode'].variable_last_coords %} - {% set last_extrude = printer['gcode_macro _position_mode'].variable_last_extrude %} + {% set last_coords = printer['gcode_macro P500'].variable_last_coords %} + {% set last_extrude = printer['gcode_macro P500'].variable_last_extrude %} ## Get current values {% if printer.gcode_move.absolute_coordinates == True %} {% set coords = 90 %} From ab5130529b7207626c14d56b93a3b34f562e325a Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 04:43:36 -0400 Subject: [PATCH 58/81] some fixes to sevice generation and operation --- src/gen_service.py | 107 +++++++++++++++++++++++++++++++++++++++++++++ src/setup.py | 72 +++++++++++------------------- 2 files changed, 132 insertions(+), 47 deletions(-) create mode 100644 src/gen_service.py diff --git a/src/gen_service.py b/src/gen_service.py new file mode 100644 index 0000000..493255f --- /dev/null +++ b/src/gen_service.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +# +# This file is part of printcfg. +# +# printcfg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# printcfg is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printcfg. If not, see . + +#!/usr/bin/env python3 +import os +import sys +import subprocess + +if len(sys.argv) < 3: + USER = os.environ["USER"] + GROUP = os.environ["USER"] + HOME= os.path.expanduser('~') +else: + USER = sys.argv[1] + GROUP = sys.argv[1] + HOME = sys.argv[2] + +# Service name and configuration file +SERVICE_NAME = "printcfg" +SERVICE_FILE = f"/etc/systemd/system/{SERVICE_NAME}.service" +SERVICE_PATH = f"{HOME}/{SERVICE_NAME}" + +# Path to the Python script +PYTHON_SCRIPT = f"{SERVICE_PATH}/src/{SERVICE_NAME}.py" +PYTHON_EXECUTABLE = sys.executable + +# Prompt for sudo password +#def prompt_sudo(): +# ret = 0 +# if os.geteuid() != 0: +# msg = "[sudo] password for %u:" +# ret = subprocess.check_call("sudo -v -p '%s'" % msg, shell=True) +# return ret + +if len(sys.argv) < 2 and len(sys.argv) > 0: + MODE = sys.argv[1] +elif len(sys.argv) < 0: + print("Please provide the --install argument to install the service.") +else: + if sys.argv[3] == "--install": + if not PYTHON_SCRIPT: + print("Please provide the path to the Python script as an argument.") + sys.exit(1) + + # Create the service file + service_content = f"""\ + [Unit] + Description=Print Configuration Service + Requires=klipper.service + After=klipper.service + + [Service] + User={USER} + Group={GROUP} + RemainAfterExit=yes + ExecStart={PYTHON_EXECUTABLE} {PYTHON_SCRIPT} + WorkingDirectory={os.path.dirname(SERVICE_PATH)} + TimeoutStartSec=0 + + [Install] + WantedBy=default.target + """ + + print("Installing service...") + print(f"Service file: {SERVICE_FILE}") + print(f"Python script: {PYTHON_SCRIPT}") + print(f"Python executable: {PYTHON_EXECUTABLE}") + print(f"Working directory: {os.path.dirname(SERVICE_PATH)}") + + os.makedirs(os.path.dirname(SERVICE_FILE), exist_ok=True) + with open(SERVICE_FILE, "w") as service: + service.write(service_content) + + # Set the appropriate permissions for the service configuration file + os.chmod(SERVICE_FILE, 0o644) + + # Switch to the root user + + + # Reload systemd to recognize the new service + os.system("systemctl daemon-reload") + + # Enable and start the service + os.system(f"systemctl enable {SERVICE_NAME}") + os.system(f"systemctl start {SERVICE_NAME}") + + # Check the status of the service + os.system(f"systemctl status {SERVICE_NAME}") + else: + print("Please provide the --install argument to install the service.") + sys.exit(1) \ No newline at end of file diff --git a/src/setup.py b/src/setup.py index 4db9d23..e53dd2f 100644 --- a/src/setup.py +++ b/src/setup.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 - # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) # # This file is part of printcfg. @@ -17,50 +15,30 @@ # You should have received a copy of the GNU General Public License # along with printcfg. If not, see . -#!/usr/bin/env python3 import os import sys - -# Service name and configuration file -SERVICE_NAME = "printcfg" -SERVICE_FILE = f"{os.path.expanduser('~')}/.config/systemd/user/{SERVICE_NAME}.service" -SERVICE_PATH = f"{os.path.expanduser('~')}/{SERVICE_NAME}/src" - -# Path to the Python script -PYTHON_SCRIPT = f"{SERVICE_PATH}/{SERVICE_NAME}.py" -PYTHON_EXECUTABLE = sys.executable - -if sys.argv[1] == "--install": - if not PYTHON_SCRIPT: - print("Please provide the path to the Python script as an argument.") - sys.exit(1) - - # Create the service file - service_content = f"""\ - [Unit] - Description=Print Configuration Service - - [Service] - ExecStart={PYTHON_EXECUTABLE} {PYTHON_SCRIPT} - WorkingDirectory={os.path.dirname(SERVICE_PATH)} - - [Install] - WantedBy=default.target - """ - - os.makedirs(os.path.dirname(SERVICE_FILE), exist_ok=True) - with open(SERVICE_FILE, "w") as service: - service.write(service_content) - - # Reload user systemd to recognize the new service - os.system("systemctl --user daemon-reload") - - # Enable and start the service - os.system(f"systemctl --user enable {SERVICE_NAME}") - os.system(f"systemctl --user start {SERVICE_NAME}") - - # Check the status of the service - os.system(f"systemctl --user status {SERVICE_NAME}") -else: - print("Please provide the --install argument to install the service.") - +import getpass +import subprocess + +def start_script_as_root(): + # Get the current user name + current_user = getpass.getuser() + user_home = os.path.expanduser('~') + my_path = os.path.dirname(os.path.realpath(__file__)) + script_dir = os.path.dirname(my_path) + mode = sys.argv[1] + + # Define the path to the second script + script_path = f'{script_dir}/src/gen_service.py' + + # Check if the second script exists + if not os.path.isfile(script_path): + print(f"Error: The script '{script_path}' does not exist.") + return + + # Start the second script as root with the current user name as the first argument + command = ['sudo', 'python3', script_path, current_user, user_home, mode] + subprocess.run(command) + +if __name__ == '__main__': + start_script_as_root() \ No newline at end of file From fe9d707e2e5b9060ddef7d3d35804229bf879388 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 04:51:03 -0400 Subject: [PATCH 59/81] Add some documentation to python scripts --- scripts/read_patch_notes.py | 2 ++ scripts/search_replace.py | 2 ++ src/gen_service.py | 10 ++-------- src/printcfg.py | 2 ++ src/setup.py | 2 ++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/read_patch_notes.py b/scripts/read_patch_notes.py index bfc474e..d5a3b30 100644 --- a/scripts/read_patch_notes.py +++ b/scripts/read_patch_notes.py @@ -19,6 +19,8 @@ #!/usr/bin/env python3 +# This script reads the patch notes file and returns the highest version number. + import os import sys import re diff --git a/scripts/search_replace.py b/scripts/search_replace.py index bfa092f..9af8abc 100644 --- a/scripts/search_replace.py +++ b/scripts/search_replace.py @@ -19,6 +19,8 @@ #!/usr/bin/env python3 +# This script searches for a line containing a specific text and replaces the whole line with a new text. + import os import sys diff --git a/src/gen_service.py b/src/gen_service.py index 493255f..6f7b5bd 100644 --- a/src/gen_service.py +++ b/src/gen_service.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU General Public License # along with printcfg. If not, see . +# This script generates a service file for printcfg. + #!/usr/bin/env python3 import os import sys @@ -40,14 +42,6 @@ PYTHON_SCRIPT = f"{SERVICE_PATH}/src/{SERVICE_NAME}.py" PYTHON_EXECUTABLE = sys.executable -# Prompt for sudo password -#def prompt_sudo(): -# ret = 0 -# if os.geteuid() != 0: -# msg = "[sudo] password for %u:" -# ret = subprocess.check_call("sudo -v -p '%s'" % msg, shell=True) -# return ret - if len(sys.argv) < 2 and len(sys.argv) > 0: MODE = sys.argv[1] elif len(sys.argv) < 0: diff --git a/src/printcfg.py b/src/printcfg.py index bf974c4..66f52aa 100644 --- a/src/printcfg.py +++ b/src/printcfg.py @@ -19,6 +19,8 @@ #!/usr/bin/env python3 +# This is the printcfg service. + import subprocess import os diff --git a/src/setup.py b/src/setup.py index e53dd2f..4a9e4c5 100644 --- a/src/setup.py +++ b/src/setup.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with printcfg. If not, see . +# This script collects some data and then triggers the service generator. + import os import sys import getpass From a00e3a19d66183e85f3736ff8e19063f92b24024 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 06:52:25 -0400 Subject: [PATCH 60/81] some tweaks --- scripts/install.sh | 7 +++++-- scripts/setup.sh | 40 +++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 1f52558..1659794 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -191,10 +191,13 @@ fi # Check if the service is enabled echo "Checking if the ${repo} service is enabled..." -if systemctl --user is-enabled "${repo}" >/dev/null 2>&1; then +if systemctl is-enabled "${repo}" >/dev/null 2>&1; then echo "The ${repo} service is enabled." else echo "Installing the ${repo} service..." + echo "Acquiring root privileges..." + # Acquire root privileges + sudo -v Date: Fri, 26 May 2023 06:54:14 -0400 Subject: [PATCH 61/81] ugh what did i do --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 1659794..763907f 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -424,7 +424,7 @@ echo echo "Performing Setup Checks..." echo -sh "$home/$repo/scripts/setup.sh --$src" +bash $home/$repo/scripts/setup.sh $src echo -e "\e[32mSetup checks passed.\e[0m" From 634e9d698524f8a7969af27692f38fb27403faa9 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 09:57:17 -0400 Subject: [PATCH 62/81] incorporate change_profile and remove_printcfg These can be executed manually using their respective scripts or using setup.py --- scripts/change_profile.sh | 336 +++++++++++++++++++++++++++++++++++++ scripts/remove_printcfg.sh | 119 +++++++++++++ scripts/search_replace.py | 3 + src/mooncfg.conf | 2 +- src/setup.py | 78 ++++++++- 5 files changed, 533 insertions(+), 5 deletions(-) create mode 100644 scripts/change_profile.sh create mode 100644 scripts/remove_printcfg.sh diff --git a/scripts/change_profile.sh b/scripts/change_profile.sh new file mode 100644 index 0000000..63bf273 --- /dev/null +++ b/scripts/change_profile.sh @@ -0,0 +1,336 @@ +#!/bin/bash + +# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +# +# This file is part of printcfg. +# +# printcfg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# printcfg is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printcfg. If not, see . + +##################################### +## Printcfg Profile Change ## +## Version 3.9.0 2023-5-22 ## +##################################### + +# This script will change the user profile to the specified profile. +# Arguments: +# $1: (mandatory) + +#################################################################################################### + +# Example: +# ./change_profile.sh default +# This will change the user profile to the default profile. + +#################################################################################################### + +# Set the dev and repo name +dev="rootiest" +repo="printcfg" +branch="master" +# Get home directory +home=$(eval echo ~$USER) +# Define the klipper config file +config=$home/printer_data/config +# Define the printer.cfg and moonraker.conf files +printer=$home/printer_data/config/printer.cfg +moonraker=$home/printer_data/config/moonraker.conf +# Set the default profile +default_src=default +user_vars=$config/user_profile.cfg +old_user_vars=$config/$repo/user_profile.cfg +user_cfg=$config/user_config.cfg +old_user_cfg=$config/$repo/user_config.cfg +profile_pattern="# Profile:(.*)" + +# Check if any parameters were provided +if [ $# -eq 0 ] +then + echo -e "\n\e[31mERROR: No profile name provided.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 +else + # Set the profile name + if [ -n "$1" ] + then + if [ "$1" == "backup" ] + then + src_vars=$config/user_profile.cfg.bak + src_cfg=$config/user_config.cfg.bak + src_path=$config + else + src_vars=$config/$repo/profiles/$1/variables.cfg + src_cfg=$config/$repo/profiles/$1/config.cfg + src_path=$config/$repo/profiles/$1 + fi + fi +fi + +echo -e "\nChanging profile to $1..." + +# Check if the profile exists +if [ ! -d "$src_path" ] +then + echo -e "\n\e[31mERROR: Profile $1 does not exist.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 +fi + +# Check if the profile is already active +if [ -f "$user_vars" ] +then + # Search for the profile_pattern in the user_vars using grep + vars_profile=$(grep -oP "$profile_pattern" "$user_vars" | cut -d':' -f2) + # Verify that the profile marker was found + if [ -z "$vars_profile" ] + then + echo -e "\n\e[31mERROR: Profile marker not found in $user_vars.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + # Search for the profile_pattern in the src_vars using grep + src_profile=$(grep -oP "$profile_pattern" "$src_vars" | cut -d':' -f2) + # Verify that the profile marker was found + if [ -z "$src_profile" ] + then + echo -e "\n\e[31mERROR: Profile marker not found in $src_vars.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + # Check if the profile is already active + if [ "$vars_profile" == "$src_profile" ] + then + echo -e "\n\e[31mERROR: Profile $1 is already active.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Check if the user config file exists +if [ -f "$user_cfg" ] +then + # Search for the profile_pattern in the user_cfg using grep + cfg_profile=$(grep -oP "$profile_pattern" "$user_cfg" | cut -d':' -f2) + # Verify that the profile marker was found + if [ -z "$cfg_profile" ] + then + echo -e "\n\e[31mERROR: Profile marker not found in $user_cfg.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + # Search for the profile_pattern in the src_cfg using grep + src_profile=$(grep -oP "$profile_pattern" "$src_cfg" | cut -d':' -f2) + # Verify that the profile marker was found + if [ -z "$src_profile" ] + then + echo -e "\n\e[31mERROR: Profile marker not found in $src_cfg.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + # Check if the profile is already active + if [ "$cfg_profile" == "$src_profile" ] + then + echo -e "\n\e[31mERROR: Profile $1 is already active.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Check if source file extensions end in .bak +if [ "${src_vars: -4}" == ".bak" ] +then + # Copy them to a temp file + cp "$src_vars" "$src_vars.tmp" + src_vars="$src_vars.tmp" +fi +if [ "${src_cfg: -4}" == ".bak" ] +then + # Copy them to a temp file + cp "$src_cfg" "$src_cfg.tmp" + src_cfg="$src_cfg.tmp" +fi + +# Backup the current user profile +if [ -f "$user_vars" ] +then + # Check if the backup already exists + if [ -f "$user_vars.bak" ] + then + # Rename the backup + cp "$user_vars.bak" "$user_vars.old" + # Verify that the rename was successful + if [ $? -ne 0 ] + then + echo -e "\n\e[31mERROR: Failed to rename $user_vars.bak to $user_vars.old.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + fi + # Backup the current user profile + cp "$user_vars" "$user_vars.bak" + # Verify that the backup was successful + if [ $? -ne 0 ] + then + echo -e "\n\e[31mERROR: Failed to backup $user_vars.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Backup the current user config +if [ -f "$user_cfg" ] +then + # Check if the backup already exists + if [ -f "$user_cfg.bak" ] + then + # Rename the backup + cp "$user_cfg.bak" "$user_cfg.old" + # Verify that the rename was successful + if [ $? -ne 0 ] + then + echo -e "\n\e[31mERROR: Failed to rename $user_cfg.bak to $user_cfg.old.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + fi + # Backup the current user config + cp "$user_cfg" "$user_cfg.bak" + # Verify that the backup was successful + if [ $? -ne 0 ] + then + echo -e "\n\e[31mERROR: Failed to backup $user_cfg.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Apply the new profile +if [ -f "$user_vars" ] +then + # Copy the new profile to the user profile + cp "$src_vars" "$user_vars" + # Verify that the copy was successful + if [ $? -ne 0 ] + then + echo -e "\n\e[31mERROR: Failed to copy $src_vars to $user_vars.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Apply the new config +if [ -f "$user_cfg" ] +then + # Copy the new config to the user config + cp "$src_cfg" "$user_cfg" + # Verify that the copy was successful + if [ $? -ne 0 ] + then + echo -e "\n\e[31mERROR: Failed to copy $src_cfg to $user_cfg.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Check for the new profile marker in the user_vars +if [ -f "$user_vars" ] +then + # Search for the profile_pattern in the user_vars using grep + vars_profile=$(grep -oP "$profile_pattern" "$user_vars" | cut -d':' -f2) + # Verify that the profile marker was found + if [ -z "$vars_profile" ] + then + echo -e "\n\e[31mERROR: Profile marker not found in $user_vars.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + # Search for the profile_pattern in the src_vars using grep + src_profile=$(grep -oP "$profile_pattern" "$src_vars" | cut -d':' -f2) + # Verify that the profile marker was found + if [ -z "$src_profile" ] + then + echo -e "\n\e[31mERROR: Profile marker not found in $src_vars.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + # Check if the profile is already active + if [ "$vars_profile" != "$src_profile" ] + then + echo -e "\n\e[31mERROR: Failed to apply profile $1.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Check for the new profile marker in the user_cfg +if [ -f "$user_cfg" ] +then + # Search for the profile_pattern in the user_cfg using grep + cfg_profile=$(grep -oP "$profile_pattern" "$user_cfg" | cut -d':' -f2) + # Verify that the profile marker was found + if [ -z "$cfg_profile" ] + then + echo -e "\n\e[31mERROR: Profile marker not found in $user_cfg.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + # Search for the profile_pattern in the src_cfg using grep + src_profile=$(grep -oP "$profile_pattern" "$src_cfg" | cut -d':' -f2) + # Verify that the profile marker was found + if [ -z "$src_profile" ] + then + echo -e "\n\e[31mERROR: Profile marker not found in $src_cfg.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi + # Check if the profile is already active + if [ "$cfg_profile" != "$src_profile" ] + then + echo -e "\n\e[31mERROR: Failed to apply profile $1.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Remove temp files + +# Check if src_vars is a temp file +if [ "${src_vars: -4}" == ".tmp" ] +then + # Remove the temp file + rm "$src_vars" + # Verify that the file was removed + if [ $? -ne 0 ] + then + echo -e "\n\e[31mERROR: Failed to remove $src_vars.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Check if src_cfg is a temp file +if [ "${src_cfg: -4}" == ".tmp" ] +then + # Remove the temp file + rm "$src_cfg" + # Verify that the file was removed + if [ $? -ne 0 ] + then + echo -e "\n\e[31mERROR: Failed to remove $src_cfg.\e[0m" + echo "Usage: ./change_profile.sh " + exit 1 + fi +fi + +# Success +echo -e "\n\e[32mSuccessfully applied profile $1.\e[0m" diff --git a/scripts/remove_printcfg.sh b/scripts/remove_printcfg.sh new file mode 100644 index 0000000..eebf5ab --- /dev/null +++ b/scripts/remove_printcfg.sh @@ -0,0 +1,119 @@ +#!/bin/bash +# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +# +# This file is part of printcfg. +# +# printcfg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# printcfg is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printcfg. If not, see . + +# This script will remove printcfg from your system. + +# Set the dev and repo name +dev="rootiest" +repo="printcfg" +branch="master" +# Get home directory +home=$(eval echo ~$USER) +# Define the klipper config file +config=$home/printer_data/config +# Define the printer.cfg and moonraker.conf files +printer=$home/printer_data/config/printer.cfg +moonraker=$home/printer_data/config/moonraker.conf +# Set the default profile +default_src=default +user_vars=$config/user_profile.cfg +old_user_vars=$config/$repo/user_profile.cfg +user_cfg=$config/user_config.cfg +old_user_cfg=$config/$repo/user_config.cfg + +# Check if any parameters were provided +if [ "$1" ]; then + # No parameters were provided + # Check if the first parameter is 'force' + if [ "$1" != "force" ]; then + # Prompt the user to confirm + echo -e "\e[31mWARNING: This script will remove $repo from your system.\e[0m" + read -p "Are you sure you want to remove $repo? [y/N] " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + # Exit the script + exit 1 + fi +fi + +# Stop the printcfg service +sudo systemctl stop $repo.service + +# Verify that the printcfg service was stopped +if [ "$(systemctl is-active $repo.service)" = "active" ]; then + echo -e "\e[31mFailed to stop the printcfg service.\e[0m" + exit 1 +fi + +# Remove the printcfg service +sudo rm /etc/systemd/system/$repo.service + +# Verify that the printcfg service was removed +if [ -f /etc/systemd/system/$repo.service ]; then + echo -e "\e[31mFailed to remove the printcfg service.\e[0m" + exit 1 +fi + +# Remove the [include user_config.cfg] line from printer.cfg +include_line="[include user_config.cfg]" +replace_line="#[include user_config.cfg]" +python3 $home/$repo/scripts/search_replace.py $include_line $replace_line $printer + +# Remove the printcfg directory +sudo rm -r $home/$repo + +# Verify that the printcfg directory was removed +if [ -d $home/$repo ]; then + echo -e "\e[31mFailed to remove the printcfg directory.\e[0m" + exit 1 +fi + +# Remove the printcfg symlink from the klipper config directory +sudo rm $config/$repo + +# Verify that the printcfg symlink was removed +if [ -L $config/$repo ]; then + echo -e "\e[31mFailed to remove the printcfg symlink.\e[0m" + exit 1 +fi + +# Success +echo -e "\e[32mSuccessfully removed $repo.\e[0m" + + + + + + + + + + + + + + + +# Get the current script directory +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Remove the script directory +rm -r "$SCRIPT_DIR" + +# Remove the script file +rm "$0" \ No newline at end of file diff --git a/scripts/search_replace.py b/scripts/search_replace.py index 9af8abc..2dc9dfa 100644 --- a/scripts/search_replace.py +++ b/scripts/search_replace.py @@ -20,6 +20,9 @@ #!/usr/bin/env python3 # This script searches for a line containing a specific text and replaces the whole line with a new text. +# If the text is not found, the new text is added to the beginning of the file. + +# Usage: python3 search_replace.py import os import sys diff --git a/src/mooncfg.conf b/src/mooncfg.conf index d4e1f9f..446ff1e 100644 --- a/src/mooncfg.conf +++ b/src/mooncfg.conf @@ -7,7 +7,7 @@ [update_manager printcfg] type: git_repo channel: dev -primary_branch: dev +primary_branch: master path: ~/printcfg origin: https://github.com/rootiest/printcfg.git is_system_service: True diff --git a/src/setup.py b/src/setup.py index 4a9e4c5..614a35e 100644 --- a/src/setup.py +++ b/src/setup.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) # # This file is part of printcfg. @@ -17,15 +18,19 @@ # This script collects some data and then triggers the service generator. +#!/usr/bin/env python3 + import os import sys import getpass import subprocess -def start_script_as_root(): # Get the current user name - current_user = getpass.getuser() - user_home = os.path.expanduser('~') +current_user = getpass.getuser() +user_home = os.path.expanduser('~') + +def start_script_as_root(): + my_path = os.path.dirname(os.path.realpath(__file__)) script_dir = os.path.dirname(my_path) mode = sys.argv[1] @@ -42,5 +47,70 @@ def start_script_as_root(): command = ['sudo', 'python3', script_path, current_user, user_home, mode] subprocess.run(command) +def change_profile(profile): + # Define the path to the second script + script_path = f'{user_home}/printcfg/scripts/change_profile.sh' + + # Check if the second script exists + if not os.path.isfile(script_path): + print(f"Error: The script '{script_path}' does not exist.") + return + + # Start the second script as root with the current user name as the first argument + command = ['bash', script_path, profile] + subprocess.run(command) + +def remove_printcfg(): + # Define the path to the second script + script_path = f'{user_home}/printcfg/scripts/remove_printcfg.sh' + + # Check if the second script exists + if not os.path.isfile(script_path): + print(f"Error: The script '{script_path}' does not exist.") + return + + # Start the second script as root with the current user name as the first argument + command = ['bash', script_path] + subprocess.run(command) + if __name__ == '__main__': - start_script_as_root() \ No newline at end of file + # Check the number of arguments + if len(sys.argv) < 2: + print('Error: This script requires one argument.') + print('Usage: python3 setup.py ') + print('Modes: install, change, remove') + sys.exit(1) + # Check the argument + if sys.argv[1] not in ['install', 'change', 'remove']: + print('Error: The argument must be either install, change, or remove.') + sys.exit(1) + # If the argument is 'install' start the script as root + if sys.argv[1] == 'install': + start_script_as_root() + # If the argument is 'change' check for a second argument + elif sys.argv[1] == 'change': + if len(sys.argv) != 3: + print('Error: The change script requires two arguments.') + print('Usage: python3 setup.py change ') + sys.exit(1) + else: + # Check if the profile exists + profile = sys.argv[2] + profile_path = f'{user_home}/printcfg/profiles/{profile}' + print(f"Changing to profile '{profile}'") + # If the profile is 'backup' then skip the check + if profile == 'backup': + change_profile(profile) + else: + # If the profile path does not exist, exit + if not os.path.isdir(profile_path): + print(f"Error: The profile '{profile}' does not exist.") + sys.exit(1) + else: + change_profile(profile) + # If the argument is 'remove' + elif sys.argv[1] == 'remove': + remove_printcfg() + else: + print('Error: The argument must be either install, change, or remove.') + sys.exit(1) \ No newline at end of file From 12c130859ff1cf4900b131af223747dfffcdddd6 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 11:50:30 -0400 Subject: [PATCH 63/81] printcfg v4.0.0 Implement door control --- README.md | 2 +- print_debug.cfg | 2 +- print_extras.cfg | 2 +- print_macros.cfg | 76 ++++++++++++++++++- profiles/README.md | 2 +- profiles/default/config.cfg | 4 +- profiles/default/patch_notes.txt | 12 +++ profiles/default/patches/3.9.0/vars.patch | 0 .../patches/4.0.0}/config.patch | 28 +++++++ profiles/default/patches/4.0.0/vars.patch | 10 +++ profiles/default/variables.cfg | 18 ++++- profiles/hephaestus/config.cfg | 4 +- profiles/hephaestus/patch_notes.txt | 6 ++ profiles/hephaestus/patches/3.9.0/vars.patch | 0 .../patches/4.0.0}/config.patch | 28 +++++++ profiles/hephaestus/patches/4.0.0/vars.patch | 10 +++ profiles/hephaestus/variables.cfg | 18 ++++- scripts/change_profile.sh | 2 +- scripts/install.sh | 2 +- scripts/patch.sh | 22 +++++- scripts/setup.sh | 2 +- src/mooncfg.conf | 2 +- 22 files changed, 229 insertions(+), 23 deletions(-) delete mode 100644 profiles/default/patches/3.9.0/vars.patch rename profiles/{hephaestus/patches/3.9.0 => default/patches/4.0.0}/config.patch (86%) create mode 100644 profiles/default/patches/4.0.0/vars.patch delete mode 100644 profiles/hephaestus/patches/3.9.0/vars.patch rename profiles/{default/patches/3.9.0 => hephaestus/patches/4.0.0}/config.patch (86%) create mode 100644 profiles/hephaestus/patches/4.0.0/vars.patch diff --git a/README.md b/README.md index ebd8814..5433be2 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ diff --git a/print_debug.cfg b/print_debug.cfg index 24ac385..1295d28 100644 --- a/print_debug.cfg +++ b/print_debug.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Debugging ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### ## This file contains optional macros diff --git a/print_extras.cfg b/print_extras.cfg index 9ca5c6d..d07ce40 100644 --- a/print_extras.cfg +++ b/print_extras.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Extras ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### ## This file contains optional config diff --git a/print_macros.cfg b/print_macros.cfg index 875a508..5da4a1b 100644 --- a/print_macros.cfg +++ b/print_macros.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Macros ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### ################################ @@ -1473,6 +1473,80 @@ gcode: #M{printcfg.output|int} Disabling filament sensor SET_FILAMENT_SENSOR SENSOR={SENSOR} ENABLE=0 +################################ +######### DOOR CONTROL ######### +################################ +## Door control macros + +### Door Variables ### +[gcode_macro _door_cfg] +variable_debounce: 0 ; <-- DO NOT CHANGE THIS VARIABLE +variable_state: 0 ; <-- DO NOT CHANGE THIS VARIABLE +variable_bounce: 0 ; <-- DO NOT CHANGE THIS VARIABLE + +[gcode_macro _open_door] +description: Door is opened +gcode: + {% set doorcfg = printer['gcode_macro _door_cfg'] %} ; get doorcfg variables + {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables + {% if doorcfg.debounce == 0 %} ; check debounce + M{printcfg.output|int} Door Open ; status output + {printcfg.status_door_open} ; open door LEDs + {printcfg.door_open_gcode} ; open door custom macro + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=debounce VALUE=1 ; set debounce state + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=state VALUE=1 ; set door state + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=1 ; set door bounce + UPDATE_DELAYED_GCODE ID=door_debounce DURATION={(printcfg.door_debounce / 1000)|float} ; set debounce timer + {% else %} ; bounced + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=1 ; set door bounce + {% endif %} + +[gcode_macro _close_door] +description: Door is closed +gcode: + {% set doorcfg = printer['gcode_macro _door_cfg'] %} ; get doorcfg variables + {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables + {% if doorcfg.debounce == 0 %} ; check debounce + M{printcfg.output|int} Door Closed ; status output + {% if printer.virtual_sdcard.is_active == True %} ; printing state + {printcfg.status_printing} ; closed door printing LEDs + {% else %} ; idle state + {printcfg.status_ready} ; closed door idle LEDs + {% endif %} + {printcfg.door_closed_gcode} ; closed door custom macro + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=debounce VALUE=1 ; set debounce state + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=state VALUE=0 ; set door state + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=0 ; set door bounce + UPDATE_DELAYED_GCODE ID=door_debounce DURATION={(printcfg.door_debounce / 1000)|float} ; set debounce timer + {% else %} ; bounced + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=0 ; set door bounce + {% endif %} + +[delayed_gcode door_debounce] +gcode: + {% set doorcfg = printer['gcode_macro _door_cfg'] %} ; get doorcfg variables + {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables + {% if doorcfg.bounce != doorcfg.state %} ; check if a bounce ocurred + {% if doorcfg.bounce == 1 %} ; bounced open + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=state VALUE=1 ; set door state + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=1 ; set door bounce + M{printcfg.output|int} Door Open ; status output + {printcfg.status_door_open} ; open door LEDs + {printcfg.door_open_gcode} ; open door custom macro + {% else %} ; bounced closed + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=state VALUE=0 ; set door state + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=0 ; set door bounce + M{printcfg.output|int} Door Closed ; status output + {% if printer.virtual_sdcard.is_active == True %} ; printing state + {printcfg.status_printing} ; closed door printing LEDs + {% else %} ; idle state + {printcfg.status_ready} ; closed door idle LEDs + {% endif %} + {printcfg.door_closed_gcode} ; closed door custom macro + {% endif %} + {% endif %} + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=debounce VALUE=0 ; reset debounce state + ################################ ##### STORE_POSITION_MODE ###### ################################ diff --git a/profiles/README.md b/profiles/README.md index 7b0253a..6d9069b 100644 --- a/profiles/README.md +++ b/profiles/README.md @@ -20,7 +20,7 @@ # Preset Profiles diff --git a/profiles/default/config.cfg b/profiles/default/config.cfg index 3b04541..1621095 100644 --- a/profiles/default/config.cfg +++ b/profiles/default/config.cfg @@ -17,10 +17,10 @@ ##################################### ## Print Configuration ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### # Profile:default -# Patch:3.9.0 +# Patch:4.0.0 ##################################### ## Default Profile ## ##################################### diff --git a/profiles/default/patch_notes.txt b/profiles/default/patch_notes.txt index 35ff736..5d8addb 100644 --- a/profiles/default/patch_notes.txt +++ b/profiles/default/patch_notes.txt @@ -2,3 +2,15 @@ - Moved z_hopped variable as it's only used by the backend. (non-critical) Remove: variable_z_hopped +3.9.0: + - Moved SET_MATERIAL and SET_NOZZLE to user_config.cfg + Add: + USER_CONFIG: + SET_MATERIAL + SET_NOZZLE +4.0.0: + - Add door control + Add: + Door Variables (see 4.0.0/vars.patch) + MANUAL: + Add '# End Custom Variables #` line before read-only variables in _printcfg macro. \ No newline at end of file diff --git a/profiles/default/patches/3.9.0/vars.patch b/profiles/default/patches/3.9.0/vars.patch deleted file mode 100644 index e69de29..0000000 diff --git a/profiles/hephaestus/patches/3.9.0/config.patch b/profiles/default/patches/4.0.0/config.patch similarity index 86% rename from profiles/hephaestus/patches/3.9.0/config.patch rename to profiles/default/patches/4.0.0/config.patch index 4287600..d92cb16 100644 --- a/profiles/hephaestus/patches/3.9.0/config.patch +++ b/profiles/default/patches/4.0.0/config.patch @@ -86,3 +86,31 @@ gcode: {%else %} ; If any other nozzle diameter #SET_GCODE_OFFSET Z=0 ; Set z_offset {% endif %} + +################################ +######## Door Configs ########## +################################ + +#[gcode_button left_door] +########## IMPORTANT ########### +## ---------------------------- ## +# Set pin to match your machine: # +#pin: !PG16 # +## ---------------------------- ## +########## IMPORTANT ########### +#press_gcode: +# _close_door ; DO NOT CHANGE +#release_gcode: +# _open_door ; DO NOT CHANGE + +#[gcode_button right_door] +########## IMPORTANT ########### +## ---------------------------- ## +# Set pin to match your machine: # +#pin: !PG16 # +## ---------------------------- ## +########## IMPORTANT ########### +#press_gcode: +# _close_door ; DO NOT CHANGE +#release_gcode: +# _open_door ; DO NOT CHANGE \ No newline at end of file diff --git a/profiles/default/patches/4.0.0/vars.patch b/profiles/default/patches/4.0.0/vars.patch new file mode 100644 index 0000000..0e2f7c1 --- /dev/null +++ b/profiles/default/patches/4.0.0/vars.patch @@ -0,0 +1,10 @@ + +## Door Switch Variables +variable_doors: 0 ; Number of doors (0, 1 or 2) +variable_door1: 'left_door' ; Name of first door switch +variable_door2: 'right_door' ; Name of second door switch +## Note: Additional door switches can be added here (e.g. variable_door3, variable_door4, etc.) +variable_door_debounce: 250 ; Debounce time for door switch (ms) +variable_status_door_open: '_STATUS_BRIGHT' ; Status to show when door is open +variable_door_open_gcode: 'M116' ; Custom macro for open doors (set to 'M116' to disable) +variable_door_closed_gcode: 'M116' ; Custom macro for closed doors (set to 'M116' to disable) diff --git a/profiles/default/variables.cfg b/profiles/default/variables.cfg index 19de450..c13c218 100644 --- a/profiles/default/variables.cfg +++ b/profiles/default/variables.cfg @@ -17,10 +17,10 @@ ##################################### ## User Profile ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### # Profile:default -# Patch:3.9.0 +# Patch:4.0.0 ##################################### ## Default Profile ## ##################################### @@ -38,7 +38,7 @@ ## printcfg Configuration Variables ## Variables file version -variable_version: '3.9.0' +variable_version: '4.0.0' ## Default temperatures variable_extruder_temp: 200 @@ -261,6 +261,18 @@ variable_alert_freq: 5 variable_use_telegram: False # Use Telegram feedback macros variable_telegram_runout: 'TELEGRAM_FILAMENT_RUNOUT' +## Door Switch Variables +variable_doors: 0 ; Number of doors (0, 1 or 2) +variable_door1: 'left_door' ; Name of first door switch +variable_door2: 'right_door' ; Name of second door switch +## Note: Additional door switches can be added here (e.g. variable_door3, variable_door4, etc.) +variable_door_debounce: 250 ; Debounce time for door switch (ms) +variable_status_door_open: '_STATUS_BRIGHT' ; Status to show when door is open +variable_door_open_gcode: 'M116' ; Custom macro for open doors (set to 'M116' to disable) +variable_door_closed_gcode: 'M116' ; Custom macro for closed doors (set to 'M116' to disable) + +# End Custom Variables # + ############################################################################################################# #################################### Do not edit below this line ############################################ ############################################################################################################# diff --git a/profiles/hephaestus/config.cfg b/profiles/hephaestus/config.cfg index 3bf7c9c..68b7199 100644 --- a/profiles/hephaestus/config.cfg +++ b/profiles/hephaestus/config.cfg @@ -17,10 +17,10 @@ ##################################### ## Print Configuration ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### # Profile:hephaestus -# Patch:3.9.0 +# Patch:4.0.0 ##################################### ## Hephaestus Profile ## ##################################### diff --git a/profiles/hephaestus/patch_notes.txt b/profiles/hephaestus/patch_notes.txt index 63c5bb4..5d8addb 100644 --- a/profiles/hephaestus/patch_notes.txt +++ b/profiles/hephaestus/patch_notes.txt @@ -8,3 +8,9 @@ USER_CONFIG: SET_MATERIAL SET_NOZZLE +4.0.0: + - Add door control + Add: + Door Variables (see 4.0.0/vars.patch) + MANUAL: + Add '# End Custom Variables #` line before read-only variables in _printcfg macro. \ No newline at end of file diff --git a/profiles/hephaestus/patches/3.9.0/vars.patch b/profiles/hephaestus/patches/3.9.0/vars.patch deleted file mode 100644 index e69de29..0000000 diff --git a/profiles/default/patches/3.9.0/config.patch b/profiles/hephaestus/patches/4.0.0/config.patch similarity index 86% rename from profiles/default/patches/3.9.0/config.patch rename to profiles/hephaestus/patches/4.0.0/config.patch index 4287600..fe4f638 100644 --- a/profiles/default/patches/3.9.0/config.patch +++ b/profiles/hephaestus/patches/4.0.0/config.patch @@ -86,3 +86,31 @@ gcode: {%else %} ; If any other nozzle diameter #SET_GCODE_OFFSET Z=0 ; Set z_offset {% endif %} + +################################ +######## Door Configs ########## +################################ + +[gcode_button doors] +########## IMPORTANT ########### +## ---------------------------- ## +# Set pin to match your machine: # +pin: !PG15 # +## ---------------------------- ## +########## IMPORTANT ########### +press_gcode: + _close_door ; DO NOT CHANGE +release_gcode: + _open_door ; DO NOT CHANGE + +#[gcode_button right_door] +########## IMPORTANT ########### +## ---------------------------- ## +# Set pin to match your machine: # +#pin: !PG16 # +## ---------------------------- ## +########## IMPORTANT ########### +#press_gcode: +# _close_door ; DO NOT CHANGE +#release_gcode: +# _open_door ; DO NOT CHANGE diff --git a/profiles/hephaestus/patches/4.0.0/vars.patch b/profiles/hephaestus/patches/4.0.0/vars.patch new file mode 100644 index 0000000..281f28e --- /dev/null +++ b/profiles/hephaestus/patches/4.0.0/vars.patch @@ -0,0 +1,10 @@ + +## Door Switch Variables +variable_doors: 1 ; Number of doors (0, 1 or 2) +variable_door1: 'doors' ; Name of first door switch +variable_door2: 'right_door' ; Name of second door switch +## Note: Additional door switches can be added here (e.g. variable_door3, variable_door4, etc.) +variable_door_debounce: 250 ; Debounce time for door switch (ms) +variable_status_door_open: '_STATUS_BRIGHT' ; Status to show when door is open +variable_door_open_gcode: 'M116' ; Custom macro for open doors (set to 'M116' to disable) +variable_door_closed_gcode: 'M116' ; Custom macro for closed doors (set to 'M116' to disable) diff --git a/profiles/hephaestus/variables.cfg b/profiles/hephaestus/variables.cfg index 2c3cd2f..d2974b2 100644 --- a/profiles/hephaestus/variables.cfg +++ b/profiles/hephaestus/variables.cfg @@ -17,10 +17,10 @@ ##################################### ## User Profile ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### # Profile:hephaestus -# Patch:3.9.0 +# Patch:4.0.0 ##################################### ## Hephaestus Profile ## ##################################### @@ -38,7 +38,7 @@ ## printcfg Configuration Variables ## Variables file version -variable_version: '3.9.0' +variable_version: '4.0.0' ## Default temperatures variable_extruder_temp: 240 @@ -261,6 +261,18 @@ variable_alert_freq: 5 variable_use_telegram: False # Use Telegram feedback macros variable_telegram_runout: 'TELEGRAM_FILAMENT_RUNOUT' +## Door Switch Variables +variable_doors: 1 ; Number of doors (0, 1 or 2) +variable_door1: 'doors' ; Name of first door switch +variable_door2: 'right_door' ; Name of second door switch +## Note: Additional door switches can be added here (e.g. variable_door3, variable_door4, etc.) +variable_door_debounce: 250 ; Debounce time for door switch (ms) +variable_status_door_open: '_STATUS_BRIGHT' ; Status to show when door is open +variable_door_open_gcode: 'M116' ; Custom macro for open doors (set to 'M116' to disable) +variable_door_closed_gcode: 'M116' ; Custom macro for closed doors (set to 'M116' to disable) + +# End Custom Variables # + ############################################################################################################# #################################### Do not edit below this line ############################################ ############################################################################################################# diff --git a/scripts/change_profile.sh b/scripts/change_profile.sh index 63bf273..9963afa 100644 --- a/scripts/change_profile.sh +++ b/scripts/change_profile.sh @@ -19,7 +19,7 @@ ##################################### ## Printcfg Profile Change ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### # This script will change the user profile to the specified profile. diff --git a/scripts/install.sh b/scripts/install.sh index 763907f..3ab4e41 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -19,7 +19,7 @@ ##################################### ## Printcfg Install Script ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### # This script will download and install the printcfg package from GitHub. diff --git a/scripts/patch.sh b/scripts/patch.sh index 13985fe..f9e6ce3 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -19,7 +19,7 @@ ##################################### ## Printcfg Patch Script ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### # This script will apply version patches to the user profile and user config. @@ -29,7 +29,7 @@ #################################################################################################### # Example: -# ./patch.sh 3.9.0 +# ./patch.sh 4.0.0 # This will force the user profile to be patched for the specified version. # Example: @@ -219,11 +219,12 @@ if [ "$update_config" = "False" ] && [ "$update_profile" = "False" ]; then echo -e "\e[32mNo action required.\e[0m" exit 0 else - z # Search for patch files matching the user profile version + # Search for patch files matching the user profile version echo "Searching for patch files..." vars_patch=$home/$repo/profiles/$vars_profile/patches/$highest_version/vars.patch config_patch=$home/$repo/profiles/$config_profile/patches/$highest_version/config.patch + # Check if the config needs to be updated if [ "$update_config" = "True" ]; then # Check if the patch file exists if [ -f $config_patch ]; then @@ -252,13 +253,26 @@ else fi fi + # Check if the profile needs to be updated if [ "$update_profile" = "True" ]; then # Check if the patch file exists if [ -f $vars_patch ]; then echo "Patch file found." # Append the contents of the patch file to the user config echo "Applying profile patch file..." - cat $vars_patch >> $user_vars + # Find the line containing '# End Custom Variables #' + vars_end=$(grep -n '# End Custom Variables #' $user_vars | cut -d':' -f1) + # Make sure the line number is not empty + if [ -z "$vars_end" ]; then + echo -e "\e[31mEnd of custom variables marker not found.\e[0m" + echo "Marker: # End Custom Variables #" + echo + echo "Using 'gcode:' instead." + vars_end=$(grep -n 'gcode:' $user_vars | cut -d':' -f1) + # Add the patch before the line + sed -i "$vars_end r $vars_patch" $user_vars + # Add a newline after the patch + sed -i "$vars_end a \ " $user_vars echo "Profile patch file applied." # Update version number in user profile echo "Updating version number..." diff --git a/scripts/setup.sh b/scripts/setup.sh index 6c2cd4b..587145a 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -19,7 +19,7 @@ ##################################### ## Printcfg Setup Script ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### # This script will check the user profile and update it if necessary. diff --git a/src/mooncfg.conf b/src/mooncfg.conf index 446ff1e..9289961 100644 --- a/src/mooncfg.conf +++ b/src/mooncfg.conf @@ -1,6 +1,6 @@ ##################################### ## Printcfg Moonraker ## -## Version 3.9.0 2023-5-22 ## +## Version 4.0.0 2023-5-26 ## ##################################### ## Manage updates for Rootiest printcfg Suite for Klipper From c75a25bd6e33528eea8152ade2e6c792d2f52e55 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 11:51:59 -0400 Subject: [PATCH 64/81] forgot a fi --- scripts/patch.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/patch.sh b/scripts/patch.sh index f9e6ce3..cce01cb 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -269,6 +269,7 @@ else echo echo "Using 'gcode:' instead." vars_end=$(grep -n 'gcode:' $user_vars | cut -d':' -f1) + fi # Add the patch before the line sed -i "$vars_end r $vars_patch" $user_vars # Add a newline after the patch From 5778c54a3d4ca169bdf9c49716b3b24422e7befa Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 11:58:05 -0400 Subject: [PATCH 65/81] profile updates --- profiles/default/config.cfg | 60 ++++++++++++++++++++++++++-------- profiles/hephaestus/config.cfg | 31 ++++++++++++++++-- 2 files changed, 75 insertions(+), 16 deletions(-) diff --git a/profiles/default/config.cfg b/profiles/default/config.cfg index 1621095..006a841 100644 --- a/profiles/default/config.cfg +++ b/profiles/default/config.cfg @@ -159,20 +159,24 @@ gcode: [gcode_macro M300] description: Play a tone gcode: - {% set S = params.S|default(1000)|int %} ; S sets the tone frequency - {% set P = params.P|default(100)|int %} ; P sets the tone duration - {% set L = 0.5 %} ; L varies the PWM on time, close to 0 or 1 the tone gets a bit quieter. 0.5 is a symmetric waveform - {% if S <= 0 %} ; dont divide through zero - {% set F = 1 %} - {% set L = 0 %} - {% elif S >= 10000 %} ;max frequency set to 10kHz - {% set F = 0 %} - {% else %} - {% set F = 1/S %} ;convert frequency to seconds - {% endif %} - SET_PIN PIN=_beeper VALUE={L} CYCLE_TIME={F} ;Play tone - G4 P{P} ;tone duration - SET_PIN PIN=_beeper VALUE=0 + +########################################################################## +################# Uncomment Below to enable beeper ####################### +########################################################################## +# {% set S = params.S|default(1000)|int %} ; S sets the tone frequency +# {% set P = params.P|default(100)|int %} ; P sets the tone duration +# {% set L = 0.5 %} ; L varies the PWM on time, close to 0 or 1 the tone gets a bit quieter. 0.5 is a symmetric waveform +# {% if S <= 0 %} ; dont divide through zero +# {% set F = 1 %} +# {% set L = 0 %} +# {% elif S >= 10000 %} ;max frequency set to 10kHz +# {% set F = 0 %} +# {% else %} +# {% set F = 1/S %} ;convert frequency to seconds +# {% endif %} +# SET_PIN PIN=_beeper VALUE={L} CYCLE_TIME={F} ;Play tone +# G4 P{P} ;tone duration +# SET_PIN PIN=_beeper VALUE=0 ################################ ######### SET_CONFIGS ########## @@ -261,3 +265,31 @@ gcode: {%else %} ; If any other nozzle diameter #SET_GCODE_OFFSET Z=0 ; Set z_offset {% endif %} + +################################ +######## Door Configs ########## +################################ + +#[gcode_button left_door] +########## IMPORTANT ########### +## ---------------------------- ## +# Set pin to match your machine: # +#pin: !PG16 # +## ---------------------------- ## +########## IMPORTANT ########### +#press_gcode: +# _close_door ; DO NOT CHANGE +#release_gcode: +# _open_door ; DO NOT CHANGE + +#[gcode_button right_door] +########## IMPORTANT ########### +## ---------------------------- ## +# Set pin to match your machine: # +#pin: !PG16 # +## ---------------------------- ## +########## IMPORTANT ########### +#press_gcode: +# _close_door ; DO NOT CHANGE +#release_gcode: +# _open_door ; DO NOT CHANGE \ No newline at end of file diff --git a/profiles/hephaestus/config.cfg b/profiles/hephaestus/config.cfg index 68b7199..d10f38e 100644 --- a/profiles/hephaestus/config.cfg +++ b/profiles/hephaestus/config.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Configuration ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-5-20 ## ##################################### # Profile:hephaestus # Patch:4.0.0 @@ -173,7 +173,6 @@ gcode: SET_PIN PIN=_beeper VALUE={L} CYCLE_TIME={F} ;Play tone G4 P{P} ;tone duration SET_PIN PIN=_beeper VALUE=0 - ################################ ######### SET_CONFIGS ########## ################################ @@ -261,3 +260,31 @@ gcode: {%else %} ; If any other nozzle diameter #SET_GCODE_OFFSET Z=0 ; Set z_offset {% endif %} + +################################ +######## Door Configs ########## +################################ + +[gcode_button doors] +########## IMPORTANT ########### +## ---------------------------- ## +# Set pin to match your machine: # +pin: !PG15 # +## ---------------------------- ## +########## IMPORTANT ########### +press_gcode: + _close_door ; DO NOT CHANGE +release_gcode: + _open_door ; DO NOT CHANGE + +#[gcode_button right_door] +########## IMPORTANT ########### +## ---------------------------- ## +# Set pin to match your machine: # +#pin: !PG16 # +## ---------------------------- ## +########## IMPORTANT ########### +#press_gcode: +# _close_door ; DO NOT CHANGE +#release_gcode: +# _open_door ; DO NOT CHANGE From 3855591776de1e7665726f0362a9cbc9abf688fd Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 13:06:11 -0400 Subject: [PATCH 66/81] test run with a printcfg executable! --- README.md | 24 +++++--- scripts/install.sh | 10 +++- src/gen_service.py | 9 ++- src/printcfg.py | 139 ++++++++++++++++++++++++++++++++++++++++----- src/setup.py | 116 ------------------------------------- 5 files changed, 154 insertions(+), 144 deletions(-) delete mode 100644 src/setup.py diff --git a/README.md b/README.md index 5433be2..20bad16 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ - [Overview](#overview) - [Installation](#installation) - [What the install script does](#what-the-install-script-does) + - [Updating](#updating) + - [Changing Profiles](#changing-profiles) - [Configuration](#configuration) - [Using the suite](#using-the-suite) - [Profile Configuration](#profile-configuration) @@ -91,6 +93,10 @@ You can also specify a preset profile for a more printer-specific default config curl https://raw.githubusercontent.com/rootiest/printcfg/master/scripts/install.sh | bash -s -- default +Additionally, you can specify a different branch to install from: + + curl https://raw.githubusercontent.com/rootiest/printcfg/master/scripts/install.sh | bash -s -- default dev + ### What the install script does The install script will begin by checking for dependencies and installing them if they are missing. @@ -109,7 +115,7 @@ This will consist of two files: `user_profile.cfg` and `user_config.cfg`. The following line will be added to your `printer.cfg` file: - [include print_config.cfg] + [include user_config.cfg] This tells Klipper to include the printcfg config file. The other files will be included from there. @@ -121,21 +127,21 @@ This adds some moonraker configuration, specifically the `update_manager` for pr After all of these changes are made and verified, the script will restart Klipper and Moonraker. -Future updates will be performed by the `update_manager` service and will typically require a restart of only Klipper. +## Updating -Most updates will be performed automatically, but some may require manual intervention. The installer will notify you if this is the case. +Updates are handled by moonraker's `update_manager` service. -When the update requires manual intervention, you will be notified of the changes that need to be made to your user_profile.cfg file and the installer will exit. Run the setup.sh script again to verify the changes were made and continue the update. +They will appear in the UI alongside updates for Klipper and Moonraker. -In most cases this will only require you to add new variables or remove obsolete variables from your user_profile.cfg file. +The installer can now patch your config files to add new variables or configuration sections. This allows user profiles to be updated without overwriting your existing configuration. -Best efforts will be made to avoid this as much as possible, but future features may require new variables to be added and the process has been made as simple as possible. +Most updates will happen completely automatically, but some may require manual intervention.If an update requires manual intervention, it will be marked as `MANUAL` in the changelog. -It's important to keep the user_profile.cfg file untouched by the automated update process so that your customizations are not overwritten. +## Changing Profiles -When new features are added, you will likely prefer to customize them to your liking, so it's best not to automatically append potentially unwanted new variables to your profile config. +To change profiles, run the following command: -I'm also open to suggestions for improving this process or PRs that add an interactive update process for profile changes from a patch file. + ## Configuration diff --git a/scripts/install.sh b/scripts/install.sh index 3ab4e41..5e4dda9 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -199,12 +199,18 @@ else # Acquire root privileges sudo -v . -#!/usr/bin/env python3 +# This is the printcfg process that runs in the background. +# It also manages the printcfg service. +# Usage: python3 printcfg.py [mode] +# Modes: +# default: Run the script normally (default) +# install: Install the printcfg service +# change: Change the printcfg profile +# remove: Remove the printcfg service +# update: Update printcfg -# This is the printcfg service. +#!/usr/bin/env python3 -import subprocess import os +import sys +import getpass +import subprocess -# Path to the shell script -SHELL_SCRIPT = "/home/pi/printcfg/scripts/setup.sh" +# Set the repo name +REPO = 'printcfg' -# Run the shell script at startup -subprocess.Popen(["/bin/bash", SHELL_SCRIPT]) +# Get the current user name +current_user = getpass.getuser() +user_home = os.path.expanduser('~') +profile_path = f"{user_home}/printer_data/user_profile.cfg" +setup_script = f"{user_home}/printcfg/scripts/setup.sh" -# Continuously run in the background -while True: - # Do any other tasks or operations here - # You can add your code logic within this loop +def find_profile(path): + # Find the profile name (Eg: '# Profile: default' = 'default') + with open(path, 'r') as file: + for line in file: + if line.startswith('# Profile: '): + # Return the profile name + return line[11:].strip() + +def normal_ops(): + # Run the shell script at startup + subprocess.Popen(["/bin/bash", setup_script]) + print (f"Running in the background as {current_user}") + # Continuously run in the background + while True: + # Sleep for a minute + os.system("sleep 60") + +def generate_service(): + # Define the path to the second script + script_dir = f'{user_home}/{REPO}/' + mode = sys.argv[1] + # Define the path to the second script + script_path = f'{script_dir}/src/gen_service.py' + # Check if the second script exists + if not os.path.isfile(script_path): + print(f"Error: The script '{script_path}' does not exist.") + return + # Start the second script as root with the current user name as the first argument + command = ['sudo', 'python3', script_path, current_user, user_home, mode] + subprocess.run(command) + +def change_profile(profile): + # Define the path to the second script + script_path = f'{user_home}/{REPO}/scripts/change_profile.sh' + # Check if the second script exists + if not os.path.isfile(script_path): + print(f"Error: The script '{script_path}' does not exist.") + return + # Start the change profile script + command = ['bash', script_path, profile] + subprocess.run(command) - # Sleep for a certain duration (e.g., 1 second) - os.system("sleep 1") +def update_printcfg(): + # Define the path to the second script + script_path = f'{user_home}/{REPO}/scripts/install.sh' + # Check if the second script exists + if not os.path.isfile(script_path): + print(f"Error: The script '{script_path}' does not exist.") + return + # Find the current profile + profile = find_profile(profile_path) + # Start the update script + command = ['bash', script_path, profile] + +def remove_printcfg(): + # Define the path to the second script + script_path = f'{user_home}/{REPO}/scripts/remove_{REPO}.sh' + # Check if the second script exists + if not os.path.isfile(script_path): + print(f"Error: The script '{script_path}' does not exist.") + return + # Start the second script as root with the current user name as the first argument + command = ['bash', script_path] + subprocess.run(command) + +if __name__ == '__main__': + # Check if there are any arguments + if len(sys.argv) < 2: + normal_ops() + sys.exit(1) + # Check the argument + if sys.argv[1] not in ['install', 'change', 'remove', 'update', 'default']: + print('Error: The argument must be either install, change, remove, update, or default.') + sys.exit(1) + # If the argument is 'install' start the script as root + if sys.argv[1] == 'install': + generate_service() + # If the argument is 'change' check for a second argument + elif sys.argv[1] == 'change': + if len(sys.argv) != 3: + print('Error: The change script requires two arguments.') + print(f'Usage: python3 {REPO}.py change ') + sys.exit(1) + else: + # Check if the profile exists + profile = sys.argv[2] + profile_path = f'{user_home}/{REPO}/profiles/{profile}' + print(f"Changing to profile '{profile}'") + # If the profile is 'backup' then skip the check + if profile == 'backup': + change_profile(profile) + else: + # If the profile path does not exist, exit + if not os.path.isdir(profile_path): + print(f"Error: The profile '{profile}' does not exist.") + sys.exit(1) + else: + change_profile(profile) + # If the argument is 'remove' + elif sys.argv[1] == 'remove': + remove_printcfg() + elif sys.argv[1] == 'update': + update_printcfg() + + else: + normal_ops() \ No newline at end of file diff --git a/src/setup.py b/src/setup.py deleted file mode 100644 index 614a35e..0000000 --- a/src/setup.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) -# -# This file is part of printcfg. -# -# printcfg is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# printcfg is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with printcfg. If not, see . - -# This script collects some data and then triggers the service generator. - -#!/usr/bin/env python3 - -import os -import sys -import getpass -import subprocess - - # Get the current user name -current_user = getpass.getuser() -user_home = os.path.expanduser('~') - -def start_script_as_root(): - - my_path = os.path.dirname(os.path.realpath(__file__)) - script_dir = os.path.dirname(my_path) - mode = sys.argv[1] - - # Define the path to the second script - script_path = f'{script_dir}/src/gen_service.py' - - # Check if the second script exists - if not os.path.isfile(script_path): - print(f"Error: The script '{script_path}' does not exist.") - return - - # Start the second script as root with the current user name as the first argument - command = ['sudo', 'python3', script_path, current_user, user_home, mode] - subprocess.run(command) - -def change_profile(profile): - # Define the path to the second script - script_path = f'{user_home}/printcfg/scripts/change_profile.sh' - - # Check if the second script exists - if not os.path.isfile(script_path): - print(f"Error: The script '{script_path}' does not exist.") - return - - # Start the second script as root with the current user name as the first argument - command = ['bash', script_path, profile] - subprocess.run(command) - -def remove_printcfg(): - # Define the path to the second script - script_path = f'{user_home}/printcfg/scripts/remove_printcfg.sh' - - # Check if the second script exists - if not os.path.isfile(script_path): - print(f"Error: The script '{script_path}' does not exist.") - return - - # Start the second script as root with the current user name as the first argument - command = ['bash', script_path] - subprocess.run(command) - -if __name__ == '__main__': - # Check the number of arguments - if len(sys.argv) < 2: - print('Error: This script requires one argument.') - print('Usage: python3 setup.py ') - print('Modes: install, change, remove') - sys.exit(1) - # Check the argument - if sys.argv[1] not in ['install', 'change', 'remove']: - print('Error: The argument must be either install, change, or remove.') - sys.exit(1) - # If the argument is 'install' start the script as root - if sys.argv[1] == 'install': - start_script_as_root() - # If the argument is 'change' check for a second argument - elif sys.argv[1] == 'change': - if len(sys.argv) != 3: - print('Error: The change script requires two arguments.') - print('Usage: python3 setup.py change ') - sys.exit(1) - else: - # Check if the profile exists - profile = sys.argv[2] - profile_path = f'{user_home}/printcfg/profiles/{profile}' - print(f"Changing to profile '{profile}'") - # If the profile is 'backup' then skip the check - if profile == 'backup': - change_profile(profile) - else: - # If the profile path does not exist, exit - if not os.path.isdir(profile_path): - print(f"Error: The profile '{profile}' does not exist.") - sys.exit(1) - else: - change_profile(profile) - # If the argument is 'remove' - elif sys.argv[1] == 'remove': - remove_printcfg() - else: - print('Error: The argument must be either install, change, or remove.') - sys.exit(1) \ No newline at end of file From f59eea75b39426d59fbe32f46aa7102b3ce270b4 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 13:10:19 -0400 Subject: [PATCH 67/81] oopsie --- scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.sh b/scripts/install.sh index 5e4dda9..cd08ea9 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -200,7 +200,7 @@ else sudo -v Date: Fri, 26 May 2023 13:11:38 -0400 Subject: [PATCH 68/81] forgot to finish --- scripts/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/install.sh b/scripts/install.sh index cd08ea9..1f88ba2 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -210,6 +210,8 @@ if [ ! -f /usr/local/bin/printcfg ]; then echo "Creating printcfg bin..." sudo ln -s $home/$repo/src/printcfg.py /usr/local/bin/printcfg sudo chmod +x /usr/local/bin/printcfg + echo -e "\e[32mprintcfg bin created successfully.\e[0m" +fi # Make all scripts in printcfg executable #chmod +x $home/$repo/scripts/*.sh From d25a75bbd348905d946a5bb036424f0892ae4839 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 13:17:56 -0400 Subject: [PATCH 69/81] fix gen_service script --- src/gen_service.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gen_service.py b/src/gen_service.py index 4cfe6e2..c2db03b 100644 --- a/src/gen_service.py +++ b/src/gen_service.py @@ -45,9 +45,9 @@ if len(sys.argv) < 2 and len(sys.argv) > 0: MODE = sys.argv[1] elif len(sys.argv) < 0: - print("Please provide the --install argument to install the service.") + print("Please provide the 'install' argument to install the service.") else: - if sys.argv[3] == "--install": + if sys.argv[3] == "install": if not PYTHON_SCRIPT: print("Please provide the path to the Python script as an argument.") sys.exit(1) @@ -100,5 +100,5 @@ os.chmod(f"/usr/local/bin/{SERVICE_NAME}", 0o755) else: - print("Please provide the --install argument to install the service.") + print("Please provide the 'install' argument to install the service.") sys.exit(1) \ No newline at end of file From 3cadb77aa7901d8d09c8830086eadcbcf8ddc9fe Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 13:20:31 -0400 Subject: [PATCH 70/81] tweak to printcfg process --- src/gen_service.py | 1 + src/printcfg.py | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/gen_service.py b/src/gen_service.py index c2db03b..aa0cbcc 100644 --- a/src/gen_service.py +++ b/src/gen_service.py @@ -60,6 +60,7 @@ After=klipper.service [Service] + Mode=oneshot User={USER} Group={GROUP} RemainAfterExit=yes diff --git a/src/printcfg.py b/src/printcfg.py index 5b498cd..641e3d3 100644 --- a/src/printcfg.py +++ b/src/printcfg.py @@ -53,11 +53,6 @@ def find_profile(path): def normal_ops(): # Run the shell script at startup subprocess.Popen(["/bin/bash", setup_script]) - print (f"Running in the background as {current_user}") - # Continuously run in the background - while True: - # Sleep for a minute - os.system("sleep 60") def generate_service(): # Define the path to the second script From 4feff151d6130768b596d79e6ad4136ba3931a35 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 13:23:54 -0400 Subject: [PATCH 71/81] make sure we exit safely --- src/printcfg.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/printcfg.py b/src/printcfg.py index 641e3d3..b203f10 100644 --- a/src/printcfg.py +++ b/src/printcfg.py @@ -53,6 +53,8 @@ def find_profile(path): def normal_ops(): # Run the shell script at startup subprocess.Popen(["/bin/bash", setup_script]) + # Exit successfully + exit(0) def generate_service(): # Define the path to the second script @@ -67,6 +69,8 @@ def generate_service(): # Start the second script as root with the current user name as the first argument command = ['sudo', 'python3', script_path, current_user, user_home, mode] subprocess.run(command) + # Exit successfully + exit(0) def change_profile(profile): # Define the path to the second script @@ -78,6 +82,8 @@ def change_profile(profile): # Start the change profile script command = ['bash', script_path, profile] subprocess.run(command) + # Exit successfully + exit(0) def update_printcfg(): # Define the path to the second script @@ -90,6 +96,9 @@ def update_printcfg(): profile = find_profile(profile_path) # Start the update script command = ['bash', script_path, profile] + subprocess.run(command) + # Exit successfully + exit(0) def remove_printcfg(): # Define the path to the second script @@ -101,6 +110,8 @@ def remove_printcfg(): # Start the second script as root with the current user name as the first argument command = ['bash', script_path] subprocess.run(command) + # Exit successfully + exit(0) if __name__ == '__main__': # Check if there are any arguments From 69d85d3fd984378bd455a494d0f5ba4ac44216da Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 May 2023 13:35:47 -0400 Subject: [PATCH 72/81] let setup script check on bin --- scripts/install.sh | 13 +++++-------- scripts/setup.sh | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 1f88ba2..7a05efe 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -206,16 +206,13 @@ else fi # Create printcfg bin -if [ ! -f /usr/local/bin/printcfg ]; then - echo "Creating printcfg bin..." - sudo ln -s $home/$repo/src/printcfg.py /usr/local/bin/printcfg - sudo chmod +x /usr/local/bin/printcfg - echo -e "\e[32mprintcfg bin created successfully.\e[0m" +if [ ! -f /usr/local/bin/$repo ]; then + echo "Creating $repo bin..." + sudo ln -s $home/$repo/src/$repo.py /usr/local/bin/$repo + sudo chmod +x /usr/local/bin/$repo + echo -e "\e[32m$repo bin created successfully.\e[0m" fi -# Make all scripts in printcfg executable -#chmod +x $home/$repo/scripts/*.sh - ### Install into klippers config ### # Check if config directory exists diff --git a/scripts/setup.sh b/scripts/setup.sh index 587145a..211fb5d 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -71,6 +71,26 @@ else fi fi +echo "Checking $repo executable..." +# Check if bin exists +if [ ! -f /usr/local/bin/$repo ] +then + echo "Creating $repo bin..." + sudo ln -s $home/$repo/src/$repo.py /usr/local/bin/$repo + sudo chmod +x /usr/local/bin/$repo + echo -e "\e[32m$repo bin created successfully.\e[0m" +else + # Check if bin is executable + if [ ! -x /usr/local/bin/$repo ] + then + echo "Making $repo bin executable..." + sudo chmod +x /usr/local/bin/$repo + echo -e "\e[32m$repo bin made executable.\e[0m" + else + echo -e "\e[32m$repo bin is up to date.\e[0m" + fi +fi + echo "Checking user config..." # Check that user config exists From 2892ee24f89ad5f41777e8df61459036763306eb Mon Sep 17 00:00:00 2001 From: Rootiest Date: Fri, 26 May 2023 13:37:53 -0400 Subject: [PATCH 73/81] Make printcfg executable --- src/printcfg.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/printcfg.py diff --git a/src/printcfg.py b/src/printcfg.py old mode 100644 new mode 100755 From 7981991396a8ecc7b9c734d2d619ab8846dc9cac Mon Sep 17 00:00:00 2001 From: rootiest Date: Mon, 29 May 2023 13:54:24 -0400 Subject: [PATCH 74/81] logging function (will be implemented throughout) --- logging.cfg | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 logging.cfg diff --git a/logging.cfg b/logging.cfg new file mode 100644 index 0000000..7a47618 --- /dev/null +++ b/logging.cfg @@ -0,0 +1,175 @@ +## Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +## +## This file is part of printcfg. +## +## printcfg is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## printcfg is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with printcfg. If not, see . + +########################################## +############### logger ################### +########################################## +## Parameters: ## +## TITLE: Title of the log entry ## +## MSG: Message of the log entry ## +## LEVEL: Level of the log entry ## +## OUTPUT: Output the log ## +## GLOBAL: Use global log ## +########################################## +########################################## +## NOTE: ## +## Although this macro is included in ## +## the printcfg package, it is not ## +## dependent on printcfg to function. ## +## ## +## This file can be included in any ## +## printer configuration and used in ## +## any macro you wish to have logging. ## +########################################## + +## This macro allows you to log messages and output them. +## The log is stored in the variable "log" and can be output with "logger output=1". +## The global log is stored in the variable "global" and can be output with "logger global=1". +## The log is stored in the format [title, message, level] where level is 0-7. + +## The log levels are as follows: +## 0: debug +## 1: info +## 2: notice +## 3: warning +## 4: error +## 5: critical +## 6: alert +## 7: emergency + +## Outputting the log will clear the log. +## The global log will not be cleared until the printer is restarted. + +## Examples: + +## logger title="Test" msg="This is a test" level="info" +## This will log the message "This is a test" with the title "Test" and the level "info". + +## logger title="Test" msg="This is a test" level="info" output=1 +## This will log the message "This is a test" with the title "Test" and the level "info" and output/clear the log. + +## logger +## This will output the log. + +## logger global=1 +## This will output the global log. + +## logger level="debug" +## This will output the log with the level "debug" and higher. + +## logger level="info" global=1 +## This will output the global log with the level "info" and higher. + + +[gcode_macro logger] +description: Log messages for debugging +variable_log: [] +variable_global: [] +gcode: + {% set title = params.TITLE|default('LOG') %} ; title parameter + {% set msg = params.MSG|default('--------') %} ; message parameter + {% set level = params.LEVEL %} ; log level parameter + {% set output = params.OUTPUT|default(0)|int %} ; output parameter + {% set only_global = params.GLOBAL|default(0)|int %} ; global parameter + # Fix level strings + {% if level|lower == "info" %} + {% set level = 1 %} + {% elif level|lower == "debug" %} + {% set level = 0 %} + {% elif level|lower == "warning" %} + {% set level = 3 %} + {% elif level|lower == "error" %} + {% set level = 4 %} + {% elif level|lower == "critical" %} + {% set level = 5 %} + {% elif level|lower == "alert" %} + {% set level = 6 %} + {% elif level|lower == "emergency" %} + {% set level = 7 %} + {% else %} + {% set level = params.LEVEL|default(1)|int %} + {% endif %} + + {% macro log_print(log=log, level=1, clear=1) -%} ; create log_print macro + {% set out = [] %} ; create output array + {% for entry in log %} ; loop through logger array + # Check level 0-7 for log level + {% if entry[2] == 7 and entry[2] >= level %} ; check if level is 7 + {% set _dummy = out.append("EMERGENCY: %s: %s" % (entry[0], entry[1])) %} ; append text to output array + {% elif entry[2] == 6 and entry[2] >= level %} ; check if level is 6 + {% set _dummy = out.append("ALERT: %s: %s" % (entry[0], entry[1])) %} ; append text to output array + {% elif entry[2] == 5 and entry[2] >= level %} ; check if level is 5 + {% set _dummy = out.append("CRITICAL: %s: %s" % (entry[0], entry[1])) %} ; append text to output array + {% elif entry[2] == 4 and entry[2] >= level %} ; check if level is 4 + {% set _dummy = out.append("ERROR: %s: %s" % (entry[0], entry[1])) %} ; append text to output array + {% elif entry[2] == 3 and entry[2] >= level %} ; check if level is 3 + {% set _dummy = out.append("WARNING:%s: %s" % (entry[0], entry[1])) %} ; append text to output array + {% elif entry[2] == 2 and entry[2] >= level %} ; check if level is 2 + {% set _dummy = out.append("NOTICE: %s: %s" % (entry[0], entry[1])) %} ; append text to output array + {% elif entry[2] == 1 and entry[2] >= level %} ; check if level is 0 + {% set _dummy = out.append("INFO: %s: %s" % (entry[0], entry[1])) %} ; append text to output array + {% elif entry[2] == 0 and entry[2] >= level %} ; check if level is 3 + {% set _dummy = out.append("DEBUG: %s: %s" % (entry[0], entry[1])) %} ; append text to output array + {% endif %} + {% endfor %} + {% if clear == 1 %} + {% set _dummy = log.clear() %} ; clear logger array + {% endif %} + {% if out %} + {action_respond_info(out|join("\n"))} ; output all variables + {% else %} + {action_respond_info("No log entries found.")} ; no log to output + {% endif %} + {% endmacro -%} + + {% macro log_entry(title='LOG', msg='--------', level=0, log=log) -%} ; create logger macro + {% set entry = [title, msg, level] %} ; cocatenate title and message + {% set _dummy = log.append(entry) %} ; append text to logger array + {% endmacro -%} + + {% if params.TITLE is defined or params.MSG is defined %} ; check if title and msg are not empty + {% if only_global != 1 %} + {% if level == -1 %} + {% set level = 0 %} + {% endif %} + { log_entry(title=title, msg=msg, level=level, log=log) } ; call logger macro + {% endif %} + { log_entry(title=title, msg=msg, level=level, log=global)} ; call logger macro for global log + {% if output == true %} ; check if output is true + { log_print(log=log, level=level) } ; output log + {% endif %} + {% else %} + {% if level == -1 %} + {% set level = 1 %} + {% endif %} + {% if only_global != 1 %} + { log_print(log=log, level=level) } ; output log + {% else %} + { log_print(log=global, level=level, clear=0) } ; output log + {% endif %} + {% endif %} + +[gcode_macro TEST_LOGGER] +gcode: + {% set config = printer.configfile.settings %} ; get realtime configfile settings + {% set my_var = params.MY_VAR|default('') %} ; example parameter + logger title="Debugger" + logger msg="TEST_LOGGER" level=0 ; add macro name to log + logger title="Variable" msg={my_var} level=1 ; add variable to log + logger title="Configured Z-min" msg="{config.stepper_z.position_min}" level=2 ; add config value to log + logger title="Configured Z-max" msg="{config.stepper_z.position_max}" level=3 ; add config value to log + logger title="Debugging" msg="completed successfully" level=7 output=1 ; add debugging status to log and output log \ No newline at end of file From 65a3c50ac5435e9b07449af986d432b136f62e31 Mon Sep 17 00:00:00 2001 From: rootiest Date: Tue, 30 May 2023 18:26:22 -0400 Subject: [PATCH 75/81] use regex in search_replace --- scripts/install.sh | 2 +- scripts/patch.sh | 2 +- scripts/search_replace.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 7a05efe..ee82e06 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -315,7 +315,7 @@ fi # Set branch in moonraker-printcfg.conf echo "Setting branch in moonraker config..." # Define search pattern -branch_pattern="primary_branch:" +branch_pattern="primary_branch:*" # Set branch to current branch python3 $home/$repo/scripts/search_replace.py "$branch_pattern" "$branch_pattern $branch" "$config/moonraker-$repo.conf" diff --git a/scripts/patch.sh b/scripts/patch.sh index cce01cb..572b4f6 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -60,7 +60,7 @@ profile_pattern="# Profile:(.*)" patch_pattern="# Patch:(.*)" uconfig_pattern_old="[include $repo/user_config.cfg]" uconfig_pattern_new="[include user_config.cfg]" -ver_patch="# Patch:" +ver_patch="# Patch: *" # Check if any parameters were provided if [ $# -eq 0 ] diff --git a/scripts/search_replace.py b/scripts/search_replace.py index 2dc9dfa..c3da75f 100644 --- a/scripts/search_replace.py +++ b/scripts/search_replace.py @@ -24,8 +24,8 @@ # Usage: python3 search_replace.py -import os import sys +import re def search_and_replace(search_text, replace_text, file_name): """Searches for the line containing the search_text and replaces the whole line with the replace_text and saves the updated file over the original. @@ -44,7 +44,7 @@ def search_and_replace(search_text, replace_text, file_name): found = False for i, line in enumerate(lines): - if search_text in line: + if re.search(search_text, line): lines[i] = replace_text + '\n' found = True break From 0f0ac7ef8443f71d9c932cea284a9625e441c7f4 Mon Sep 17 00:00:00 2001 From: rootiest Date: Tue, 30 May 2023 18:32:46 -0400 Subject: [PATCH 76/81] Initial implementation of debug logging system This will be used throughout the macros to log data about: - actions - variables - performance - and more! This feature can be used for debugging purposes or to trace the cause of any issues you may experience --- print_macros.cfg | 161 ++++++++++++++++--- profiles/default/patches/4.0.0/vars.patch | 14 ++ profiles/hephaestus/patches/4.0.0/vars.patch | 14 ++ 3 files changed, 169 insertions(+), 20 deletions(-) diff --git a/print_macros.cfg b/print_macros.cfg index 5da4a1b..0d25ad0 100644 --- a/print_macros.cfg +++ b/print_macros.cfg @@ -20,6 +20,8 @@ ## Version 4.0.0 2023-5-26 ## ##################################### +[include logging.cfg] + ################################ ######### START_PRINT ########## ################################ @@ -85,19 +87,21 @@ gcode: [gcode_macro PREP_CHAMBER] gcode: {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables - {% if printcfg.chamber_temp != 0 %} ; if chamber temp is set - M{printcfg.output} Preheating chamber ; status feedback - {% if printcfg.led_status == True %} ; if using LED status - {printcfg.status_heat} ; LED feedback - {% endif %} - {% if printcfg.chamber_type == 'temperature_fan' %} ; if using a temperature_fan chamber sensor - SET_TEMPERATURE_FAN_TARGET temperature_fan={printcfg.chamber_name} target={printcfg.chamber_temp} ; set chamber temp - {% elif printcfg.chamber_type == 'heater_generic' %} ; if using a heater_generic chamber sensor - SET_HEATER_TEMPERATURE HEATER={printcfg.chamber_name} TARGET={printcfg.chamber_temp} ; set chamber temp - {% endif %} - {% if printcfg.heat_soak == True %} ; if heat soak is enabled - SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=heat_soak_complete VALUE=0 ; set heat soak incomplete - HEAT_SOAK ; start heat soak + {% if printcfg.chamber == True %} ; if using a chamber + {% if printcfg.chamber_temp != 0 %} ; if chamber temp is set + M{printcfg.output} Preheating chamber ; status feedback + {% if printcfg.led_status == True %} ; if using LED status + {printcfg.status_heat} ; LED feedback + {% endif %} + {% if printcfg.chamber_type == 'temperature_fan' %} ; if using a temperature_fan chamber sensor + SET_TEMPERATURE_FAN_TARGET temperature_fan={printcfg.chamber_name} target={printcfg.chamber_temp} ; set chamber temp + {% elif printcfg.chamber_type == 'heater_generic' %} ; if using a heater_generic chamber sensor + SET_HEATER_TEMPERATURE HEATER={printcfg.chamber_name} TARGET={printcfg.chamber_temp} ; set chamber temp + {% endif %} + {% if printcfg.heat_soak == True %} ; if heat soak is enabled + SET_GCODE_VARIABLE MACRO=_printcfg VARIABLE=heat_soak_complete VALUE=0 ; set heat soak incomplete + HEAT_SOAK ; start heat soak + {% endif %} {% endif %} {% endif %} @@ -223,7 +227,18 @@ gcode: {printcfg.clean_macro} ; clean nozzle {% endif %} M400 ; - ## Z-tilt or QGL + ## Z Calibration Functions + {% if printcfg.auto_z_calibrate == True %} ; if using auto z-calibration + {% if config.z_calibration is defined %} ; if z-calibration is configured + M{printcfg.output} Calibrating Z ; status feedback + {% if printcfg.led_status == True %} ; if using LED status + {printcfg.status_calibrating_z} ; LED feedback + {% endif %} + CALIBRATE_Z ; adjust z-calibration + {% else %} ; if z-calibration not configured + M{printcfg.error_output} Z_calibration not configured! + {% endif %} + {% endif %} {% if printcfg.z_tilt == True %} ; if using z-tilt {% if config.z_tilt is defined %} ; if z-tilt is configured M{printcfg.output} Calibrating Z ; status feedback @@ -1483,19 +1498,28 @@ gcode: variable_debounce: 0 ; <-- DO NOT CHANGE THIS VARIABLE variable_state: 0 ; <-- DO NOT CHANGE THIS VARIABLE variable_bounce: 0 ; <-- DO NOT CHANGE THIS VARIABLE +variable_last_door: 0 ; <-- DO NOT CHANGE THIS VARIABLE +variable_last_state: 0 ; <-- DO NOT CHANGE THIS VARIABLE [gcode_macro _open_door] description: Door is opened +variable_door: 0 gcode: {% set doorcfg = printer['gcode_macro _door_cfg'] %} ; get doorcfg variables {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables + {% set door = params.DOOR|default(0) %} ; get door number + SET_GCODE_VARIABLE MACRO=_open_door VARIABLE=door VALUE={door} ; set door {% if doorcfg.debounce == 0 %} ; check debounce - M{printcfg.output|int} Door Open ; status output + M{printcfg.output|int} Door {door}: Open ; status output {printcfg.status_door_open} ; open door LEDs - {printcfg.door_open_gcode} ; open door custom macro + {% if custom_macro == True %} ; check for custom macro + {printer['gcode_macro _printcfg'][door_macro]} ; run custom macro + {% endif %} SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=debounce VALUE=1 ; set debounce state SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=state VALUE=1 ; set door state SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=1 ; set door bounce + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=last_door VALUE={door} ; set last door + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=last_state VALUE=open ; set last state UPDATE_DELAYED_GCODE ID=door_debounce DURATION={(printcfg.door_debounce / 1000)|float} ; set debounce timer {% else %} ; bounced SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=1 ; set door bounce @@ -1503,50 +1527,147 @@ gcode: [gcode_macro _close_door] description: Door is closed +variable_door: 0 gcode: {% set doorcfg = printer['gcode_macro _door_cfg'] %} ; get doorcfg variables {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables + {% set door = params.DOOR|default(0) %} ; get door number + SET_GCODE_VARIABLE MACRO=_close_door VARIABLE=door VALUE={door} ; set door + {% set door_macro = "door" + door|string + "_closed" %} + {% set custom_macro = True if printer['gcode_macro _printcfg'][door_macro] is defined else False %} {% if doorcfg.debounce == 0 %} ; check debounce - M{printcfg.output|int} Door Closed ; status output + M{printcfg.output|int} Door {door}: Closed ; status output {% if printer.virtual_sdcard.is_active == True %} ; printing state {printcfg.status_printing} ; closed door printing LEDs {% else %} ; idle state {printcfg.status_ready} ; closed door idle LEDs {% endif %} - {printcfg.door_closed_gcode} ; closed door custom macro + {% if custom_macro == True %} ; check for custom macro + {printer['gcode_macro _printcfg'][door_macro]} ; run custom macro + {% endif %} SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=debounce VALUE=1 ; set debounce state SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=state VALUE=0 ; set door state SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=0 ; set door bounce + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=last_door VALUE={door} ; set last door + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=last_state VALUE=closed ; set last state UPDATE_DELAYED_GCODE ID=door_debounce DURATION={(printcfg.door_debounce / 1000)|float} ; set debounce timer {% else %} ; bounced SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=0 ; set door bounce {% endif %} + [delayed_gcode door_debounce] gcode: {% set doorcfg = printer['gcode_macro _door_cfg'] %} ; get doorcfg variables {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables + {% set door = printer['gcode_macro _doorcfg'].last_door %} ; get door number + {% set state = printer['gcode_macro _doorcfg'].last_state %} ; get door state + {% set door_macro = "door" + door|string + "_" + state|string %} ; get door macro {% if doorcfg.bounce != doorcfg.state %} ; check if a bounce ocurred {% if doorcfg.bounce == 1 %} ; bounced open SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=state VALUE=1 ; set door state SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=1 ; set door bounce + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=last_state VALUE=open ; set last state M{printcfg.output|int} Door Open ; status output {printcfg.status_door_open} ; open door LEDs - {printcfg.door_open_gcode} ; open door custom macro + {% if custom_macro == True %} ; check for custom macro + {printer['gcode_macro _printcfg'][door_macro]} ; run custom macro + {% endif %} {% else %} ; bounced closed SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=state VALUE=0 ; set door state SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=bounce VALUE=0 ; set door bounce + SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=last_state VALUE=closed ; set last state M{printcfg.output|int} Door Closed ; status output {% if printer.virtual_sdcard.is_active == True %} ; printing state {printcfg.status_printing} ; closed door printing LEDs {% else %} ; idle state {printcfg.status_ready} ; closed door idle LEDs {% endif %} - {printcfg.door_closed_gcode} ; closed door custom macro + {% if custom_macro == True %} ; check for custom macro + {printer['gcode_macro _printcfg'][door_macro]} ; run custom macro + {% endif %} {% endif %} {% endif %} SET_GCODE_VARIABLE MACRO=_door_cfg VARIABLE=debounce VALUE=0 ; reset debounce state +################################ +######### SIMPLE_PAUSE ######### +################################ +## This macro will determine the correct command to pause the print without any additional actions +## Example usage: +## # Pause the print +## SIMPLE_PAUSE + +## Pause the print +[gcode_macro SIMPLE_PAUSE] +description: Pause the print without any additional actions +gcode: + {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables + {% set config = printer.configfile.settings %} ; get realtime configfile settings + {% set dbg_msg = "Debugging: \nMacro: SIMPLE_PAUSE\n" %} ; set debug message"} + {% if printer['gcode_macro _CLIENT_VARIABLE'] is defined %} ; get web client variables + {% set client = printer['gcode_macro _CLIENT_VARIABLE'] %} ; get web client variables + {% set dbg_msg = dbg_msg + "Client: True\n" %} ; set debug message + {% endif %} + {% if config.pause_resume is not defined %} ; verify pause_resume feature is enabled + M{printcfg.output|int} Pause/Resume feature is not enabled + {% set dbg_msg = dbg_msg + "Pause/Resume: False\n" %} ; set debug message + {% else %} + {% set dbg_msg = dbg_msg + "Pause/Resume: True\n" %} ; set debug message + {% set pause_macro = 'gcode_macro ' + printcfg.pause_macro|string %} + {% set pause_base = 'gcode_macro ' + printcfg.pause_no_park|string %} + ## Verify macros exist + {% if printer[pause_macro] is not defined %} + M{printcfg.output|int} Pause macro does not exist + {% set dbg_msg = dbg_msg + "Pause Macro: False\n" %} ; set debug message + {% elif printer[pause_base] is not defined %} + M{printcfg.output|int} Pause without parking macro does not exist + {% set dbg_msg = dbg_msg + "Pause No Park Macro: False\n" %} ; set debug message + ## Set flag to use alternative options + {% set can_pause = False %} + {% endif %} + {% if not can_pause %} + {% set pause_base = 'gcode_macro ' + printcfg.pause|string + '_BASE' %} + {% if printer[pause_base] is defined %} + {% set pause_base = printcfg.pause|string + '_BASE' %} + {% set dbg_msg = dbg_msg + printcfg.pause|string + "_BASE Macro: True\n" %} ; set debug message + {% set can_pause = True %} + {% else %} + {% set pause_base = 'gcode_macro ' + printcfg.pause|string + '.0' %} + {% if printer[pause_base] is defined %} + {% set pause_base = printcfg.pause|string + '.0' %} + {% set dbg_msg = dbg_msg + printcfg.pause|string + ".0 Macro: True\n" %} ; set debug message + {% set can_pause = True %} + {% else %} + M{printcfg.output|int} No useable macro found, defaulting to 'PAUSE' + {% set pause_base = 'PAUSE' %} + {% set dbg_msg = dbg_msg + "Default Macro: True\n" %} ; set debug message + {% set can_pause = True %} + {% endif %} + {% endif %} + {% endif %} + {% set dbg_msg = dbg_msg + "Can Pause: " + can_pause|string + "\n" %} ; set debug message + {% set dbg_msg = dbg_msg + "Chosen macro: " + pause_base|string + "\n" %} ; set debug message + {% if can_pause %} + {% if printer.pause_resume.is_paused %} + M{printcfg.output|int} Already paused + {% set dbg_msg = dbg_msg + "Already Paused\n" %} ; set debug message + {% else %} + {% if "xyz" not in printer.toolhead.homed_axes %} + M{printcfg.output|int} Cannot pause while toolhead is not homed + {% set dbg_msg = dbg_msg + "Toolhead not homed\n" %} ; set debug message + {% else %} + {% set dbg_msg = dbg_msg + "Pause command fired: " + pause_base %} ; set debug message + {pause_base} ; pause print + {% endif %} + {% endif %} + {% endif %} + {% endif %} + {% if printcfg.debugging == True %} + {% set dbg_msg = dbg_msg + "Debugging: True\n" %} ; set debug message + M{printcfg.debug_output|int} {dbg_msg|string} + {% endif %} + ################################ ##### STORE_POSITION_MODE ###### ################################ diff --git a/profiles/default/patches/4.0.0/vars.patch b/profiles/default/patches/4.0.0/vars.patch index 0e2f7c1..b0c9749 100644 --- a/profiles/default/patches/4.0.0/vars.patch +++ b/profiles/default/patches/4.0.0/vars.patch @@ -8,3 +8,17 @@ variable_door_debounce: 250 ; Debounce time for door switch (ms) variable_status_door_open: '_STATUS_BRIGHT' ; Status to show when door is open variable_door_open_gcode: 'M116' ; Custom macro for open doors (set to 'M116' to disable) variable_door_closed_gcode: 'M116' ; Custom macro for closed doors (set to 'M116' to disable) + +## Z Calibration Variables +variable_z_calibrate: False + +## Default Offset +variable_offset_store: False ; If True, the z-offset will be saved to the config at the end of a print + +## Debugging Variables +## NOTE: These variables configure debugging +## behavior. They are used to enable +## or disable debugging output and +## to define the debug output level. +variable_debugging: True +variable_debug_level: 0 diff --git a/profiles/hephaestus/patches/4.0.0/vars.patch b/profiles/hephaestus/patches/4.0.0/vars.patch index 281f28e..2e184a3 100644 --- a/profiles/hephaestus/patches/4.0.0/vars.patch +++ b/profiles/hephaestus/patches/4.0.0/vars.patch @@ -8,3 +8,17 @@ variable_door_debounce: 250 ; Debounce time for door switch (ms) variable_status_door_open: '_STATUS_BRIGHT' ; Status to show when door is open variable_door_open_gcode: 'M116' ; Custom macro for open doors (set to 'M116' to disable) variable_door_closed_gcode: 'M116' ; Custom macro for closed doors (set to 'M116' to disable) + +## Z Calibration Variables +variable_z_calibrate: False + +## Default Offset +variable_offset_store: False ; If True, the z-offset will be saved to the config at the end of a print + +## Debugging Variables +## NOTE: These variables configure debugging +## behavior. They are used to enable +## or disable debugging output and +## to define the debug output level. +variable_debugging: True +variable_debug_level: 0 From d22e991a676c2f7cc5cb19dd40de5104a2228051 Mon Sep 17 00:00:00 2001 From: rootiest Date: Wed, 31 May 2023 20:32:29 -0400 Subject: [PATCH 77/81] some logging stuff and python cleanup --- logging.cfg | 4 +- scripts/log_logger.py | 70 +++++++++++++++++ scripts/search_replace.py | 81 +++++++++++++++++--- src/printcfg.py | 155 ++++++++++++++++++++++++++++---------- src/requirements.txt | 3 +- 5 files changed, 260 insertions(+), 53 deletions(-) create mode 100644 scripts/log_logger.py diff --git a/logging.cfg b/logging.cfg index 7a47618..cdfed46 100644 --- a/logging.cfg +++ b/logging.cfg @@ -79,6 +79,7 @@ description: Log messages for debugging variable_log: [] variable_global: [] +variable_number: 0 gcode: {% set title = params.TITLE|default('LOG') %} ; title parameter {% set msg = params.MSG|default('--------') %} ; message parameter @@ -137,7 +138,8 @@ gcode: {% endmacro -%} {% macro log_entry(title='LOG', msg='--------', level=0, log=log) -%} ; create logger macro - {% set entry = [title, msg, level] %} ; cocatenate title and message + {% set entry = [title, msg, level, number] %} ; create entry array + {% set number = number + 1 %} ; increment number {% set _dummy = log.append(entry) %} ; append text to logger array {% endmacro -%} diff --git a/scripts/log_logger.py b/scripts/log_logger.py new file mode 100644 index 0000000..8d666f4 --- /dev/null +++ b/scripts/log_logger.py @@ -0,0 +1,70 @@ +# Copyright (C) 2023 Chris Laprade (chris@rootiest.com) +# +# This file is part of printcfg. +# +# printcfg is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# printcfg is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with printcfg. If not, see . + +import sys +from watchdog.observers import Observer +from watchdog.events import FileSystemEventHandler + +class LogFileHandler(FileSystemEventHandler): + def __init__(self, watched_file, output_file): + self.watched_file = watched_file + self.output_file = output_file + self.previous_line = None + + def on_modified(self, event): + if event.src_path == self.watched_file: + try: + with open(self.watched_file, 'r') as f: + current_line = f.readline().strip() + log_index = current_line.find("log = ") + if log_index != -1: + log_text = current_line[log_index + len("log = "):] + if log_text != self.previous_line: + with open(self.output_file, 'a') as output: + output.write(log_text + '\n') + self.previous_line = log_text + except IOError as e: + print("IOError: " + e.strerror) + +# Example usage: +watched_file = 'variables.cfg' +output_file = 'printcfg.log' + +# Check for arguments: +if len(sys.argv) > 1: + if sys.argv[1] == '-h' or sys.argv[1] == '--help': + print('Usage: python3 log_logger.py ') + sys.exit(0) + else: + if len(sys.argv) > 2: + watched_file = sys.argv[1] + output_file = sys.argv[2] + + + +event_handler = LogFileHandler(watched_file, output_file) +observer = Observer() +observer.schedule(event_handler, path='.', recursive=False) +observer.start() + +try: + while True: + pass +except KeyboardInterrupt: + observer.stop() + +observer.join() diff --git a/scripts/search_replace.py b/scripts/search_replace.py index c3da75f..6364021 100644 --- a/scripts/search_replace.py +++ b/scripts/search_replace.py @@ -1,33 +1,59 @@ #!/usr/bin/env python3 # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) -# +# # This file is part of printcfg. -# +# # printcfg is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # printcfg is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with printcfg. If not, see . #!/usr/bin/env python3 -# This script searches for a line containing a specific text and replaces the whole line with a new text. -# If the text is not found, the new text is added to the beginning of the file. - -# Usage: python3 search_replace.py +# This code searches for a string in a file and replaces the whole line containing the string with a different string. +# The search is case sensitive. +# It will add the line if it does not exist. +# It will overwrite the file with the new contents. +# The file must already exist. +# +# Arguments: +# search_text: The text to search for. +# replace_text: The text to replace the search_text with. +# file_name: The name of the file to search and replace. +# +# Returns: +# A status indicating whether the change was successful. +# +# Usage: +# python3 search_replace.py +# +# Example: +# python3 search_replace.py "version" "version: 1.0.0" "patch_notes.txt" import sys import re +import logging + +logger: logging.Logger = logging.getLogger(__name__) + +# Set the logging level +logger.setLevel(logging.DEBUG) +formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") +handler = logging.StreamHandler(sys.stdout) +handler.setFormatter(formatter) +logger.addHandler(handler) + -def search_and_replace(search_text, replace_text, file_name): +def search_and_replace(search_text: str, replace_text: str, file_name: str) -> bool: """Searches for the line containing the search_text and replaces the whole line with the replace_text and saves the updated file over the original. Args: @@ -39,24 +65,59 @@ def search_and_replace(search_text, replace_text, file_name): A status indicating whether the change was successful. """ + # Log the input + logger.debug( + "search_and_replace() called with: search_text=%s, replace_text=%s, file_name=%s", + search_text, + replace_text, + file_name, + ) + + # Make sure the inputs are valid + if search_text is None or replace_text is None or file_name is None: + logger.error( + "search_and_replace() failed due to invalid input: search_text=%s, replace_text=%s, file_name=%s", + search_text, + replace_text, + file_name, + ) + return False + + # Open the file + logger.debug("search_and_replace() opened the file %s", file_name) with open(file_name, "r") as f: lines = f.readlines() + # Search the file for the search_text found = False for i, line in enumerate(lines): if re.search(search_text, line): - lines[i] = replace_text + '\n' + lines[i] = replace_text + "\n" found = True break + # If the search_text wasn't found, insert the replace_text at the top if not found: lines.insert(0, replace_text + "\n") + # Write the file + logger.debug("search_and_replace() wrote the file %s", file_name) with open(file_name, "w") as f: f.writelines(lines) + return True return found + +# Check the number of arguments +if len(sys.argv) != 4: + # Print the usage + print("Usage:") + print(" python3 search_replace.py ") + print("Example:") + print(' python3 search_replace.py "version" "version: 1.0.0" "patch_notes.txt"') + sys.exit(1) + search_text = sys.argv[1] replace_text = sys.argv[2] file_name = sys.argv[3] diff --git a/src/printcfg.py b/src/printcfg.py index b203f10..354fee8 100755 --- a/src/printcfg.py +++ b/src/printcfg.py @@ -1,18 +1,18 @@ #!/usr/bin/env python3 # Copyright (C) 2023 Chris Laprade (chris@rootiest.com) -# +# # This file is part of printcfg. -# +# # printcfg is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # printcfg is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with printcfg. If not, see . @@ -32,62 +32,118 @@ import sys import getpass import subprocess +import logging +logger: logging.Logger = logging.getLogger(__name__) + +# Set the logging level +logger.setLevel(logging.DEBUG) +formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") +handler = logging.StreamHandler(sys.stdout) +handler.setFormatter(formatter) +logger.addHandler(handler) # Set the repo name -REPO = 'printcfg' +REPO = "printcfg" # Get the current user name current_user = getpass.getuser() -user_home = os.path.expanduser('~') +user_home = os.path.expanduser("~") profile_path = f"{user_home}/printer_data/user_profile.cfg" setup_script = f"{user_home}/printcfg/scripts/setup.sh" + def find_profile(path): + logger.debug("Searching for profile name in file: {}".format(path)) # Find the profile name (Eg: '# Profile: default' = 'default') - with open(path, 'r') as file: - for line in file: - if line.startswith('# Profile: '): - # Return the profile name - return line[11:].strip() + with open(path, "r") as file: + for line in file: + if line.startswith("# Profile: "): + logger.debug("Found profile name: {}".format(line[11:].strip())) + # Return the profile name + return line[11:].strip() + + # If no profile was found, raise an error + logger.error("Profile not found in file: {}".format(path)) + raise ValueError("Profile not found in file: {}".format(path)) + def normal_ops(): - # Run the shell script at startup - subprocess.Popen(["/bin/bash", setup_script]) + logger.info("Starting normal operations...") + try: + # Run the shell script at startup + subprocess.Popen(["/bin/bash", setup_script]) + logger.info("Startup script complete.") + except Exception as e: + # Log the error + logger.error("Error running startup script: {}".format(str(e))) + # Exit with error + exit(1) # Exit successfully + logger.info("Startup script complete, exiting.") exit(0) + def generate_service(): + logger.info("Generating service...") # Define the path to the second script - script_dir = f'{user_home}/{REPO}/' + script_dir = f"{user_home}/{REPO}/" + logger.debug("Script directory: {}".format(script_dir)) mode = sys.argv[1] + logger.debug("Mode: {}".format(mode)) # Define the path to the second script - script_path = f'{script_dir}/src/gen_service.py' + script_path = f"{script_dir}/src/gen_service.py" + logger.debug("Script path: {}".format(script_path)) # Check if the second script exists if not os.path.isfile(script_path): print(f"Error: The script '{script_path}' does not exist.") + logger.error("Error: The script '{}' does not exist.".format(script_path)) return # Start the second script as root with the current user name as the first argument - command = ['sudo', 'python3', script_path, current_user, user_home, mode] - subprocess.run(command) + command = ["sudo", "python3", script_path, current_user, user_home, mode] + logger.debug("Executing command: {}".format(command)) + print(f"Executing command: {command}") + try: + result = subprocess.run(command, capture_output=True) + except subprocess.CalledProcessError as e: + + logger.debug("Command output: {}".format(result.stdout.decode("utf-8"))) + if result.returncode != 0: + print(f"Error: The command '{command}' failed with code {result.returncode}.") + logger.error("Error: The command '{}' failed with code {}.".format(command, result.returncode)) + print(f"Output from command: {result.stdout.decode('utf-8')}") + print(f"Error from command: {result.stderr.decode('utf-8')}") + return # Exit successfully + logger.info("Service generated successfully.") exit(0) + def change_profile(profile): # Define the path to the second script - script_path = f'{user_home}/{REPO}/scripts/change_profile.sh' + script_path = f"{user_home}/{REPO}/scripts/change_profile.sh" + logger.debug("Script path: {}".format(script_path)) # Check if the second script exists if not os.path.isfile(script_path): print(f"Error: The script '{script_path}' does not exist.") + logger.error("Error: The script '{}' does not exist.".format(script_path)) return # Start the change profile script - command = ['bash', script_path, profile] - subprocess.run(command) + command = ["bash", script_path, profile] + logger.debug("Executing command: {}".format(command)) + try: + subprocess.run(command, check=True) + except subprocess.CalledProcessError as e: + print("Error: The subprocess returned an error.") + print(e.stderr) + logger.error("Error: The subprocess returned an error: {}".format(e.stderr)) # Exit successfully + logger.info("Profile changed successfully.") exit(0) - + + def update_printcfg(): # Define the path to the second script - script_path = f'{user_home}/{REPO}/scripts/install.sh' + script_path = f"{user_home}/{REPO}/scripts/install.sh" # Check if the second script exists if not os.path.isfile(script_path): print(f"Error: The script '{script_path}' does not exist.") @@ -95,49 +151,66 @@ def update_printcfg(): # Find the current profile profile = find_profile(profile_path) # Start the update script - command = ['bash', script_path, profile] - subprocess.run(command) + command = ["bash", script_path, profile] + logger.debug("Executing command: {}".format(command)) + try: + subprocess.run(command) + except subprocess.CalledProcessError as e: + print("Error: The subprocess returned an error.") + print(e.stderr) + logger.error("Error: The subprocess returned an error: {}".format(e.stderr)) # Exit successfully + logger.info("Update complete.") exit(0) - + + def remove_printcfg(): # Define the path to the second script - script_path = f'{user_home}/{REPO}/scripts/remove_{REPO}.sh' + script_path = f"{user_home}/{REPO}/scripts/remove_{REPO}.sh" + logger.debug("Script path: {}".format(script_path)) # Check if the second script exists if not os.path.isfile(script_path): print(f"Error: The script '{script_path}' does not exist.") + logger.error("Error: The script '{}' does not exist.".format(script_path)) return # Start the second script as root with the current user name as the first argument - command = ['bash', script_path] - subprocess.run(command) + command = ["bash", script_path] + logger.debug("Executing command: {}".format(command)) + try: + subprocess.run(command) + except subprocess.CalledProcessError as e: + pr # Exit successfully exit(0) -if __name__ == '__main__': + +if __name__ == "__main__": # Check if there are any arguments if len(sys.argv) < 2: normal_ops() sys.exit(1) # Check the argument - if sys.argv[1] not in ['install', 'change', 'remove', 'update', 'default']: - print('Error: The argument must be either install, change, remove, update, or default.') + if sys.argv[1] not in ["install", "change", "remove", "update", "default"]: + print( + "Error: The argument must be either install, change, remove, update, or default." + ) sys.exit(1) # If the argument is 'install' start the script as root - if sys.argv[1] == 'install': + if sys.argv[1] == "install": generate_service() # If the argument is 'change' check for a second argument - elif sys.argv[1] == 'change': + elif sys.argv[1] == "change": if len(sys.argv) != 3: - print('Error: The change script requires two arguments.') - print(f'Usage: python3 {REPO}.py change ') + print("Error: The change script requires two arguments.") + print(f"Usage: python3 {REPO}.py change ") sys.exit(1) else: # Check if the profile exists profile = sys.argv[2] - profile_path = f'{user_home}/{REPO}/profiles/{profile}' + profile_path = f"{user_home}/{REPO}/profiles/{profile}" print(f"Changing to profile '{profile}'") # If the profile is 'backup' then skip the check - if profile == 'backup': + if profile == "backup": change_profile(profile) else: # If the profile path does not exist, exit @@ -147,10 +220,10 @@ def remove_printcfg(): else: change_profile(profile) # If the argument is 'remove' - elif sys.argv[1] == 'remove': + elif sys.argv[1] == "remove": remove_printcfg() - elif sys.argv[1] == 'update': + elif sys.argv[1] == "update": update_printcfg() - + else: - normal_ops() \ No newline at end of file + normal_ops() diff --git a/src/requirements.txt b/src/requirements.txt index 92d6213..ff8631f 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,3 +1,4 @@ python-apt==2.2.1 python-dateutil==2.8.2 -requests==2.30.0 \ No newline at end of file +requests==2.30.0 +watchdog=3.3.0 \ No newline at end of file From 3b524031f9c60333ede613661a39ae85ffee6460 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 1 Jun 2023 04:29:30 -0400 Subject: [PATCH 78/81] update default profile --- profiles/default/variables.cfg | 56 ++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/profiles/default/variables.cfg b/profiles/default/variables.cfg index c13c218..21615f5 100644 --- a/profiles/default/variables.cfg +++ b/profiles/default/variables.cfg @@ -46,7 +46,10 @@ variable_extruder_pretemp: 0 variable_bed_temp: 60 ## Default Offset -variable_z_offset: 0.0 +variable_z_offset: 0.0 ; Default z-offset adjustment to be applied to prints +variable_start_offset: False ; If True, the z-offset will be applied at the start of the print +variable_end_offset: True ; If True, the z-offset will be removed at the end of the print +variable_offset_store: False ; If True, the z-offset will be saved to the config at the end of a print ## Chamber Variables variable_chamber_type: 'none' @@ -55,12 +58,12 @@ variable_chamber_temp: 35 variable_chamber_time: 10 ## Soaking Variables -variable_heat_soak: True +variable_heat_soak: False variable_time_soak: False variable_temp_soak: True ## Bed Fan Variables -variable_bed_fan: True +variable_bed_fan: False variable_bed_fan_fast: 'BEDFANSFAST' variable_bed_fan_slow: 'BEDFANSSLOW' variable_bed_fan_stop: 'BEDFANSOFF' @@ -74,13 +77,13 @@ variable_soak_idle_time: 18000 ## Idle Action Variables variable_idle_extruder: True variable_idle_bed: True -variable_idle_chamber: True +variable_idle_chamber: False variable_idle_steppers: True -variable_idle_power: True +variable_idle_power: False ## Parking Variables variable_park_x: 25 -variable_park_y: 300 +variable_park_y: 25 variable_park_z: 50 variable_park_zrel: 10 variable_park_zmin: 50 @@ -89,8 +92,8 @@ variable_park_extrude: 1.0 variable_park_base: '_TOOLHEAD_PARK_PAUSE_CANCEL' ## Preheat Parking Variables -variable_preheat_x: 145 -variable_preheat_y: 153 +variable_preheat_x: 10 +variable_preheat_y: 10 variable_preheat_z: 10 ## Maintenance Parking Variables @@ -99,8 +102,8 @@ variable_maint_y: -1 variable_maint_z: -1 ## Homing Variables -variable_home_x: 145 -variable_home_y: 153 +variable_home_x: 112 +variable_home_y: 112 variable_pre_home_z: 2.0 ; Enable force_move to use this feature variable_post_home_z: 10 variable_home_travel_speed: 10000 @@ -121,14 +124,12 @@ variable_pause_no_park: 'PAUSE_BASE' ## Speed Variables variable_default_speed_factor: 100 -variable_start_offset: False variable_start_speed_factor: False -variable_end_offset: True variable_end_speed_factor: True variable_travel_speed: 300 ## Filter Variables -variable_nevermore: True +variable_nevermore: False variable_nevermore_name: 'nevermore' variable_nevermore_type: 'fan_generic' variable_nevermore_speed: 1.0 @@ -155,8 +156,9 @@ variable_attach_macro: 'Attach_Probe_Lock' variable_dock_macro: 'Dock_Probe_Unlock' ## Z Calibration Variables +variable_z_calibrate: False variable_z_tilt: False -variable_qgl: True +variable_qgl: False ## Meshing Variables variable_bed_mesh: True @@ -168,14 +170,14 @@ variable_mesh_fuzz_min: 0 # If enabled, the minimum amount in variable_mesh_fuzz_max: 4 # If enabled, the maximum amount in mm a probe point can be randomized, default is 4. ## Nozzle Cleaning Variables -variable_cleaning: True +variable_cleaning: False variable_clean_probe: True variable_clean_end: False variable_post_clean_home: False variable_clean_m600: True variable_clean_macro: 'CLEAN_NOZZLE' variable_clean_x: 50 -variable_clean_y: 303 +variable_clean_y: 50 variable_clean_z: 5 variable_clean_wipe_axis: 'X' variable_clean_wipe_dist: 50 @@ -202,7 +204,7 @@ variable_purge_debug: False ## End Gcode Variables variable_end_print: True -variable_end_retract: True +variable_end_retract: False variable_end_retract_length: 15 variable_end_retract_speed: 60 variable_power_off: False @@ -232,7 +234,7 @@ variable_output: 118 # Select 116, 117, or 118 to specify out variable_error_output: 118 ## LED Status Variables -variable_led_status: True # Use LED Status macros such as on the stealthburner +variable_led_status: False # Use LED Status macros such as on the stealthburner variable_status_ready: '_STATUS_READY' variable_status_busy: '_STATUS_BUSY' variable_status_preprint: '_STATUS_PREPRINT' @@ -249,7 +251,7 @@ variable_status_error: '_STATUS_ERROR' variable_status_printing: '_STATUS_PRINTING' ## Audio Status Variables -variable_audio_status: True # Use audio feedback macros +variable_audio_status: False # Use audio feedback macros variable_start_audio: '_PRINT_START_TUNE' variable_error_audio: '_GAME_OVER_TUNE' variable_success_audio: '_MARIO_TUNE' @@ -271,6 +273,14 @@ variable_status_door_open: '_STATUS_BRIGHT' ; Status to show when door is open variable_door_open_gcode: 'M116' ; Custom macro for open doors (set to 'M116' to disable) variable_door_closed_gcode: 'M116' ; Custom macro for closed doors (set to 'M116' to disable) +## Debugging Variables +## NOTE: These variables configure debugging +## behavior. They are used to enable +## or disable debugging output and +## to define the debug output level. +variable_debugging: False +variable_debug_level: 0 + # End Custom Variables # ############################################################################################################# @@ -299,8 +309,8 @@ gcode: # No gcode needed ## Mainsail Client Macro Variables [gcode_macro _CLIENT_VARIABLE] variable_use_custom_pos : False ; use custom park coordinates for x,y [True/False] -variable_custom_park_x : 50.0 ; custom x position; value must be within your defined min and max of X -variable_custom_park_y : 302.0 ; custom y position; value must be within your defined min and max of Y +variable_custom_park_x : 50.0 ; custom x position; value must be within your defined min and max of X +variable_custom_park_y : 50.0 ; custom y position; value must be within your defined min and max of Y variable_custom_park_dz : 2.0 ; custom dz value; the value in mm to lift the nozzle when move to park position variable_retract : 1.0 ; the value to retract while PAUSE variable_cancel_retract : 5.0 ; the value to retract while CANCEL_PRINT @@ -309,9 +319,9 @@ variable_unretract : 1.0 ; the value to unretract while RESUME variable_speed_unretract : 35.0 ; unretract speed in mm/s variable_speed_hop : 15.0 ; z move speed in mm/s variable_speed_move : 100.0 ; move speed in mm/s -variable_park_at_cancel : True ; allow to move the toolhead to park while execute CANCEL_PRINT [True/False] +variable_park_at_cancel : True ; allow to move the toolhead to park while execute CANCEL_PRINT [True/False] variable_park_at_cancel_x : 50.0 ; different park position during CANCEL_PRINT [None/Position as Float]; park_at_cancel must be True -variable_park_at_cancel_y : 302.0 ; different park position during CANCEL_PRINT [None/Position as Float]; park_at_cancel must be True +variable_park_at_cancel_y : 50.0 ; different park position during CANCEL_PRINT [None/Position as Float]; park_at_cancel must be True ## !!! Caution [firmware_retraction] must be defined in the printer.cfg if you set use_fw_retract: True !!! variable_use_fw_retract : True ; use fw_retraction instead of the manual version [True/False] gcode: From 50f927cb8c0ca64d1328e1c7ac74de53bc2106ea Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 1 Jun 2023 04:30:10 -0400 Subject: [PATCH 79/81] logging stuff --- .gitignore | 3 ++- .vscode/settings.json | 3 ++- src/printcfg.py | 46 +++++++++++++++++++++++++++++++++++-------- src/requirements.txt | 4 ++-- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 049fbe2..6804318 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ user_profile.cfg -user_config.cfg \ No newline at end of file +user_config.cfg +logs/* \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 66b6b74..23934bf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { "licenser.projectName": "printcfg", - "python.analysis.typeCheckingMode": "basic" + "python.analysis.typeCheckingMode": "basic", + "cSpell.words": ["printcfg"] } diff --git a/src/printcfg.py b/src/printcfg.py index 354fee8..b5f070e 100755 --- a/src/printcfg.py +++ b/src/printcfg.py @@ -36,12 +36,6 @@ logger: logging.Logger = logging.getLogger(__name__) -# Set the logging level -logger.setLevel(logging.DEBUG) -formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") -handler = logging.StreamHandler(sys.stdout) -handler.setFormatter(formatter) -logger.addHandler(handler) # Set the repo name REPO = "printcfg" @@ -51,6 +45,24 @@ profile_path = f"{user_home}/printer_data/user_profile.cfg" setup_script = f"{user_home}/printcfg/scripts/setup.sh" +# Set the logfile +logfile = f"{user_home}/printcfg/logs/printcfg.log" + +# Check if the logfile exists +if not os.path.exists(f"{user_home}/printcfg/logs/"): + # Create the log directory + os.mkdir(f"{user_home}/printcfg/logs/") + # Create the logfile + with open(logfile, "w") as file: + pass + +# Set the logging level +logger.setLevel(logging.DEBUG) +formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") +handler = logging.FileHandler(logfile) +handler.setFormatter(formatter) +logger.addHandler(handler) + def find_profile(path): logger.debug("Searching for profile name in file: {}".format(path)) @@ -105,7 +117,10 @@ def generate_service(): try: result = subprocess.run(command, capture_output=True) except subprocess.CalledProcessError as e: - + print(f"Error: The subprocess returned an error.") + print(e.stderr) + logger.error("Error: The subprocess returned an error: {}".format(e.stderr)) + return logger.debug("Command output: {}".format(result.stdout.decode("utf-8"))) if result.returncode != 0: print(f"Error: The command '{command}' failed with code {result.returncode}.") @@ -179,14 +194,18 @@ def remove_printcfg(): try: subprocess.run(command) except subprocess.CalledProcessError as e: - pr + print("Error: The subprocess returned an error.") + print(e.stderr) + logger.error("Error: The subprocess returned an error: {}".format(e.stderr)) # Exit successfully + logger.info("Printcfg removed successfully.") exit(0) if __name__ == "__main__": # Check if there are any arguments if len(sys.argv) < 2: + logger.info("No arguments provided, running normal operations.") normal_ops() sys.exit(1) # Check the argument @@ -194,36 +213,47 @@ def remove_printcfg(): print( "Error: The argument must be either install, change, remove, update, or default." ) + logger.error("Error: The argument must be either install, change, remove, update, or default.") sys.exit(1) # If the argument is 'install' start the script as root if sys.argv[1] == "install": + logger.info("Running install operations.") generate_service() # If the argument is 'change' check for a second argument elif sys.argv[1] == "change": if len(sys.argv) != 3: print("Error: The change script requires two arguments.") print(f"Usage: python3 {REPO}.py change ") + logger.error("Error: The change script requires two arguments.") sys.exit(1) else: # Check if the profile exists profile = sys.argv[2] + logger.info("Running change operations.") profile_path = f"{user_home}/{REPO}/profiles/{profile}" + logger.debug("Profile path: {}".format(profile_path)) print(f"Changing to profile '{profile}'") # If the profile is 'backup' then skip the check if profile == "backup": + logger.info("Changing to backup profile.") change_profile(profile) else: # If the profile path does not exist, exit if not os.path.isdir(profile_path): print(f"Error: The profile '{profile}' does not exist.") + logger.error("Error: The profile '{}' does not exist.".format(profile)) sys.exit(1) else: + logger.info("Changing to profile '{}'.".format(profile)) change_profile(profile) # If the argument is 'remove' elif sys.argv[1] == "remove": + logger.info("Running remove operations.") remove_printcfg() elif sys.argv[1] == "update": + logger.info("Running update operations.") update_printcfg() else: + logger.info("Running normal operations.") normal_ops() diff --git a/src/requirements.txt b/src/requirements.txt index ff8631f..b2ef71f 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,4 +1,4 @@ -python-apt==2.2.1 +python-apt==0.7.8 python-dateutil==2.8.2 requests==2.30.0 -watchdog=3.3.0 \ No newline at end of file +watchdog==3.0.0 \ No newline at end of file From 2be6e8d0790ab105383692bd47b222f983c47a9a Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 1 Jun 2023 04:44:16 -0400 Subject: [PATCH 80/81] make use of door names --- print_macros.cfg | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/print_macros.cfg b/print_macros.cfg index 0d25ad0..b33a8dd 100644 --- a/print_macros.cfg +++ b/print_macros.cfg @@ -1508,9 +1508,10 @@ gcode: {% set doorcfg = printer['gcode_macro _door_cfg'] %} ; get doorcfg variables {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables {% set door = params.DOOR|default(0) %} ; get door number - SET_GCODE_VARIABLE MACRO=_open_door VARIABLE=door VALUE={door} ; set door + {% set door_name = printcfg['door' + door] %} ; set door name + SET_GCODE_VARIABLE MACRO=_open_door VARIABLE=door VALUE={door} ; store door {% if doorcfg.debounce == 0 %} ; check debounce - M{printcfg.output|int} Door {door}: Open ; status output + M{printcfg.output|int} Door {door_name}: Open ; status output {printcfg.status_door_open} ; open door LEDs {% if custom_macro == True %} ; check for custom macro {printer['gcode_macro _printcfg'][door_macro]} ; run custom macro @@ -1532,7 +1533,8 @@ gcode: {% set doorcfg = printer['gcode_macro _door_cfg'] %} ; get doorcfg variables {% set printcfg = printer['gcode_macro _printcfg'] %} ; get printcfg variables {% set door = params.DOOR|default(0) %} ; get door number - SET_GCODE_VARIABLE MACRO=_close_door VARIABLE=door VALUE={door} ; set door + {% set door_name = printcfg['door' + door] %} ; set door name + SET_GCODE_VARIABLE MACRO=_close_door VARIABLE=door VALUE={door} ; store door {% set door_macro = "door" + door|string + "_closed" %} {% set custom_macro = True if printer['gcode_macro _printcfg'][door_macro] is defined else False %} {% if doorcfg.debounce == 0 %} ; check debounce From 9e80b4bfd6cc266c249308c4b695e302602ce682 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 1 Jun 2023 04:51:49 -0400 Subject: [PATCH 81/81] bump date --- README.md | 44 ++++++++++++++++--------------- print_debug.cfg | 2 +- print_extras.cfg | 2 +- print_macros.cfg | 2 +- profiles/README.md | 13 ++++----- profiles/default/config.cfg | 2 +- profiles/default/variables.cfg | 2 +- profiles/hephaestus/variables.cfg | 2 +- scripts/change_profile.sh | 2 +- scripts/install.sh | 2 +- scripts/patch.sh | 2 +- scripts/setup.sh | 2 +- src/mooncfg.conf | 2 +- 13 files changed, 41 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 20bad16..d4c1ed1 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,18 @@ @@ -20,7 +20,7 @@ @@ -71,7 +71,7 @@ ## !!! WARNING: THIS IS STILL A WORK IN PROGRESS !!! - > I am currently running this suite on my personal machine so I consider it to be ready for brave testers to play around with. Expect to encounter issues! But please tell me about them so I can fix them in a later revision! +> I am currently running this suite on my personal machine so I consider it to be ready for brave testers to play around with. Expect to encounter issues! But please tell me about them so I can fix them in a later revision! ## Overview @@ -101,7 +101,7 @@ Additionally, you can specify a different branch to install from: The install script will begin by checking for dependencies and installing them if they are missing. -It will then clone the repo into your home directory in a folder named `printcfg`. +It will then clone the repo into your home directory in a folder named `printcfg`. Please do not modify the contents of this folder. @@ -109,8 +109,8 @@ The files for the profile you specified will be copied into your main config fol This will consist of two files: `user_profile.cfg` and `user_config.cfg`. -> NOTE: You are free to modify these files as you see fit, but please only modify files that begin with `user_` so that the update system can successfully merge changes. -> +> NOTE: You are free to modify these files as you see fit, but please only modify files that begin with `user_` so that the update system can successfully merge changes. +> > These files will be placed in your main config folder, so they will not be overwritten by future updates. The following line will be added to your `printer.cfg` file: @@ -141,13 +141,11 @@ Most updates will happen completely automatically, but some may require manual i To change profiles, run the following command: - - ## Configuration The vast majority of the configuration is done via the `_printcfg` macro in `user_profile.cfg`. -This is the "master" macro that hosts the configuration variables for the entire suite. +This is the "master" macro that hosts the configuration variables for the entire suite. It is here that we configure the behavior of the suite. @@ -167,7 +165,7 @@ Preset profiles are [available](./profiles/) for various common configurations. If you would like to submit a profile, please see the [Submitting A Profile](#submitting-a-profile) section below. - I'd love to have a wide variety of community profiles available for everyone to choose from! +I'd love to have a wide variety of community profiles available for everyone to choose from! Custom configuration can be achieved by editing the `user_profile.cfg` file on your local installation. @@ -237,7 +235,7 @@ This allows all the macros in the suite to be kept apprised of any slicer values It's completely ok if you don't use these settings in your klipper install or even in your slicer! -This suite is built to support ***everything*** so that the user can simply set the configuration values (either manually in the config file or via `SET_GCODE_VARIABLE` commands) +This suite is built to support **_everything_** so that the user can simply set the configuration values (either manually in the config file or via `SET_GCODE_VARIABLE` commands) The idea is that you don't need to worry about the correct way to configure the slicer for your needs or even finding (or creating!) the right macros for your needs. @@ -251,7 +249,7 @@ The bulk of profile configuration occurs in the `user_profile.cfg` file. There a ### Versioning -- `variable_version` +- `variable_version` - Determines when updates require new variables to be added to the profile. It is used by the install script to determine when profiles need updating. ### Default temperatures @@ -271,7 +269,7 @@ The bulk of profile configuration occurs in the `user_profile.cfg` file. There a ## Chamber Variables - `variable_chamber_type` - - Defines the chamber sensor type. This could be 'temperature_sensor', 'temperature_fan', 'heater', or 'none' + - Defines the chamber sensor type. This could be 'temperature_sensor', 'temperature_fan', 'heater', or 'none' - `variable_chamber_name` - Defines the name of the chamber sensor. Typically this will be 'chamber'. - `variable_chamber_temp` @@ -340,7 +338,7 @@ The bulk of profile configuration occurs in the `user_profile.cfg` file. There a - `variable_park_extrude` - Sets the default extrusion amount for parking moves. - `variable_park_base` - - Sets the "native" command for parking. This is typically something like '_TOOLHEAD_PAUSE_PARK_CANCEL' + - Sets the "native" command for parking. This is typically something like '\_TOOLHEAD_PAUSE_PARK_CANCEL' ### Preheat Parking Variables @@ -386,6 +384,7 @@ Setting any of these values to -1 will park at the center of all 3 axes. - Sets the stepper current to be used during homing. ### Homing Macros + - `variable_home_x_macro` - Sets the macro to be used for x-homing. - `variable_home_y_macro` @@ -394,12 +393,14 @@ Setting any of these values to -1 will park at the center of all 3 axes. - Sets the macro to be used for z-homing. ### Pause Macros + - `variable_pause_macro` - Sets the macro to be used for pausing. - `variable_pause_no_park` - Sets the macro to be used for pausing without parking. ### Speed Variables + - `variable_default_speed_factor` - Sets the default speed factor for all moves. - `variable_start_offset` @@ -552,6 +553,7 @@ Setting any of these values to -1 will park at the center of all 3 axes. - Enables debug logging for purging. ### End Gcode Variables + - `variable_end_print` - Determines whether to run the end print macro. - `variable_end_retract` @@ -570,7 +572,7 @@ Setting any of these values to -1 will park at the center of all 3 axes. ### Filament Change Variables - `variable_m600` - - Sets the command to be used for filament change. + - Sets the command to be used for filament change. - `variable_auto_filament_sensor` - Determines whether to automatically toggle the filament sensor. - `variable_auto_filament_delay` @@ -699,7 +701,7 @@ Each profile must consist of the following files: This file contains the patch notes for the profile. It should list the version of the profile and "initial release" if it is the first release. - **README.md** - + This file contains the profile description. It should have one header with the profile name with By: Your Name underneath. It should also have a description of the profile and any special instructions for using it. You should also briefly list the printer and components the profile was designed for. If your README file requires any images, please place them in an `images` folder within your profile folder and reference them in your README file. @@ -709,7 +711,7 @@ Each profile must consist of the following files: The main goal is to make it easy for users to quickly find the information they need to use your profile. Keep in mind that large files will increase the size of the install on every machine whether they use your profile or not. All profiles are synced alongside the rest of the repo. But only the selected profile is added to the user's config. - + Please be reasonable with the size of your images to keep the repository size small and the sync time low. - When your profile is installed on a user's printer, only the variables.cfg and config.cfg files are used. The README.md and patch_notes.txt files are only used for display purposes in the repository. Similarly, any additional files you include in your profile will not be added to the user's config. \ No newline at end of file + When your profile is installed on a user's printer, only the variables.cfg and config.cfg files are used. The README.md and patch_notes.txt files are only used for display purposes in the repository. Similarly, any additional files you include in your profile will not be added to the user's config. diff --git a/print_debug.cfg b/print_debug.cfg index 1295d28..764c4c3 100644 --- a/print_debug.cfg +++ b/print_debug.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Debugging ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### ## This file contains optional macros diff --git a/print_extras.cfg b/print_extras.cfg index d07ce40..d9be908 100644 --- a/print_extras.cfg +++ b/print_extras.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Extras ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### ## This file contains optional config diff --git a/print_macros.cfg b/print_macros.cfg index b33a8dd..55a6f2b 100644 --- a/print_macros.cfg +++ b/print_macros.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Macros ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### [include logging.cfg] diff --git a/profiles/README.md b/profiles/README.md index 6d9069b..14b8de4 100644 --- a/profiles/README.md +++ b/profiles/README.md @@ -1,18 +1,18 @@ @@ -20,9 +20,10 @@ + # Preset Profiles ## [Default](./default/) @@ -31,4 +32,4 @@ This is the default configuration. Virtually all extra features are disabled in ## [Hephaestus](./hephaestus/) -This profile is for a Voron V2.4 with TAP and a nozzle brush. This is what I use on my personal machine. \ No newline at end of file +This profile is for a Voron V2.4 with TAP and a nozzle brush. This is what I use on my personal machine. diff --git a/profiles/default/config.cfg b/profiles/default/config.cfg index 006a841..fe8a547 100644 --- a/profiles/default/config.cfg +++ b/profiles/default/config.cfg @@ -17,7 +17,7 @@ ##################################### ## Print Configuration ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### # Profile:default # Patch:4.0.0 diff --git a/profiles/default/variables.cfg b/profiles/default/variables.cfg index 21615f5..c352e25 100644 --- a/profiles/default/variables.cfg +++ b/profiles/default/variables.cfg @@ -17,7 +17,7 @@ ##################################### ## User Profile ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### # Profile:default # Patch:4.0.0 diff --git a/profiles/hephaestus/variables.cfg b/profiles/hephaestus/variables.cfg index d2974b2..4a2e0ce 100644 --- a/profiles/hephaestus/variables.cfg +++ b/profiles/hephaestus/variables.cfg @@ -17,7 +17,7 @@ ##################################### ## User Profile ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### # Profile:hephaestus # Patch:4.0.0 diff --git a/scripts/change_profile.sh b/scripts/change_profile.sh index 9963afa..1fea609 100644 --- a/scripts/change_profile.sh +++ b/scripts/change_profile.sh @@ -19,7 +19,7 @@ ##################################### ## Printcfg Profile Change ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### # This script will change the user profile to the specified profile. diff --git a/scripts/install.sh b/scripts/install.sh index ee82e06..99c8c53 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -19,7 +19,7 @@ ##################################### ## Printcfg Install Script ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### # This script will download and install the printcfg package from GitHub. diff --git a/scripts/patch.sh b/scripts/patch.sh index 572b4f6..db6a73d 100644 --- a/scripts/patch.sh +++ b/scripts/patch.sh @@ -19,7 +19,7 @@ ##################################### ## Printcfg Patch Script ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### # This script will apply version patches to the user profile and user config. diff --git a/scripts/setup.sh b/scripts/setup.sh index 211fb5d..4e690e2 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -19,7 +19,7 @@ ##################################### ## Printcfg Setup Script ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### # This script will check the user profile and update it if necessary. diff --git a/src/mooncfg.conf b/src/mooncfg.conf index 9289961..37c523f 100644 --- a/src/mooncfg.conf +++ b/src/mooncfg.conf @@ -1,6 +1,6 @@ ##################################### ## Printcfg Moonraker ## -## Version 4.0.0 2023-5-26 ## +## Version 4.0.0 2023-6-1 ## ##################################### ## Manage updates for Rootiest printcfg Suite for Klipper