Implement further config validation
Basically just parse the config file before we save it, ensuring that it can be parsed by `configparser` - the same parser used by Klipper. This PR depende on the changes from https://github.com/AliceGrey/OctoprintKlipperPlugin/pull/8 in order to send a warning popup when validation fails.
This commit is contained in:
parent
e553a69ff5
commit
1d8a6cb352
|
@ -22,6 +22,7 @@ import os
|
|||
from octoprint.util.comm import parse_firmware_line
|
||||
from .modules import KlipperLogAnalyzer
|
||||
import flask
|
||||
import configparser
|
||||
|
||||
class KlipperPlugin(
|
||||
octoprint.plugin.StartupPlugin,
|
||||
|
@ -116,6 +117,17 @@ class KlipperPlugin(
|
|||
try:
|
||||
data["config"] = data["config"].encode('utf-8')
|
||||
|
||||
# Basic validation of config file - makes sure it parses
|
||||
try:
|
||||
parser = configparser.RawConfigParser()
|
||||
parser.read_string(data["config"])
|
||||
except configParser.Error as error:
|
||||
self._logger.error(
|
||||
"Error: Invalid Klipper config file: {}".format(str(error))
|
||||
)
|
||||
self.sendMessage("errorPopUp","warning", "OctoKlipper Settings", "Invalid Klipper config file: " + str(error))
|
||||
|
||||
|
||||
f = open(configpath, "w")
|
||||
f.write(data["config"])
|
||||
f.close()
|
||||
|
|
Loading…
Reference in New Issue