fix for python2.7

This commit is contained in:
thelastWallE 2021-04-03 00:49:40 +02:00
parent 6629dc0bd4
commit 51ca8dc259
2 changed files with 23 additions and 6 deletions

View File

@ -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))

View File

@ -19,7 +19,7 @@ plugin_package = "octoprint_klipper"
plugin_name = "OctoKlipper"
plugin_version = "0.3.6"
plugin_version = "0.3.6a"
plugin_description = """A plugin for OctoPrint to configure,control and monitor the Klipper 3D printer software."""