-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ballaswag
committed
Jan 17, 2024
1 parent
6d71018
commit a20edd7
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class GuppyConfigHelper: | ||
def __init__(self, config): | ||
self.printer = config.get_printer() | ||
|
||
# Register commands | ||
gcode = config.get_printer().lookup_object('gcode') | ||
gcode.register_command("GUPPY_SAVE_CONFIG", self.cmd_guppy_save_config) | ||
gcode.register_command("GUPPY_DELETE_CONFIG", self.cmd_guppy_delete_config) | ||
|
||
def cmd_guppy_save_config(self, gcmd): | ||
self.section = gcmd.get('SECTION', None) | ||
self.pairs = gcmd.get('KEY_VALUE', None) | ||
|
||
if self.section and self.pairs: | ||
configfile = self.printer.lookup_object('configfile') | ||
kv = self.pairs.split(',') | ||
d = dict(s.split(':') for s in kv) | ||
|
||
configfile.remove_section(self.section) | ||
|
||
for k, v in d.items(): | ||
configfile.set(self.section, k, v) | ||
|
||
def cmd_guppy_delete_config(self, gcmd): | ||
self.section = gcmd.get('SECTION', None) | ||
|
||
if self.section: | ||
configfile = self.printer.lookup_object('configfile') | ||
configfile.remove_section(self.section) | ||
|
||
def load_config(config): | ||
return GuppyConfigHelper(config) |