From ea0ec71cf0bb790a0fb11966160ff587a29b64c3 Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 4 Dec 2020 16:40:05 +0000 Subject: [PATCH 01/10] Only attempt unmount if the SD card is actually mounted --- octoprint_firmwareupdater/methods/lpc1768.py | 37 +++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/octoprint_firmwareupdater/methods/lpc1768.py b/octoprint_firmwareupdater/methods/lpc1768.py index 979a82d..11e1d73 100644 --- a/octoprint_firmwareupdater/methods/lpc1768.py +++ b/octoprint_firmwareupdater/methods/lpc1768.py @@ -42,23 +42,26 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): return False time.sleep(1) - unmount_command = self._settings.get(["lpc1768_unmount_command"]) - if unmount_command: - unmount_command = unmount_command.replace("{mountpoint}", lpc1768_path) - - self._logger.info(u"Unmounting SD card: '{}'".format(unmount_command)) - try: - r = os.system(unmount_command) - except: - e = sys.exc_info()[0] - self._logger.error("Error executing unmount command '{}'".format(unmount_command)) - self._send_status("flasherror", message="Unable to unmount SD card") - return False - - if r != 0: - self._logger.error("Error executing unmount command '{}'".format(unmount_command)) - self._send_status("flasherror", message="Unable to unmount SD card") - return False + if os.access(lpc1768_path, os.W_OK): + unmount_command = self._settings.get(["lpc1768_unmount_command"]) + if unmount_command: + unmount_command = unmount_command.replace("{mountpoint}", lpc1768_path) + + self._logger.info(u"Unmounting SD card: '{}'".format(unmount_command)) + try: + r = os.system(unmount_command) + except: + e = sys.exc_info()[0] + self._logger.error("Error executing unmount command '{}'".format(unmount_command)) + self._send_status("flasherror", message="Unable to unmount SD card") + return False + + if r != 0: + self._logger.error("Error executing unmount command '{}'".format(unmount_command)) + self._send_status("flasherror", message="Unable to unmount SD card") + return False + else: + self._logger.info(u"SD card not mounted, skipping unmount") self._logger.info(u"Pre-flash reset: attempting to reset the board") if not _reset_lpc1768(self, printer_port): From 335e70d03830143707315350e1b12dc5fb7c3e3c Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 4 Dec 2020 17:25:30 +0000 Subject: [PATCH 02/10] Catch output from unmount command --- octoprint_firmwareupdater/methods/lpc1768.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/octoprint_firmwareupdater/methods/lpc1768.py b/octoprint_firmwareupdater/methods/lpc1768.py index 11e1d73..33cde20 100644 --- a/octoprint_firmwareupdater/methods/lpc1768.py +++ b/octoprint_firmwareupdater/methods/lpc1768.py @@ -2,6 +2,7 @@ import os import time import shutil +import subprocess def _check_lpc1768(self): lpc1768_path = self._settings.get(["lpc1768_path"]) @@ -49,7 +50,7 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): self._logger.info(u"Unmounting SD card: '{}'".format(unmount_command)) try: - r = os.system(unmount_command) + (r, o) = subprocess.getstatusoutput(unmount_command) except: e = sys.exc_info()[0] self._logger.error("Error executing unmount command '{}'".format(unmount_command)) @@ -58,6 +59,7 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): if r != 0: self._logger.error("Error executing unmount command '{}'".format(unmount_command)) + self._logger.error("{}".format(o)) self._send_status("flasherror", message="Unable to unmount SD card") return False else: @@ -120,7 +122,7 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): self._logger.info(u"Unmounting SD card: '{}'".format(unmount_command)) try: - r = os.system(unmount_command) + (r, o) = subprocess.getstatusoutput(unmount_command) except: e = sys.exc_info()[0] self._logger.error("Error executing unmount command '{}'".format(unmount_command)) @@ -129,6 +131,7 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): if r != 0: self._logger.error("Error executing unmount command '{}'".format(unmount_command)) + self._logger.error("{}".format(o)) self._send_status("flasherror", message="Unable to unmount SD card") return False From 8bbe7b77f03b51acecfcddd1ea09edc17668250e Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 4 Dec 2020 17:26:06 +0000 Subject: [PATCH 03/10] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0555e4f..a15b92b 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-FirmwareUpdater" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.7.6" +plugin_version = "1.7.6rc0" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module From 33401d6594e2b71407740db6c97c8a6949cf3759 Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 4 Dec 2020 20:42:36 +0000 Subject: [PATCH 04/10] Python 2 and 3 compatible --- octoprint_firmwareupdater/methods/lpc1768.py | 14 ++++++++++---- setup.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/octoprint_firmwareupdater/methods/lpc1768.py b/octoprint_firmwareupdater/methods/lpc1768.py index 33cde20..1587d11 100644 --- a/octoprint_firmwareupdater/methods/lpc1768.py +++ b/octoprint_firmwareupdater/methods/lpc1768.py @@ -50,7 +50,10 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): self._logger.info(u"Unmounting SD card: '{}'".format(unmount_command)) try: - (r, o) = subprocess.getstatusoutput(unmount_command) + p = subprocess.Popen(unmount_command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + out, err = p.communicate() + r = p.returncode + except: e = sys.exc_info()[0] self._logger.error("Error executing unmount command '{}'".format(unmount_command)) @@ -59,7 +62,7 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): if r != 0: self._logger.error("Error executing unmount command '{}'".format(unmount_command)) - self._logger.error("{}".format(o)) + self._logger.error("{}".format(err.strip())) self._send_status("flasherror", message="Unable to unmount SD card") return False else: @@ -122,7 +125,10 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): self._logger.info(u"Unmounting SD card: '{}'".format(unmount_command)) try: - (r, o) = subprocess.getstatusoutput(unmount_command) + p = subprocess.Popen(unmount_command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + out, err = p.communicate() + r = p.returncode + except: e = sys.exc_info()[0] self._logger.error("Error executing unmount command '{}'".format(unmount_command)) @@ -131,7 +137,7 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): if r != 0: self._logger.error("Error executing unmount command '{}'".format(unmount_command)) - self._logger.error("{}".format(o)) + self._logger.error("{}".format(err.strip())) self._send_status("flasherror", message="Unable to unmount SD card") return False diff --git a/setup.py b/setup.py index a15b92b..ea3ac25 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-FirmwareUpdater" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.7.6rc0" +plugin_version = "1.7.6rc1" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module From cd5c001bbc460636fa1d27e53aabd74485e49cd9 Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 4 Dec 2020 21:00:03 +0000 Subject: [PATCH 05/10] Fix exception handling --- octoprint_firmwareupdater/methods/lpc1768.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/octoprint_firmwareupdater/methods/lpc1768.py b/octoprint_firmwareupdater/methods/lpc1768.py index 1587d11..fd2c85c 100644 --- a/octoprint_firmwareupdater/methods/lpc1768.py +++ b/octoprint_firmwareupdater/methods/lpc1768.py @@ -3,6 +3,7 @@ import time import shutil import subprocess +import sys def _check_lpc1768(self): lpc1768_path = self._settings.get(["lpc1768_path"]) @@ -57,6 +58,7 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): except: e = sys.exc_info()[0] self._logger.error("Error executing unmount command '{}'".format(unmount_command)) + self._logger.error("{}".format(str(e))) self._send_status("flasherror", message="Unable to unmount SD card") return False @@ -132,6 +134,7 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): except: e = sys.exc_info()[0] self._logger.error("Error executing unmount command '{}'".format(unmount_command)) + self._logger.error("{}".format(str(e))) self._send_status("flasherror", message="Unable to unmount SD card") return False From 126abf371fcf9352cd37a51573e6a338238d736d Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 4 Dec 2020 22:47:31 +0000 Subject: [PATCH 06/10] Better handling of attempting to unmount a device that is not mounted --- octoprint_firmwareupdater/methods/lpc1768.py | 22 +++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/octoprint_firmwareupdater/methods/lpc1768.py b/octoprint_firmwareupdater/methods/lpc1768.py index fd2c85c..403044a 100644 --- a/octoprint_firmwareupdater/methods/lpc1768.py +++ b/octoprint_firmwareupdater/methods/lpc1768.py @@ -63,10 +63,13 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): return False if r != 0: - self._logger.error("Error executing unmount command '{}'".format(unmount_command)) - self._logger.error("{}".format(err.strip())) - self._send_status("flasherror", message="Unable to unmount SD card") - return False + if err.strip().endswith("not mounted."): + self._logger.info("{}".format(err.strip())) + else: + self._logger.error("Error executing unmount command '{}'".format(unmount_command)) + self._logger.error("{}".format(err.strip())) + self._send_status("flasherror", message="Unable to unmount SD card") + return False else: self._logger.info(u"SD card not mounted, skipping unmount") @@ -139,10 +142,13 @@ def _flash_lpc1768(self, firmware=None, printer_port=None): return False if r != 0: - self._logger.error("Error executing unmount command '{}'".format(unmount_command)) - self._logger.error("{}".format(err.strip())) - self._send_status("flasherror", message="Unable to unmount SD card") - return False + if err.strip().endswith("not mounted."): + self._logger.info("{}".format(err.strip())) + else: + self._logger.error("Error executing unmount command '{}'".format(unmount_command)) + self._logger.error("{}".format(err.strip())) + self._send_status("flasherror", message="Unable to unmount SD card") + return False self._logger.info(u"Firmware update reset: attempting to reset the board") if not _reset_lpc1768(self, printer_port): From 31d6cc671fb7622d52376202cf6d97764f2a73f1 Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 4 Dec 2020 22:55:04 +0000 Subject: [PATCH 07/10] Add development release channel --- octoprint_firmwareupdater/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/octoprint_firmwareupdater/__init__.py b/octoprint_firmwareupdater/__init__.py index 03c15dd..3269efe 100644 --- a/octoprint_firmwareupdater/__init__.py +++ b/octoprint_firmwareupdater/__init__.py @@ -370,9 +370,11 @@ def update_hook(self): repo="OctoPrint-FirmwareUpdater", current=self._plugin_version, - # stable branch + # stable releases stable_branch=dict( - name="Stable", branch="master", comittish=["master"] + name="Stable", + branch="master", + comittish=["master"] ), # release candidates @@ -381,6 +383,11 @@ def update_hook(self): name="Release Candidate", branch="rc", comittish=["rc", "master"], + ), + dict( + name="Development", + branch="devel", + comittish=["devel", "rc", "master"], ) ], From dd048c040137d4d9f4558463ae8ab3664d0c7f83 Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 4 Dec 2020 22:55:43 +0000 Subject: [PATCH 08/10] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ea3ac25..62aafee 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-FirmwareUpdater" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.7.6rc1" +plugin_version = "1.7.6rc2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module From 94daf222b709db5385d7b9a424c03d44d1ec4cd3 Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Sun, 6 Dec 2020 14:22:43 +0000 Subject: [PATCH 09/10] Show plugin version --- .../templates/firmwareupdater_settings.jinja2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 index 0adef22..a4a8864 100644 --- a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 +++ b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 @@ -71,8 +71,9 @@

No warranty is given, and no responsibility can be accepted if there are problems. By using this plugin you accept the associated risks.

  
Documentation
-

Documentation is available on Github

+

Documentation is available on Github

+
Plugin Version:
+
Plugin Version: