repair missing update

This commit is contained in:
CChen616
2024-08-23 10:45:24 +08:00
parent 3402ca3ef6
commit 25ee651226
9 changed files with 1560 additions and 1283 deletions

View File

@@ -18,6 +18,29 @@ class SaveVariables:
gcode = self.printer.lookup_object('gcode')
gcode.register_command('SAVE_VARIABLE', self.cmd_SAVE_VARIABLE,
desc=self.cmd_SAVE_VARIABLE_help)
def load_variable(self, section, option):
varfile = configparser.ConfigParser()
try:
varfile.read(self.filename)
return varfile.get(section, option)
except:
msg = "Unable to parse existing variable file"
logging.exception(msg)
raise self.printer.command_error(msg)
def save_variable(self, section, option, value):
varfile = configparser.ConfigParser()
try:
varfile.read(self.filename)
if not varfile.has_section(section):
varfile.add_section(section)
varfile.set(section, option, value)
with open(self.filename, 'w') as configfile:
varfile.write(configfile)
except Exception as e:
msg = "Unable to save variable"
logging.exception(msg)
raise self.printer.command_error(msg)
def loadVariables(self):
allvars = {}
varfile = configparser.ConfigParser()