From 51ca8dc259a4ae817825b41b3310bec127411c7f Mon Sep 17 00:00:00 2001 From: thelastWallE <12502210+thelastWallE@users.noreply.github.com> Date: Sat, 3 Apr 2021 00:49:40 +0200 Subject: [PATCH] fix for python2.7 --- octoprint_klipper/__init__.py | 27 ++++++++++++++++++++++----- setup.py | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/octoprint_klipper/__init__.py b/octoprint_klipper/__init__.py index bf56602..207de27 100644 --- a/octoprint_klipper/__init__.py +++ b/octoprint_klipper/__init__.py @@ -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() - dataToValidated.read_string(dataToBeValidated) + # + if sys.version_info[0] < 3: + buf = StringIO.StringIO(dataToBeValidated) + dataToValidated.readfp(buf) + else: + dataToValidated.read_string(dataToBeValidated) except configparser.Error as error: - 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" + 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) self.log_error( "Error: Invalid Klipper config file:\n" + "{}".format(str(error)) diff --git a/setup.py b/setup.py index faef05d..42a7740 100644 --- a/setup.py +++ b/setup.py @@ -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."""