fix for python2.7
This commit is contained in:
parent
6629dc0bd4
commit
51ca8dc259
|
@ -32,6 +32,9 @@ try:
|
|||
except ImportError:
|
||||
import ConfigParser as configparser
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
import StringIO
|
||||
|
||||
class KlipperPlugin(
|
||||
octoprint.plugin.StartupPlugin,
|
||||
octoprint.plugin.TemplatePlugin,
|
||||
|
@ -428,9 +431,12 @@ class KlipperPlugin(
|
|||
configpath)
|
||||
)
|
||||
else:
|
||||
|
||||
self._settings.set(["config"], data["config"])
|
||||
# self.send_message("reload", "config", "", data["config"])
|
||||
# send the configdata to frontend to update ace editor
|
||||
if sys.version_info[0] < 3:
|
||||
data["config"] = data["config"].decode('utf-8')
|
||||
return flask.jsonify(data=data["config"])
|
||||
elif command == "checkConfig":
|
||||
if "config" in data:
|
||||
|
@ -539,12 +545,23 @@ class KlipperPlugin(
|
|||
|
||||
try:
|
||||
dataToValidated = configparser.RawConfigParser()
|
||||
#
|
||||
if sys.version_info[0] < 3:
|
||||
buf = StringIO.StringIO(dataToBeValidated)
|
||||
dataToValidated.readfp(buf)
|
||||
else:
|
||||
dataToValidated.read_string(dataToBeValidated)
|
||||
except configparser.Error as error:
|
||||
if sys.version_info[0] < 3:
|
||||
error.message = error.message.replace("\\n","")
|
||||
error.message = error.message.replace("file: u","Klipper Configuration", 1)
|
||||
error.message = error.message.replace("'","", 2)
|
||||
error.message = error.message.replace("u'","'", 1)
|
||||
|
||||
else:
|
||||
error.message = error.message.replace("\\n","")
|
||||
error.message = error.message.replace("file:","Klipper Configuration", 1)
|
||||
error.message = error.message.replace("'","", 2)
|
||||
error.source = "Klipper config"
|
||||
self.log_error(
|
||||
"Error: Invalid Klipper config file:\n" +
|
||||
"{}".format(str(error))
|
||||
|
|
Loading…
Reference in New Issue