From e4582265806b6b9679442f8818baad6f750e7117 Mon Sep 17 00:00:00 2001 From: thelastWallE <12502210+thelastWallE@users.noreply.github.com> Date: Wed, 3 Nov 2021 11:01:06 +0100 Subject: [PATCH 1/4] remove workflow --- .github/workflows/fakeaction.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .github/workflows/fakeaction.yml diff --git a/.github/workflows/fakeaction.yml b/.github/workflows/fakeaction.yml deleted file mode 100644 index 7100b21..0000000 --- a/.github/workflows/fakeaction.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: FakeAction - -on: - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Run a one-line script - run: echo ping From 7e1bdcba1cbfef3ede3c694740e10e3774530f8e Mon Sep 17 00:00:00 2001 From: thelastWallE <12502210+thelastWallE@users.noreply.github.com> Date: Wed, 3 Nov 2021 19:46:30 +0100 Subject: [PATCH 2/4] :bug: add encoding for ISO-8859-1 - will try to encode with ISO-8859-1 after utf-8 failed. --- octoprint_klipper/__init__.py | 63 ++++++++++++++++++++++++++--------- setup.py | 2 +- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/octoprint_klipper/__init__.py b/octoprint_klipper/__init__.py index d171c3e..a57e624 100644 --- a/octoprint_klipper/__init__.py +++ b/octoprint_klipper/__init__.py @@ -21,6 +21,7 @@ import octoprint.plugin.core import glob import os import sys +import io from octoprint.util.comm import parse_firmware_line from octoprint.access.permissions import Permissions, ADMIN_GROUP, USER_GROUP from .modules import KlipperLogAnalyzer @@ -141,16 +142,33 @@ class KlipperPlugin( configpath = os.path.expanduser( self._settings.get(["configuration", "configpath"]) ) - try: - f = open(configpath, "r") - data["config"] = f.read() - f.close() + with io.open(configpath, "r", encoding="utf8") as f: + data["config"] = f.read() + f.close() except IOError: self.log_error( "Error: Klipper config file not found at: {}".format( configpath) ) + except UnicodeDecodeError as e: + self.log_debug( + "Loading config with utf-8 failed. Trying to load config file with ISO-8859-1 now." + ) + try: + with io.open(configpath, "r", encoding="ISO-8859-1") as f: + data["config"] = f.read() + f.close() + except UnicodeDecodeError as e: + self.log_error( + "Error: Klipper config file cannot be decoded: {}".format(e) + ) + else: + self.log_debug( + "Loading config with ISO-8859-1 finished." + ) + self.send_message("reload", "config", "", data["config"]) + # send the configdata to frontend to update ace editor else: self.send_message("reload", "config", "", data["config"]) # send the configdata to frontend to update ace editor @@ -183,11 +201,9 @@ class KlipperPlugin( ) if self.file_exist(configpath) and (self._parsing_check_response or not check_parse): try: - f = open(configpath, "w") - f.write(data["config"]) - f.close() - - + with io.open(configpath, "w", encoding="utf-8") as f: + f.write(data["config"]) + f.close() self.log_debug("Writing Klipper config to {}".format(configpath)) except IOError: self.log_error("Error: Couldn't write Klipper config file: {}".format(configpath)) @@ -446,21 +462,38 @@ class KlipperPlugin( configpath = os.path.expanduser( self._settings.get(["configuration", "configpath"]) ) - try: - f = open(configpath, "r") - data["config"] = f.read() - f.close() + with io.open(configpath, "r", encoding="utf-8") as f: + data["config"] = f.read() + f.close() except IOError: self.log_error( "Error: Klipper config file not found at: {}".format( configpath) ) + except UnicodeDecodeError as e: + self.log_debug( + "Loading config with utf-8 failed. Trying to load config file with ISO-8859-1 now." + ) + try: + with io.open(configpath, "r", encoding="ISO-8859-1") as f: + data["config"] = f.read() + f.close() + except UnicodeDecodeError as e: + self.log_error( + "Error: Klipper config file cannot be decoded: {}".format(e) + ) + else: + self.log_debug( + "Loading config with ISO-8859-1 finished." + ) + self._settings.set(["config"], data["config"]) + if sys.version_info[0] < 3: + data["config"] = data["config"].decode('utf-8') + return flask.jsonify(data=data["config"]) 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"]) diff --git a/setup.py b/setup.py index b27da43..b87e090 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ plugin_package = "octoprint_klipper" plugin_name = "OctoKlipper" -plugin_version = "0.3.8.3" +plugin_version = "0.3.8.4" plugin_description = """A plugin for OctoPrint to configure,control and monitor the Klipper 3D printer software.""" From afd97f93153d7af3497999f427ad6b3023e23c20 Mon Sep 17 00:00:00 2001 From: thelastWallE <12502210+thelastWallE@users.noreply.github.com> Date: Wed, 3 Nov 2021 20:51:34 +0100 Subject: [PATCH 3/4] :bug: fix encoding for python 2 --- octoprint_klipper/__init__.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/octoprint_klipper/__init__.py b/octoprint_klipper/__init__.py index a57e624..5b435d6 100644 --- a/octoprint_klipper/__init__.py +++ b/octoprint_klipper/__init__.py @@ -186,8 +186,6 @@ class KlipperPlugin( else: check_parse = self._settings.get(["configuration", "parse_check"]) - if sys.version_info[0] < 3: - data["config"] = data["config"].encode('utf-8') # check for configpath if it was changed during changing of the configfile if self.key_exist(data, "configuration", "configpath"): @@ -220,7 +218,7 @@ class KlipperPlugin( # Restart klippy to reload config self._printer.commands(reload_command) self.log_info("Restarting Klipper.") - # we dont want to write the klipper conf to the octoprint settings + # we don't want to write the klipper conf to the octoprint settings data.pop("config", None) # save the rest of changed settings into config.yaml of octoprint @@ -488,14 +486,10 @@ class KlipperPlugin( "Loading config with ISO-8859-1 finished." ) self._settings.set(["config"], data["config"]) - if sys.version_info[0] < 3: - data["config"] = data["config"].decode('utf-8') return flask.jsonify(data=data["config"]) else: self._settings.set(["config"], data["config"]) - 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: From 185ddad004a14475945215bcb3e921d4dae88bb0 Mon Sep 17 00:00:00 2001 From: thelastWallE <12502210+thelastWallE@users.noreply.github.com> Date: Wed, 3 Nov 2021 21:05:33 +0100 Subject: [PATCH 4/4] update stale workflow --- .github/workflows/staleissues.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/staleissues.yml b/.github/workflows/staleissues.yml index 8272e8a..1006d9c 100644 --- a/.github/workflows/staleissues.yml +++ b/.github/workflows/staleissues.yml @@ -9,10 +9,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Close Stale Issues - uses: actions/stale@v3.0.18 + uses: actions/stale@v4.0.0 with: # Token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`. # repo-token: ${{ github.token }} stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.' days-before-stale: 30 days-before-close: 5 + exempt-all-pr-milestones: true + exempt-all-assignees: true