From 0d035496f5dc9b43d8f4d3d4c5a766ad3bf78837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 7 Feb 2020 19:28:11 +0100 Subject: [PATCH 01/28] =?UTF-8?q?=F0=9F=90=9B=20Fix=20caching=20on=20/api/?= =?UTF-8?q?files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were calculating the last modified date for the internal file cache wrong and that led to returning stale data. Should fix #3422 --- src/octoprint/server/api/files.py | 78 +++++++++++++++++++------------ 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index d56a9300a..6ea51da02 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -41,7 +41,11 @@ def _clear_file_cache(): _file_cache.clear() def _create_lastmodified(path, recursive): - if path.endswith("/files"): + path = path[len("/api/files"):] + if path.startswith("/"): + path = path[1:] + + if path == "": # all storages involved lms = [0] for storage in fileManager.registered_storages: @@ -58,16 +62,13 @@ def _create_lastmodified(path, recursive): # if we reach this point, we return the maximum of all dates return max(lms) - elif path.endswith("/files/local"): - # only local storage involved - try: - return fileManager.last_modified(FileDestinations.LOCAL, recursive=recursive) - except Exception: - logging.getLogger(__name__).exception("There was an error retrieving the last modified data from storage {}".format(FileDestinations.LOCAL)) - return None - else: - return None + storage, path_in_storage = path.split("/", 1) + try: + return fileManager.last_modified(storage, path=path_in_storage, recursive=recursive) + except Exception: + logging.getLogger(__name__).exception("There was an error retrieving the last modified data from storage {} and path {}".format(storage, path_in_storage)) + return None def _create_etag(path, filter, recursive, lm=None): @@ -85,7 +86,16 @@ def _create_etag(path, filter, recursive, lm=None): hash_update(str(filter)) hash_update(str(recursive)) - if path.endswith("/files") or path.endswith("/files/sdcard"): + path = path[len("/api/files"):] + if path.startswith("/"): + path = path[1:] + + if "/" in path: + storage, _ = path.split("/", 1) + else: + storage = path + + if path == "" or storage == FileDestinations.SDCARD: # include sd data in etag hash_update(repr(sorted(printer.get_sd_files(), key=lambda x: sv(x[0])))) @@ -141,6 +151,30 @@ def readGcodeFilesForOrigin(origin): return jsonify(files=files) +@api.route("/files//", methods=["GET"]) +@Permissions.FILES_LIST.require(403) +@with_revalidation_checking(etag_factory=lambda lm=None: _create_etag(request.path, + request.values.get("filter", False), + request.values.get("recursive", False), + lm=lm), + lastmodified_factory=lambda: _create_lastmodified(request.path, + request.values.get("recursive", False)), + unless=lambda: request.values.get("force", False) or request.values.get("_refresh", False)) +def readGcodeFile(target, filename): + if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]: + return make_response("Unknown target: %s" % target, 404) + + recursive = False + if "recursive" in request.values: + recursive = request.values["recursive"] in valid_boolean_trues + + file = _getFileDetails(target, filename, recursive=recursive) + if not file: + return make_response("File not found on '%s': %s" % (target, filename), 404) + + return jsonify(file) + + def _getFileDetails(origin, path, recursive=True): parent, path = os.path.split(path) files = _getFileList(origin, path=parent, recursive=recursive) @@ -188,9 +222,10 @@ def _getFileList(origin, path=None, filter=None, recursive=False, allow_from_cac with _file_cache_mutex: cache_key = "{}:{}:{}:{}".format(origin, path, recursive, filter) files, lastmodified = _file_cache.get(cache_key, ([], None)) - if not allow_from_cache or lastmodified is None or lastmodified < fileManager.last_modified(origin, path=path, recursive=recursive): + # recursive needs to be True for lastmodified queries so we get lastmodified of whole subtree - #3422 + if not allow_from_cache or lastmodified is None or lastmodified < fileManager.last_modified(origin, path=path, recursive=True): files = list(fileManager.list_files(origin, path=path, filter=filter_func, recursive=recursive)[origin].values()) - lastmodified = fileManager.last_modified(origin, path=path, recursive=recursive) + lastmodified = fileManager.last_modified(origin, path=path, recursive=True) _file_cache[cache_key] = (files, lastmodified) def analyse_recursively(files, path=None): @@ -470,23 +505,6 @@ def uploadGcodeFile(target): return make_response("No file to upload and no folder to create", 400) -@api.route("/files//", methods=["GET"]) -@Permissions.FILES_LIST.require(403) -def readGcodeFile(target, filename): - if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]: - return make_response("Unknown target: %s" % target, 404) - - recursive = False - if "recursive" in request.values: - recursive = request.values["recursive"] in valid_boolean_trues - - file = _getFileDetails(target, filename, recursive=recursive) - if not file: - return make_response("File not found on '%s': %s" % (target, filename), 404) - - return jsonify(file) - - @api.route("/files//", methods=["POST"]) @no_firstrun_access def gcodeFileCommand(filename, target): From cf560a47d5af35e3e544d2d25e10c339226fe466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 26 Feb 2020 15:31:03 +0100 Subject: [PATCH 02/28] =?UTF-8?q?=F0=9F=94=96=20staging/maintenance=20is?= =?UTF-8?q?=20now=201.4.0rc7.dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .versioneer-lookup | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.versioneer-lookup b/.versioneer-lookup index 094d7998a..bb61500f1 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -24,13 +24,13 @@ maintenance 1.4.1 2da7aa358d950b4567aaab8f18d6b5779193e077 pep440-dev fix/.* 1.4.1 2da7aa358d950b4567aaab8f18d6b5779193e077 pep440-dev improve/.* 1.4.1 2da7aa358d950b4567aaab8f18d6b5779193e077 pep440-dev -# staging/maintenance is currently the branch for preparation of 1.4.0rc6 +# staging/maintenance is currently the branch for preparation of 1.4.0rc7 # so is regressionfix/... -staging/maintenance 1.4.0rc6 73f7c4d8a11a7aea7b0ece474d3bf37ad53c65d4 pep440-dev -regressionfix/.* 1.4.0rc6 73f7c4d8a11a7aea7b0ece474d3bf37ad53c65d4 pep440-dev +staging/maintenance 1.4.0rc7 d99af420acb9d5b18a4f60f9cae8abb458e131d4 pep440-dev +regressionfix/.* 1.4.0rc7 d99af420acb9d5b18a4f60f9cae8abb458e131d4 pep440-dev -# staging/devel is currently inactive (but has the 1.4.0rc6 namespace) -staging/devel 1.4.0rc6 73f7c4d8a11a7aea7b0ece474d3bf37ad53c65d4 pep440-dev +# staging/devel is currently inactive (but has the 1.4.0rc7 namespace) +staging/devel 1.4.0rc7 d99af420acb9d5b18a4f60f9cae8abb458e131d4 pep440-dev # every other branch is a development branch and thus gets resolved to 1.5.0-dev for now .* 1.5.0 2da7aa358d950b4567aaab8f18d6b5779193e077 pep440-dev From c37f83c6c3f6096a08f9591ae620a731f4726466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 2 Mar 2020 15:53:46 +0100 Subject: [PATCH 03/28] =?UTF-8?q?=E2=99=BB=20tracking:=20Send=20environmen?= =?UTF-8?q?t=20with=20pong?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gets us more up to date stats regarding used hardware than on the startup event. --- src/octoprint/plugins/tracking/__init__.py | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index 85fc7416d..3f495744c 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -206,11 +206,13 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, if not self._settings.get_boolean(["events", "pong"]): return + payload = self._get_environment_payload() + plugins = self._plugin_manager.enabled_plugins plugins_thirdparty = [plugin for plugin in plugins.values() if not plugin.bundled] - payload = dict(plugins=",".join(map(lambda x: "{}:{}".format(x.key.lower(), - x.version.lower() if x.version else "?"), - plugins_thirdparty))) + payload["plugins"] = ",".join(map(lambda x: "{}:{}".format(x.key.lower(), + x.version.lower() if x.version else "?"), + plugins_thirdparty)) self._track("pong", body=True, **payload) @@ -218,19 +220,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, if not self._settings.get_boolean(["events", "startup"]): return - payload = dict(version=get_octoprint_version_string(), - os=self._environment["os"]["id"], - python=self._environment["python"]["version"], - pip=self._environment["python"]["pip"], - cores=self._environment["hardware"]["cores"], - freq=self._environment["hardware"]["freq"], - ram=self._environment["hardware"]["ram"]) - - if "plugins" in self._environment and "pi_support" in self._environment["plugins"]: - payload["pi_model"] = self._environment["plugins"]["pi_support"]["model"] - - if "octopi_version" in self._environment["plugins"]["pi_support"]: - payload["octopi_version"] = self._environment["plugins"]["pi_support"]["octopi_version"] + payload = self._get_environment_payload() self._track("startup", **payload) @@ -439,6 +429,23 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, else: pass + def _get_environment_payload(self): + payload = dict(version=get_octoprint_version_string(), + os=self._environment["os"]["id"], + python=self._environment["python"]["version"], + pip=self._environment["python"]["pip"], + cores=self._environment["hardware"]["cores"], + freq=self._environment["hardware"]["freq"], + ram=self._environment["hardware"]["ram"]) + + if "plugins" in self._environment and "pi_support" in self._environment["plugins"]: + payload["pi_model"] = self._environment["plugins"]["pi_support"]["model"] + + if "octopi_version" in self._environment["plugins"]["pi_support"]: + payload["octopi_version"] = self._environment["plugins"]["pi_support"]["octopi_version"] + + return payload + __plugin_name__ = "Anonymous Usage Tracking" __plugin_description__ = "Anonymous version and usage tracking, see homepage for details on what gets tracked" __plugin_url__ = "https://tracking.octoprint.org" From 9781d5c1ff5d7344289a579edfcbd6f31d285ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 5 Mar 2020 15:41:30 +0100 Subject: [PATCH 04/28] =?UTF-8?q?=F0=9F=9A=B8=20Rewording=20of=20buttons?= =?UTF-8?q?=20in=20cancel=20confirmation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3471 --- src/octoprint/static/js/app/viewmodels/printerstate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/printerstate.js b/src/octoprint/static/js/app/viewmodels/printerstate.js index 0aee4bf56..17dfef460 100644 --- a/src/octoprint/static/js/app/viewmodels/printerstate.js +++ b/src/octoprint/static/js/app/viewmodels/printerstate.js @@ -377,8 +377,8 @@ $(function() { } else { showConfirmationDialog({ message: gettext("This will cancel your print."), - cancel: gettext("No"), - proceed: gettext("Yes"), + cancel: gettext("No, continue the print"), + proceed: gettext("Yes, cancel the print"), onproceed: function() { OctoPrint.job.cancel(); }, From 05cbe89d8798eb05533f0c4662f974d7ba18746b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 19 Mar 2020 16:45:02 +0100 Subject: [PATCH 05/28] =?UTF-8?q?=F0=9F=9A=B8=20Keep=20load&print=20button?= =?UTF-8?q?=20active=20if=20file's=20already=20loaded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For some reason people just don't seem to see the big fat blue "Print" button on their loaded print job and then get confused when they can't reprint the same file that's already loaded. So let's work around this. --- src/octoprint/static/js/app/viewmodels/files.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index c90decd0b..f63de7b57 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -648,8 +648,7 @@ $(function() { }; self.enableSelectAndPrint = function(data, printAfterSelect) { - var isLoadAndPrintActionPossible = self.isLoadAndPrintActionPossible(); - return isLoadAndPrintActionPossible && !self.listHelper.isSelected(data); + return self.isLoadAndPrintActionPossible(); }; From 27bbab9582eb3a1a9fca8f2b203e88b1682fcdc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 23 Mar 2020 16:04:33 +0100 Subject: [PATCH 06/28] =?UTF-8?q?=F0=9F=90=9B=20Don't=20mess=20with=20EOL?= =?UTF-8?q?=20style=20of=20GCODE=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue with lag in progress reporting on files that have CRLF EOLs. See also https://community.octoprint.org/t/curious-issue-with-print-progress/16304/ --- src/octoprint/util/comm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 67191a7af..a6dfc1e24 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -4078,7 +4078,7 @@ class PrintingGcodeFileInformation(PrintingFileInformation): """ PrintingFileInformation.start(self) with self._handle_mutex: - self._handle = bom_aware_open(self._filename, encoding="utf-8", errors="replace") + self._handle = bom_aware_open(self._filename, encoding="utf-8", errors="replace", newline="") self._pos = self._handle.tell() if self._handle.encoding.endswith("-sig"): # Apparently we found an utf-8 bom in the file. From 610a7ed8a8b438c33f6e3801bf49d3d704ab08f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 17 Feb 2020 15:32:52 +0100 Subject: [PATCH 07/28] =?UTF-8?q?=E2=9C=A8=20printer=5Fsafety=5Fwarning:?= =?UTF-8?q?=20Detect=20broken=20cbd=20firmware?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/printer_safety_check/__init__.py | 37 +++++++++----- .../printer_safety_check/checks/__init__.py | 5 ++ .../checks/firmware_broken.py | 48 +++++++++++++++++++ .../checks/firmware_unsafe.py | 5 +- .../static/js/printer_safety_check.js | 26 ++++++++-- .../printer_safety_check_sidebar.jinja2 | 6 +-- 6 files changed, 107 insertions(+), 20 deletions(-) create mode 100644 src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py diff --git a/src/octoprint/plugins/printer_safety_check/__init__.py b/src/octoprint/plugins/printer_safety_check/__init__.py index ffb6a2fd2..d64789c85 100644 --- a/src/octoprint/plugins/printer_safety_check/__init__.py +++ b/src/octoprint/plugins/printer_safety_check/__init__.py @@ -11,7 +11,9 @@ from octoprint.access import USER_GROUP from octoprint.access.permissions import Permissions from octoprint.util import to_unicode +from .checks import Severity from .checks.firmware_unsafe import FirmwareUnsafeChecks +from .checks.firmware_broken import FirmwareBrokenChecks import flask from flask_babel import gettext @@ -22,13 +24,14 @@ TERMINAL_SAFETY_WARNING = """ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! {message} -Learn more at https://faq.octoprint.org/warning-{warning_type} +Learn more at {url} !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! """ SAFETY_CHECKS = { - "firmware-unsafe": FirmwareUnsafeChecks.as_dict() + "firmware-unsafe": FirmwareUnsafeChecks.as_dict(), + "firmware-broken": FirmwareBrokenChecks.as_dict() } class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, @@ -46,7 +49,7 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, def get_template_configs(self): return [ dict(type="sidebar", - name=gettext("Printer Safety Warning"), + name=gettext("Attention!"), data_bind="visible: printerState.isOperational() && loginState.isAdmin() && warnings().length > 0", icon="exclamation-triangle", styles_wrapper=["display: none"]) @@ -117,6 +120,8 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, for warning_type, check_data in SAFETY_CHECKS.items(): checks = check_data.get("checks") message = check_data.get("message") + severity = check_data.get("severity", Severity.CRITICAL) + url = "https://faq.octoprint.org/warning-{warning_type}".format(warning_type=warning_type) if not checks or not message: continue @@ -139,21 +144,29 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, # check if now triggered if check.triggered: - self._register_warning(warning_type, message) + if check.url is not None: + url = check.url + + self._register_warning(warning_type, message, severity, url) # noinspection PyUnresolvedReferences self._event_bus.fire(Events.PLUGIN_PRINTER_SAFETY_CHECK_WARNING, dict(check_name=check.name, - warning_type=warning_type)) + warning_type=warning_type, + severity=severity, + url=url)) changes = True break if changes: self._ping_clients() - def _register_warning(self, warning_type, message): + def _register_warning(self, warning_type, message, severity, url): self._log_to_terminal(TERMINAL_SAFETY_WARNING.format(message="\n".join(textwrap.wrap(message, 75)), - warning_type=warning_type)) - self._warnings[warning_type] = message + warning_type=warning_type, + url=url)) + self._warnings[warning_type] = dict(message=message, + severity=severity, + url=url) def _reset_warnings(self): self._warnings.clear() @@ -190,13 +203,13 @@ __plugin_url__ = "http://docs.octoprint.org/en/master/bundledplugins/printer_saf __plugin_description__ = "Checks for unsafe printers/printer firmwares" __plugin_disabling_discouraged__ = gettext("Without this plugin OctoPrint will no longer be able to " "check if the printer it is connected to has a known safety " - "issue and inform you about that fact.") + "issue or otherwise broken firmware and inform you about that fact.") __plugin_license__ = "AGPLv3" __plugin_implementation__ = PrinterSafetyCheckPlugin() __plugin_hooks__ = { - "octoprint.comm.protocol.gcode.received": __plugin_implementation__.on_gcode_received, - "octoprint.comm.protocol.firmware.info": __plugin_implementation__.on_firmware_info_received, - "octoprint.comm.protocol.firmware.capabilities": __plugin_implementation__.on_firmware_cap_received, + "octoprint.comm.protocol.gcode.received": (__plugin_implementation__.on_gcode_received, 100), + "octoprint.comm.protocol.firmware.info": (__plugin_implementation__.on_firmware_info_received, 100), + "octoprint.comm.protocol.firmware.capabilities": (__plugin_implementation__.on_firmware_cap_received, 100), "octoprint.events.register_custom_events": register_custom_events, "octoprint.access.permissions": __plugin_implementation__.get_additional_permissions } diff --git a/src/octoprint/plugins/printer_safety_check/checks/__init__.py b/src/octoprint/plugins/printer_safety_check/checks/__init__.py index fbc4a22e4..e41e9cc27 100644 --- a/src/octoprint/plugins/printer_safety_check/checks/__init__.py +++ b/src/octoprint/plugins/printer_safety_check/checks/__init__.py @@ -7,6 +7,7 @@ __copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms class Check(object): name = None + url = None def __init__(self): self._active = True @@ -53,3 +54,7 @@ class AuthorCheck(Check): self._triggered = any(map(lambda x: x in lower_line, self.authors)) self._active = False + +class Severity(object): + INFO = "info" + CRITICAL = "critical" diff --git a/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py b/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py new file mode 100644 index 000000000..02032efc9 --- /dev/null +++ b/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals + +__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' +__copyright__ = "Copyright (C) 2020 The OctoPrint Project - Released under terms of the AGPLv3 License" + +from flask_babel import gettext +from . import Check, Severity + +class FirmwareBrokenChecks(object): + @classmethod + def as_dict(cls): + return dict(checks=(CbdCheck(),), + message=gettext("Your printer's firmware is known to have a broken implementation of the " + "communication protocol. This will cause print failures. You'll need to " + "take additional steps for OctoPrint to work with it."), + severity=Severity.INFO) + + +class CbdCheck(Check): + name = "cbd" + url = "https://faq.octoprint.org/warning-firmware-broken-cbd" + + CRITICAL_FRAGMENT = "CBD make it".lower() + + def __init__(self): + Check.__init__(self) + self._fragment_matches = None + + def received(self, line): + if not line: + return + + lower_line = line.lower() + if self.CRITICAL_FRAGMENT in lower_line: + self._fragment_matches = True + + self._evaluate() + + def _evaluate(self): + if self._fragment_matches is None: + return + self._triggered = self._fragment_matches + self._active = False + + def reset(self): + Check.reset(self) + self._fragment_matches = None diff --git a/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py b/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py index 03719772e..6b7db157d 100644 --- a/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py +++ b/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py @@ -6,7 +6,7 @@ __copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms from flask_babel import gettext from octoprint.util.version import get_comparable_version -from . import Check, AuthorCheck +from . import Check, AuthorCheck, Severity class FirmwareUnsafeChecks(object): @classmethod @@ -15,7 +15,8 @@ class FirmwareUnsafeChecks(object): MalyanM200Check(), Micro3DIMECheck(), Micro3DStockCheck(), RepetierBefore092Check(), ThermalProtectionCapCheck()), message=gettext("Your printer's firmware is known to lack mandatory safety features (e.g. " - "thermal runaway protection). This is a fire risk.")) + "thermal runaway protection). This is a fire risk."), + severity=Severity.CRITICAL) class AnetA8Check(Check): """ diff --git a/src/octoprint/plugins/printer_safety_check/static/js/printer_safety_check.js b/src/octoprint/plugins/printer_safety_check/static/js/printer_safety_check.js index 667a7999f..b25621f7a 100644 --- a/src/octoprint/plugins/printer_safety_check/static/js/printer_safety_check.js +++ b/src/octoprint/plugins/printer_safety_check/static/js/printer_safety_check.js @@ -23,8 +23,13 @@ $(function() { self.fromResponse = function(data) { var warnings = []; - _.each(data, function(message, warning_type) { - warnings.push({type: warning_type, message: gettext(message)}); + _.each(data, function(data, warning_type) { + warnings.push({ + type: warning_type, + message: gettext(data.message), + severity: data.severity, + url: data.url + }); }); self.warnings(warnings); }; @@ -44,7 +49,22 @@ $(function() { if (data.type === "update") { self.requestData(); } - } + }; + + self.cssClass = function(data) { + if (data.severity) { + return "printer_safety_warning_" + data.severity; + } else { + return undefined; + } + }; + + self.warningText = function(data) { + switch (data.severity) { + case "critical": return gettext("Critical Warning"); + default: return gettext("Warning"); + } + }; } OCTOPRINT_VIEWMODELS.push({ diff --git a/src/octoprint/plugins/printer_safety_check/templates/printer_safety_check_sidebar.jinja2 b/src/octoprint/plugins/printer_safety_check/templates/printer_safety_check_sidebar.jinja2 index a09f76812..633e063c0 100644 --- a/src/octoprint/plugins/printer_safety_check/templates/printer_safety_check_sidebar.jinja2 +++ b/src/octoprint/plugins/printer_safety_check/templates/printer_safety_check_sidebar.jinja2 @@ -1,7 +1,7 @@ -

{{ _('Warning!') }}

-

+

+


- {{ _('Learn more...') }} + {{ _('Learn more...') }}

From 8a01d890496b767b25315f7be15f42e6560a0184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 25 Mar 2020 16:03:42 +0100 Subject: [PATCH 08/28] =?UTF-8?q?=E2=9C=A8=20Detect=20ZWLF=20variant=20of?= =?UTF-8?q?=20CBD=20firmware?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/printer_safety_check/checks/firmware_broken.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py b/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py index 02032efc9..15bd4ba0d 100644 --- a/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py +++ b/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py @@ -46,3 +46,7 @@ class CbdCheck(Check): def reset(self): Check.reset(self) self._fragment_matches = None + +class ZwlfCheck(CbdCheck): + name = "zwlf" + CRITICAL_FRAGMENT = "ZWLF make it".lower() From 85ce90ca52a9ac75457455f8548d3b05b144250b Mon Sep 17 00:00:00 2001 From: ted Date: Thu, 26 Mar 2020 12:03:12 -0700 Subject: [PATCH 09/28] fix NoneType comparison error, closes #3493 --- src/octoprint/util/comm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 67191a7af..fd43f8fa2 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2537,7 +2537,7 @@ class MachineCom(object): tools = self.last_temperature.tools for temp in [tools[k][1] for k in tools.keys()]: - if temp > self._temperatureTargetSetThreshold: + if temp and temp > self._temperatureTargetSetThreshold: return get("temperatureTargetSet", target_default) bed = self.last_temperature.bed From 761a0fdb61a8d51bce8c021aa8b61d6fdc0bc4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 27 Mar 2020 15:42:06 +0100 Subject: [PATCH 10/28] =?UTF-8?q?=E2=99=BB=20Extract=20printer=20safety=20?= =?UTF-8?q?warning=20into=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renamed to firmware check, published to PyPI, on a different release cycle and version number scheme than core OctoPrint but still considered bundled via a new mechanism to mark external plugins as such. This will speed up deployment of new firmware checks in case of new printers with disabled thermal runaway protection, or stuff like the CBD firmware. --- docs/bundledplugins/firmware_check.rst | 7 + docs/bundledplugins/printer_safety_check.rst | 52 ----- setup.py | 3 + src/octoprint/plugin/__init__.py | 8 +- src/octoprint/plugin/core.py | 21 +- .../plugins/printer_safety_check/__init__.py | 216 ------------------ .../printer_safety_check/checks/__init__.py | 60 ----- .../checks/firmware_broken.py | 52 ----- .../checks/firmware_unsafe.py | 181 --------------- .../static/clientjs/printer_safety_check.js | 18 -- .../static/css/printer_safety_check.css | 1 - .../static/js/printer_safety_check.js | 76 ------ .../static/less/printer_safety_check.less | 15 -- .../printer_safety_check_sidebar.jinja2 | 7 - src/octoprint/settings.py | 2 +- 15 files changed, 31 insertions(+), 688 deletions(-) create mode 100644 docs/bundledplugins/firmware_check.rst delete mode 100644 docs/bundledplugins/printer_safety_check.rst delete mode 100644 src/octoprint/plugins/printer_safety_check/__init__.py delete mode 100644 src/octoprint/plugins/printer_safety_check/checks/__init__.py delete mode 100644 src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py delete mode 100644 src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py delete mode 100644 src/octoprint/plugins/printer_safety_check/static/clientjs/printer_safety_check.js delete mode 100644 src/octoprint/plugins/printer_safety_check/static/css/printer_safety_check.css delete mode 100644 src/octoprint/plugins/printer_safety_check/static/js/printer_safety_check.js delete mode 100644 src/octoprint/plugins/printer_safety_check/static/less/printer_safety_check.less delete mode 100644 src/octoprint/plugins/printer_safety_check/templates/printer_safety_check_sidebar.jinja2 diff --git a/docs/bundledplugins/firmware_check.rst b/docs/bundledplugins/firmware_check.rst new file mode 100644 index 000000000..ceb071039 --- /dev/null +++ b/docs/bundledplugins/firmware_check.rst @@ -0,0 +1,7 @@ +.. _sec-bundledplugins-firmware_check: + +Firmware Check +============== + +The firmware check plugin - while considered bundled with OctoPrint - is a separate project on its own release +cycle and documented on :ref:`its Github repository `_. diff --git a/docs/bundledplugins/printer_safety_check.rst b/docs/bundledplugins/printer_safety_check.rst deleted file mode 100644 index 320de9053..000000000 --- a/docs/bundledplugins/printer_safety_check.rst +++ /dev/null @@ -1,52 +0,0 @@ -.. _sec-bundledplugins-printer_safety_check: - -Printer Safety Check -==================== - -The Printer Safety Check plugin comes bundled with OctoPrint starting with version 1.3.7. - -It tries to identify printers or rather printer firmwares with known safety issues, such as -disabled thermal runaway protection, and displays a warning box to logged in users on -such identification. - -.. _fig-bundledplugins-printer_safety_check-example: -.. figure:: ../images/bundledplugins-printer_safety_check-example.png - :align: center - :alt: Printer Safety Check warning example - - An example of a warning generated by the Printer Safety Check - -Please refer to the `entry on the "unsafe firmware" warning in OctoPrint's FAQ `_ -for a list of currently identified printers. - -If you know of further printers/printer firmwares that need to be added here, please -`get in touch on the forum and provide their response to an M115 `_. - -.. note:: - - Feel free to disable the plugin in OctoPrint's Plugin Manager if you feel like it is unnecessary. Be advised though - that even if your printer might be running totally fine with a known unsafe configuration, that might change - unexpectedly and with `catastrophic `_ - `results `_. - -.. _sec-bundledplugins-printer_safety_check-events: - -Events ------- - -warning - A printer safety warning was triggered. - - Payload: - - * ``check_type``: type of check that was triggered (e.g. ``m115``, ``received`` or ``cap``) - * ``check_name``: name of check that was triggered (e.g. ``aneta8``) - * ``warning_type``: type of warning that was triggered (e.g. ``firmware-unsafe``) - -.. _sec-bundledplugins-printer_safety_check-source: - -Source Code ------------ - -The source of the Printer Safety Check plugin is bundled with OctoPrint and can be -found in its source repository under ``src/octoprint/plugins/printer_safety_check``. diff --git a/setup.py b/setup.py index 6724f3ff4..91245addd 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,9 @@ SETUP_REQUIRES = [ # Requirements for our application INSTALL_REQUIRES = [ + # additional OctoPrint plugins that are maintained on a different release cycle + "OctoPrint-FirmwareCheck>=2020.03.27", + # the following dependencies are non trivial to update since later versions introduce backwards incompatible # changes that might affect plugins, or due to other observed problems diff --git a/src/octoprint/plugin/__init__.py b/src/octoprint/plugin/__init__.py index e718a7aa3..1f3439374 100644 --- a/src/octoprint/plugin/__init__.py +++ b/src/octoprint/plugin/__init__.py @@ -38,7 +38,7 @@ def _validate_plugin(phase, plugin_info): def plugin_manager(init=False, plugin_folders=None, plugin_bases=None, plugin_entry_points=None, plugin_disabled_list=None, plugin_blacklist=None, plugin_restart_needing_hooks=None, plugin_obsolete_hooks=None, - plugin_validators=None, compatibility_ignored_list=None): + plugin_considered_bundled=None, plugin_validators=None, compatibility_ignored_list=None): """ Factory method for initially constructing and consecutively retrieving the :class:`~octoprint.plugin.core.PluginManager` singleton. @@ -63,6 +63,8 @@ def plugin_manager(init=False, plugin_folders=None, plugin_bases=None, plugin_en to logging handlers plugin_obsolete_hooks (list): A list of hooks that have been declared obsolete. Plugins implementing them will not be enabled since they might depend on functionality that is no longer available. + plugin_considered_bundled (list): A list of plugin identifiers that are considered bundled plugins even if + installed separately. plugin_validators (list): A list of additional plugin validators through which to process each plugin. compatibility_ignored_list (list): A list of plugin keys for which it will be ignored if they are flagged as incompatible. This is for development purposes only and should not be used in production. @@ -95,6 +97,9 @@ def plugin_manager(init=False, plugin_folders=None, plugin_bases=None, plugin_en if plugin_obsolete_hooks is None: plugin_obsolete_hooks = ["octoprint.comm.protocol.gcode"] + if plugin_considered_bundled is None: + plugin_considered_bundled = ["firmware_check"] + if plugin_validators is None: plugin_validators = [_validate_plugin] else: @@ -108,6 +113,7 @@ def plugin_manager(init=False, plugin_folders=None, plugin_bases=None, plugin_en plugin_blacklist=plugin_blacklist, plugin_restart_needing_hooks=plugin_restart_needing_hooks, plugin_obsolete_hooks=plugin_obsolete_hooks, + plugin_considered_bundled=plugin_considered_bundled, plugin_validators=plugin_validators, compatibility_ignored_list=compatibility_ignored_list) else: diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index f7956fe5e..4c900687a 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -119,21 +119,21 @@ class PluginInfo(object): """ Module attribute from which to retrieve the plugin's license. """ attr_pythoncompat = '__plugin_pythoncompat__' - """ - Module attribute from which to retrieve the plugin's python compatibility string. - + """ + Module attribute from which to retrieve the plugin's python compatibility string. + If unset a default of ``>=2.7,<3`` will be assumed, meaning that the plugin will be considered compatible to Python 2 but not Python 3. - + To mark a plugin as Python 3 compatible, a string of ``>=2.7,<4`` is recommended. - + Bundled plugins will automatically be assumed to be compatible. """ attr_hidden = '__plugin_hidden__' """ Module attribute from which to determine if the plugin's hidden or not. - + Only evaluated for bundled plugins, in order to hide them from the Plugin Manager and similar places. """ @@ -649,7 +649,8 @@ class PluginManager(object): def __init__(self, plugin_folders, plugin_bases, plugin_entry_points, logging_prefix=None, plugin_disabled_list=None, plugin_blacklist=None, plugin_restart_needing_hooks=None, - plugin_obsolete_hooks=None, plugin_validators=None, compatibility_ignored_list=None): + plugin_obsolete_hooks=None, plugin_considered_bundled=None, plugin_validators=None, + compatibility_ignored_list=None): self.logger = logging.getLogger(__name__) if logging_prefix is None: @@ -666,6 +667,8 @@ class PluginManager(object): plugin_blacklist = [] if compatibility_ignored_list is None: compatibility_ignored_list = [] + if plugin_considered_bundled is None: + plugin_considered_bundled = [] self.plugin_folders = plugin_folders self.plugin_bases = plugin_bases @@ -677,6 +680,7 @@ class PluginManager(object): self.plugin_validators = plugin_validators self.logging_prefix = logging_prefix self.compatibility_ignored_list = compatibility_ignored_list + self.plugin_considered_bundled = plugin_considered_bundled self.enabled_plugins = dict() self.disabled_plugins = dict() @@ -878,7 +882,8 @@ class PluginManager(object): # plugin is already defined or marked as uninstalled, ignore it continue - kwargs = dict(module_name=module_name, version=version) + bundled = key in self.plugin_considered_bundled + kwargs = dict(module_name=module_name, version=version, bundled=bundled) package_name = entry_point.dist.project_name try: entry_point_metadata = EntryPointMetadata(entry_point) diff --git a/src/octoprint/plugins/printer_safety_check/__init__.py b/src/octoprint/plugins/printer_safety_check/__init__.py deleted file mode 100644 index d64789c85..000000000 --- a/src/octoprint/plugins/printer_safety_check/__init__.py +++ /dev/null @@ -1,216 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, division, print_function, unicode_literals - -__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' -__copyright__ = "Copyright (C) 2018 The OctoPrint Project - Released under terms of the AGPLv3 License" - -import octoprint.plugin - -from octoprint.events import Events -from octoprint.access import USER_GROUP -from octoprint.access.permissions import Permissions -from octoprint.util import to_unicode - -from .checks import Severity -from .checks.firmware_unsafe import FirmwareUnsafeChecks -from .checks.firmware_broken import FirmwareBrokenChecks - -import flask -from flask_babel import gettext - -import textwrap - -TERMINAL_SAFETY_WARNING = """ -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -{message} - -Learn more at {url} -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -""" - -SAFETY_CHECKS = { - "firmware-unsafe": FirmwareUnsafeChecks.as_dict(), - "firmware-broken": FirmwareBrokenChecks.as_dict() -} - -class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, - octoprint.plugin.EventHandlerPlugin, - octoprint.plugin.SimpleApiPlugin, - octoprint.plugin.TemplatePlugin): - - # noinspection PyMissingConstructor - def __init__(self): - self._warnings = dict() - self._scan_received = True - - ##~~ TemplatePlugin API - - def get_template_configs(self): - return [ - dict(type="sidebar", - name=gettext("Attention!"), - data_bind="visible: printerState.isOperational() && loginState.isAdmin() && warnings().length > 0", - icon="exclamation-triangle", - styles_wrapper=["display: none"]) - ] - - ##~~ AssetPlugin API - - def get_assets(self): - return dict(js=("js/printer_safety_check.js",), - clientjs=("clientjs/printer_safety_check.js",), - css=("css/printer_safety_check.css",), - less=("less/printer_safety_check.less",)) - - ##~~ EventHandlerPlugin API - - def on_event(self, event, payload): - if event == Events.DISCONNECTED: - self._reset_warnings() - self._reset_state() - self._reset_checks() - - ##~~ SimpleApiPlugin API - - def on_api_get(self, request): - if not Permissions.PLUGIN_PRINTER_SAFETY_CHECK_DISPLAY.can(): - return flask.make_response("Insufficient rights", 403) - return flask.jsonify(self._warnings) - - ##~~ GCODE received hook handler - - def on_gcode_received(self, comm_instance, line, *args, **kwargs): - if self._scan_received: - self._run_checks("received", to_unicode(line, errors="replace")) - return line - - ##~~ Firmware info hook handler - - def on_firmware_info_received(self, comm_instance, firmware_name, firmware_data): - self._run_checks("m115", - to_unicode(firmware_name, errors="replace"), - dict((to_unicode(key, errors="replace"), to_unicode(value, errors="replace")) - for key, value in firmware_data.items())) - self._scan_received = False - - ##~~ Firmware capability hook handler - - def on_firmware_cap_received(self, comm_instance, cap, enabled, all_caps): - self._run_checks("cap", - to_unicode(cap, errors="replace"), - enabled) - - ##~~ Additional permissions hook handler - - def get_additional_permissions(self): - return [ - dict(key="DISPLAY", - name="Display printer safety warnings", - description=gettext("Allows to see printer safety warnings"), - roles=["display"], - default_groups=[USER_GROUP]) - ] - - ##~~ Helpers - - def _run_checks(self, check_type, *args, **kwargs): - changes = False - - for warning_type, check_data in SAFETY_CHECKS.items(): - checks = check_data.get("checks") - message = check_data.get("message") - severity = check_data.get("severity", Severity.CRITICAL) - url = "https://faq.octoprint.org/warning-{warning_type}".format(warning_type=warning_type) - if not checks or not message: - continue - - for check in checks: - if not check.active: - # skip non active checks - continue - - method = getattr(check, check_type, None) - if not callable(method): - # skip uncallable checks - continue - - # execute method - try: - method(*args, **kwargs) - except Exception: - self._logger.exception("There was an error running method {} on check {!r}".format(check_type, check)) - continue - - # check if now triggered - if check.triggered: - if check.url is not None: - url = check.url - - self._register_warning(warning_type, message, severity, url) - - # noinspection PyUnresolvedReferences - self._event_bus.fire(Events.PLUGIN_PRINTER_SAFETY_CHECK_WARNING, dict(check_name=check.name, - warning_type=warning_type, - severity=severity, - url=url)) - changes = True - break - - if changes: - self._ping_clients() - - def _register_warning(self, warning_type, message, severity, url): - self._log_to_terminal(TERMINAL_SAFETY_WARNING.format(message="\n".join(textwrap.wrap(message, 75)), - warning_type=warning_type, - url=url)) - self._warnings[warning_type] = dict(message=message, - severity=severity, - url=url) - - def _reset_warnings(self): - self._warnings.clear() - self._ping_clients() - - def _reset_state(self): - self._scan_received = True - - def _reset_checks(self): - for warning_type, check_data in SAFETY_CHECKS.items(): - checks = check_data.get("checks") - if not checks: - continue - - for check in checks: - check.reset() - - def _log_to_terminal(self, message): - if self._printer: - lines = message.split("\n") - self._printer.log_lines(*lines) - - def _ping_clients(self): - self._plugin_manager.send_plugin_message(self._identifier, dict(type="update")) - - -def register_custom_events(*args, **kwargs): - return ["warning",] - - -__plugin_name__ = "Printer Safety Check" -__plugin_author__ = "Gina Häußge" -__plugin_url__ = "http://docs.octoprint.org/en/master/bundledplugins/printer_safety_check.html" -__plugin_description__ = "Checks for unsafe printers/printer firmwares" -__plugin_disabling_discouraged__ = gettext("Without this plugin OctoPrint will no longer be able to " - "check if the printer it is connected to has a known safety " - "issue or otherwise broken firmware and inform you about that fact.") -__plugin_license__ = "AGPLv3" -__plugin_implementation__ = PrinterSafetyCheckPlugin() -__plugin_hooks__ = { - "octoprint.comm.protocol.gcode.received": (__plugin_implementation__.on_gcode_received, 100), - "octoprint.comm.protocol.firmware.info": (__plugin_implementation__.on_firmware_info_received, 100), - "octoprint.comm.protocol.firmware.capabilities": (__plugin_implementation__.on_firmware_cap_received, 100), - "octoprint.events.register_custom_events": register_custom_events, - "octoprint.access.permissions": __plugin_implementation__.get_additional_permissions -} - diff --git a/src/octoprint/plugins/printer_safety_check/checks/__init__.py b/src/octoprint/plugins/printer_safety_check/checks/__init__.py deleted file mode 100644 index e41e9cc27..000000000 --- a/src/octoprint/plugins/printer_safety_check/checks/__init__.py +++ /dev/null @@ -1,60 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, division, print_function, unicode_literals - -__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' -__copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms of the AGPLv3 License" - - -class Check(object): - name = None - url = None - - def __init__(self): - self._active = True - self._triggered = False - - def received(self, line): - """Called when receiving a new line from the printer""" - pass - - def m115(self, name, data): - """Called when receiving the response to an M115 from the printer""" - pass - - def cap(self, cap, enabled): - """Called when receiving a capability report line""" - pass - - @property - def active(self): - """Whether this check is still active""" - return self._active - - @property - def triggered(self): - """Whether the check has been triggered""" - return self._triggered - - def reset(self): - self._active = True - self._triggered = False - - -class AuthorCheck(Check): - authors = () - - AUTHOR = "| Author: ".lower() - - def received(self, line): - if not line: - return - - lower_line = line.lower() - if self.AUTHOR in lower_line: - self._triggered = any(map(lambda x: x in lower_line, self.authors)) - self._active = False - - -class Severity(object): - INFO = "info" - CRITICAL = "critical" diff --git a/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py b/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py deleted file mode 100644 index 15bd4ba0d..000000000 --- a/src/octoprint/plugins/printer_safety_check/checks/firmware_broken.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, division, print_function, unicode_literals - -__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' -__copyright__ = "Copyright (C) 2020 The OctoPrint Project - Released under terms of the AGPLv3 License" - -from flask_babel import gettext -from . import Check, Severity - -class FirmwareBrokenChecks(object): - @classmethod - def as_dict(cls): - return dict(checks=(CbdCheck(),), - message=gettext("Your printer's firmware is known to have a broken implementation of the " - "communication protocol. This will cause print failures. You'll need to " - "take additional steps for OctoPrint to work with it."), - severity=Severity.INFO) - - -class CbdCheck(Check): - name = "cbd" - url = "https://faq.octoprint.org/warning-firmware-broken-cbd" - - CRITICAL_FRAGMENT = "CBD make it".lower() - - def __init__(self): - Check.__init__(self) - self._fragment_matches = None - - def received(self, line): - if not line: - return - - lower_line = line.lower() - if self.CRITICAL_FRAGMENT in lower_line: - self._fragment_matches = True - - self._evaluate() - - def _evaluate(self): - if self._fragment_matches is None: - return - self._triggered = self._fragment_matches - self._active = False - - def reset(self): - Check.reset(self) - self._fragment_matches = None - -class ZwlfCheck(CbdCheck): - name = "zwlf" - CRITICAL_FRAGMENT = "ZWLF make it".lower() diff --git a/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py b/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py deleted file mode 100644 index 6b7db157d..000000000 --- a/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py +++ /dev/null @@ -1,181 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, division, print_function, unicode_literals - -__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' -__copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms of the AGPLv3 License" - -from flask_babel import gettext -from octoprint.util.version import get_comparable_version -from . import Check, AuthorCheck, Severity - -class FirmwareUnsafeChecks(object): - @classmethod - def as_dict(cls): - return dict(checks=(AnetA8Check(), AnycubicCheck(), CrealityCR10sCheck(), CrealityEnder3Check(), - MalyanM200Check(), Micro3DIMECheck(), Micro3DStockCheck(), RepetierBefore092Check(), - ThermalProtectionCapCheck()), - message=gettext("Your printer's firmware is known to lack mandatory safety features (e.g. " - "thermal runaway protection). This is a fire risk."), - severity=Severity.CRITICAL) - -class AnetA8Check(Check): - """ - Anet A8 stock firmware - - Identified through firmware name "ANET_A8_". - """ - name = "anet_a8" - - def m115(self, name, data): - self._triggered = name and name.lower().startswith("anet_a8_") - self._active = False - -class AnycubicCheck(Check): - """ - Anycubic MEGA stock firmware - - Identified through "Author: (Jolly, xxxxxxxx.CO.)" or "| Author: (**Jolly, xxxxxxxx.CO.**)" in startup messages - combined with "echo:Vx.y.z" in startup messages, with x.y.z < 1.1.2. - """ - name = "anycubic" - - AUTHOR = "| Author: ".lower() - VERSION = "echo:V" - - CRITICAL_AUTHOR1 = "| Author: (Jolly, xxxxxxxx.CO.)".lower() - CRITICAL_AUTHOR2 = "| Author: (**Jolly, xxxxxxxx.CO.**)".lower() - - FIXED_VERSION = get_comparable_version("1.1.2") - - def __init__(self): - Check.__init__(self) - self._author_matches = None - self._version_matches = None - - def received(self, line): - if not line: - return - - lower_line = line.lower() - if self.AUTHOR in lower_line: - self._author_matches = self.CRITICAL_AUTHOR1 in lower_line or self.CRITICAL_AUTHOR2 in lower_line - elif line.startswith(self.VERSION): - self._version_matches = self._broken_version(line) - else: - return - - self._evaluate() - - def _broken_version(self, line): - version_str = line[len(self.VERSION):] - version = get_comparable_version(version_str, base=True) - if version is not None and version < self.FIXED_VERSION: - return True - else: - return False - - def _evaluate(self): - if self._author_matches is None or self._version_matches is None: - return - self._triggered = self._author_matches and self._version_matches - self._active = False - - def reset(self): - Check.reset(self) - self._author_matches = None - self._version_matches = None - -class CrealityCR10sCheck(AuthorCheck): - """ - Creality CR10s - - Identified through " | Author: (CR-10Slanguage)" in startup messages. - """ - name = "creality_cr10s" - authors = (" | Author: (CR-10Slanguage)".lower(),) - -class CrealityEnder3Check(AuthorCheck): - """ - Creality Ender3 - - Identified through " | Author: (Ender3)" in startup messages. - """ - name = "creality_ender3" - authors = (" | Author: (Ender3)".lower(),) - -class MalyanM200Check(Check): - """ - Malyan M200 stock firmware prior to version 4.0 - - Identified through firmware name "Malyan*", model "M200" and version < 4.0. - """ - name = "malyan_m200" - - FIXED_VERSION = get_comparable_version("4.0") - - def m115(self, name, data): - self._triggered = name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < self.FIXED_VERSION - self._active = False - -class Micro3DIMECheck(Check): - """ - Micro3D with IME firmware - - Identified through firmware name "iME*". - """ - name = "micro3d_ime" - - def m115(self, name, data): - self._triggered = name and name.lower().startswith("ime") - self._active = False - -class Micro3DStockCheck(Check): - """ - Micro3D with IME firmware - - Identified through firmware name "Micro3D*". - """ - name = "micro3d" - - def m115(self, name, data): - self._triggered = name and name.lower().startswith("micro3d") - self._active = False - -class RepetierBefore092Check(Check): - """ - Repetier firmware prior to version 0.92 - - Identified through firmware name "Repetier_x.y.z" with x.y.z < 0.92 - """ - name = "repetier_before_092" - - FIXED_VERSION = get_comparable_version("0.92") - - def m115(self, name, data): - if name and name.lower().startswith("repetier"): - version = self._extract_repetier_version(name) - self._triggered = version is not None and version < self.FIXED_VERSION - self._active = False - - def _extract_repetier_version(self, name): - """ - Extracts the Repetier version number from the firmware name. - - Example: "Repetier_0.91" => 0.91 - """ - version = None - if "_" in name: - _, version = name.split("_", 1) - version = get_comparable_version(version, base=True) - return version - -class ThermalProtectionCapCheck(Check): - """ - Firmware reporting disabled THERMAL_PROTECTION capability - """ - name = "capability" - - def cap(self, cap, enabled): - if cap == "THERMAL_PROTECTION": - self._triggered = not enabled - self._active = False diff --git a/src/octoprint/plugins/printer_safety_check/static/clientjs/printer_safety_check.js b/src/octoprint/plugins/printer_safety_check/static/clientjs/printer_safety_check.js deleted file mode 100644 index 5a52fc4f9..000000000 --- a/src/octoprint/plugins/printer_safety_check/static/clientjs/printer_safety_check.js +++ /dev/null @@ -1,18 +0,0 @@ -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["OctoPrintClient"], factory); - } else { - factory(global.OctoPrintClient); - } -})(this, function(OctoPrintClient) { - var OctoPrintPrinterSafetyCheckClient = function(base) { - this.base = base; - }; - - OctoPrintPrinterSafetyCheckClient.prototype.get = function(opts) { - return this.base.get(this.base.getSimpleApiUrl("printer_safety_check"), opts); - }; - - OctoPrintClient.registerPluginComponent("printer_safety_check", OctoPrintPrinterSafetyCheckClient); - return OctoPrintPrinterSafetyCheckClient; -}); diff --git a/src/octoprint/plugins/printer_safety_check/static/css/printer_safety_check.css b/src/octoprint/plugins/printer_safety_check/static/css/printer_safety_check.css deleted file mode 100644 index b806ecf6a..000000000 --- a/src/octoprint/plugins/printer_safety_check/static/css/printer_safety_check.css +++ /dev/null @@ -1 +0,0 @@ -#sidebar_plugin_printer_safety_check_wrapper{border:1px solid #b94a48}#sidebar_plugin_printer_safety_check_wrapper .accordion-heading{background-color:#b94a48;font-weight:700;color:#fff}#sidebar_plugin_printer_safety_check_wrapper .accordion-heading .icon-black,#sidebar_plugin_printer_safety_check_wrapper .accordion-heading a,#sidebar_plugin_printer_safety_check_wrapper .accordion-heading a:active,#sidebar_plugin_printer_safety_check_wrapper .accordion-heading a:hover,#sidebar_plugin_printer_safety_check_wrapper .accordion-heading a:visited{color:#fff} \ No newline at end of file diff --git a/src/octoprint/plugins/printer_safety_check/static/js/printer_safety_check.js b/src/octoprint/plugins/printer_safety_check/static/js/printer_safety_check.js deleted file mode 100644 index b25621f7a..000000000 --- a/src/octoprint/plugins/printer_safety_check/static/js/printer_safety_check.js +++ /dev/null @@ -1,76 +0,0 @@ -$(function() { - function PrinterSafetyCheckViewModel(parameters) { - var self = this; - - self.loginState = parameters[0]; - self.printerState = parameters[1]; - self.access = parameters[2]; - - self.warnings = ko.observableArray([]); - - self.requestData = function() { - if (!self.loginState.hasPermission(self.access.permissions.PLUGIN_PRINTER_SAFETY_CHECK_DISPLAY)) { - self.warnings([]); - return; - } - - OctoPrint.plugins.printer_safety_check.get() - .done(self.fromResponse) - .fail(function() { - self.warnings([]); - }); - }; - - self.fromResponse = function(data) { - var warnings = []; - _.each(data, function(data, warning_type) { - warnings.push({ - type: warning_type, - message: gettext(data.message), - severity: data.severity, - url: data.url - }); - }); - self.warnings(warnings); - }; - - self.onStartup = function() { - self.requestData(); - }; - - self.onUserPermissionsChanged = self.onUserLoggedIn = self.onUserLoggedOut = function() { - self.requestData(); - }; - - self.onDataUpdaterPluginMessage = function(plugin, data) { - if (plugin !== "printer_safety_check") return; - if (!data.hasOwnProperty("type")) return; - - if (data.type === "update") { - self.requestData(); - } - }; - - self.cssClass = function(data) { - if (data.severity) { - return "printer_safety_warning_" + data.severity; - } else { - return undefined; - } - }; - - self.warningText = function(data) { - switch (data.severity) { - case "critical": return gettext("Critical Warning"); - default: return gettext("Warning"); - } - }; - } - - OCTOPRINT_VIEWMODELS.push({ - construct: PrinterSafetyCheckViewModel, - dependencies: ["loginStateViewModel", "printerStateViewModel", "accessViewModel"], - elements: ["#sidebar_plugin_printer_safety_check_wrapper"] - }); -}); - diff --git a/src/octoprint/plugins/printer_safety_check/static/less/printer_safety_check.less b/src/octoprint/plugins/printer_safety_check/static/less/printer_safety_check.less deleted file mode 100644 index 3dc124f1b..000000000 --- a/src/octoprint/plugins/printer_safety_check/static/less/printer_safety_check.less +++ /dev/null @@ -1,15 +0,0 @@ -#sidebar_plugin_printer_safety_check_wrapper { - border: 1px solid #b94a48; - - .accordion-heading { - background-color: #b94a48; - font-weight: bold; - color: #fff; - a, a:hover, a:visited, a:active { - color: #fff; - } - .icon-black { - color: #fff; - } - } -} diff --git a/src/octoprint/plugins/printer_safety_check/templates/printer_safety_check_sidebar.jinja2 b/src/octoprint/plugins/printer_safety_check/templates/printer_safety_check_sidebar.jinja2 deleted file mode 100644 index 633e063c0..000000000 --- a/src/octoprint/plugins/printer_safety_check/templates/printer_safety_check_sidebar.jinja2 +++ /dev/null @@ -1,7 +0,0 @@ - -

-

-
- {{ _('Learn more...') }} -

- diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 9fea4198b..7d134dbb7 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -315,7 +315,7 @@ default_settings = { "components": { "order": { "navbar": ["settings", "systemmenu", "plugin_announcements", "plugin_pi_support", "login"], - "sidebar": ["plugin_printer_safety_check", "connection", "state", "files"], + "sidebar": ["plugin_firmware_check", "connection", "state", "files"], "tab": ["temperature", "control", "gcodeviewer", "terminal", "timelapse"], "settings": [ "section_printer", "serial", "printerprofiles", "temperatures", "terminalfilters", "gcodescripts", From 5596daf34668b90fa851ff2b3b0f1730413c7d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 30 Mar 2020 15:41:26 +0200 Subject: [PATCH 11/28] =?UTF-8?q?=F0=9F=93=9D=20foosel/OctoPrint=20->=20Oc?= =?UTF-8?q?toPrint/OctoPrint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The github repository has moved to the organization, update README accordingly. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0e4ac5f3a..c070609ef 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # OctoPrint -![GitHub release](https://img.shields.io/github/release/foosel/OctoPrint.svg?colorB=brightgreen) -[![Travis build status](https://img.shields.io/travis/foosel/OctoPrint.svg)](https://travis-ci.org/foosel/OctoPrint) +![GitHub release](https://img.shields.io/github/release/OctoPrint/OctoPrint.svg?colorB=brightgreen) +[![Travis build status](https://img.shields.io/travis/OctoPrint/OctoPrint.svg)](https://travis-ci.org/OctoPrint/OctoPrint) [![Discourse topics](https://img.shields.io/discourse/https/community.octoprint.org/users.svg)](https://community.octoprint.org) [![IRC](https://img.shields.io/badge/chat-on%20irc-brightgreen.svg)](https://chat.octoprint.org) [![Twitter Follow](https://img.shields.io/twitter/follow/OctoPrint3d.svg?style=social&label=Follow)](https://twitter.com/OctoPrint3d) @@ -30,7 +30,7 @@ If you enjoy OctoPrint, please consider becoming a regular supporter!** You are currently looking at the source code repository of OctoPrint. If you already installed it (e.g. by using the Raspberry Pi targeted distribution [OctoPi](https://github.com/guysoft/OctoPi)) and only -want to find out how to use it, [the documentation](http://docs.octoprint.org/) and [the public wiki](https://github.com/foosel/OctoPrint/wiki) +want to find out how to use it, [the documentation](http://docs.octoprint.org/) and [the public wiki](https://github.com/OctoPrint/OctoPrint/wiki) might be of more interest for you. You might also want to subscribe to join [the community forum at community.octoprint.org](https://community.octoprint.org) where there are other active users who might be able to help you with any questions you might have. @@ -38,8 +38,8 @@ able to help you with any questions you might have. ## Contributing Contributions of all kinds are welcome, not only in the form of code but also with regards to the -[official documentation](http://docs.octoprint.org/) or [the public wiki](https://github.com/foosel/OctoPrint/wiki), debugging help -in the [bug tracker](https://github.com/foosel/OctoPrint/issues), support of other users on +[official documentation](http://docs.octoprint.org/) or [the public wiki](https://github.com/OctoPrint/OctoPrint/wiki), debugging help +in the [bug tracker](https://github.com/OctoPrint/OctoPrint/issues), support of other users on [the community forum at community.octoprint.org](https://community.octoprint.org) and also [financially](https://octoprint.org/support-octoprint/?utm_source=github&utm_medium=readme). @@ -48,12 +48,12 @@ in any way to make it better instead of just complaining about it -- this is an after all :) For information about how to go about submitting bug reports or pull requests, please see the project's -[Contribution Guidelines](https://github.com/foosel/OctoPrint/blob/master/CONTRIBUTING.md). +[Contribution Guidelines](https://github.com/OctoPrint/OctoPrint/blob/master/CONTRIBUTING.md). ## Installation Installation instructions for installing from source for different operating -systems can be found [on the wiki](https://github.com/foosel/OctoPrint/wiki#assorted-guides). +systems can be found [on the wiki](https://github.com/OctoPrint/OctoPrint/wiki#assorted-guides). If you want to run OctoPrint on a Raspberry Pi, you might want to take a look at [OctoPi](https://github.com/guysoft/OctoPi) which is a custom SD card image that includes OctoPrint plus dependencies. @@ -63,7 +63,7 @@ and runtime environment are the following (as *regular user*, please keep your hands *off* of the `sudo` command here!) - this assumes you already have Python 2.7, 3.6 or 3.7, pip and virtualenv set up on your system: -1. Checkout OctoPrint: `git clone https://github.com/foosel/OctoPrint.git` +1. Checkout OctoPrint: `git clone https://github.com/OctoPrint/OctoPrint.git` 2. Change into the OctoPrint folder: `cd OctoPrint` 3. Create a user-owned virtual environment therein: `virtualenv venv` if your system default python version is python 2.7, otherwise you need to specify the version explicitly, e.g. `virtualenv --python=python2.7 venv`. From b63eec3e919edb618f06ae192b2a80e686d94d1b Mon Sep 17 00:00:00 2001 From: Shawn Bruce Date: Mon, 30 Mar 2020 22:42:21 -0400 Subject: [PATCH 12/28] restore from backup wizard proof of concept --- .../corewizard/static/js/corewizard.js | 28 +++++++++++++++++++ .../plugins/corewizard/subwizards.py | 14 ++++++++++ .../corewizard_backuprestore_wizard.jinja2 | 9 ++++++ 3 files changed, 51 insertions(+) create mode 100644 src/octoprint/plugins/corewizard/templates/corewizard_backuprestore_wizard.jinja2 diff --git a/src/octoprint/plugins/corewizard/static/js/corewizard.js b/src/octoprint/plugins/corewizard/static/js/corewizard.js index 5f3dfa7d0..e7dd12797 100644 --- a/src/octoprint/plugins/corewizard/static/js/corewizard.js +++ b/src/octoprint/plugins/corewizard/static/js/corewizard.js @@ -313,6 +313,30 @@ $(function() { }; } + function CoreWizardBackupRestoreViewModel(parameters) { + var self = this; + + self.required = false; + + self.onWizardDetails = function(response) { + if (!self.required) return; + }; + + self.onWizardFinish = function() { + if (!self.required) return; + }; + + self.showRestoreFromBackup = function() { + $showRestorePluginDialogCallback = function () { + OctoPrint.coreui.viewmodels.wizardViewModel.closeDialog(); + $("#settings_dialog_menu").hide() + OctoPrint.coreui.viewmodels.settingsViewModel.show("settings_plugin_backup"); + } + + OctoPrint.coreui.viewmodels.coreWizardAclViewModel._sendData({"ac": false}, $showRestorePluginDialogCallback); + }; + } + OCTOPRINT_VIEWMODELS.push({ construct: CoreWizardAclViewModel, dependencies: ["loginStateViewModel"], @@ -337,5 +361,9 @@ $(function() { construct: CoreWizardPrinterProfileViewModel, dependencies: ["printerProfilesViewModel"], elements: ["#wizard_plugin_corewizard_printerprofile"] + }, { + construct: CoreWizardBackupRestoreViewModel, + dependencies: ["settingsViewModel"], + elements: ["#wizard_plugin_corewizard_backuprestore"] }); }); diff --git a/src/octoprint/plugins/corewizard/subwizards.py b/src/octoprint/plugins/corewizard/subwizards.py index 0fee431c7..9e652af9f 100644 --- a/src/octoprint/plugins/corewizard/subwizards.py +++ b/src/octoprint/plugins/corewizard/subwizards.py @@ -146,6 +146,20 @@ class PrinterProfileSubwizard(object): return gettext("Default Printer Profile") +# noinspection PyUnresolvedReferences,PyMethodMayBeStatic +class BackupRestoreSubwizard(object): + def _is_backuprestore_wizard_firstrunonly(self): + return True + + def _is_backuprestore_wizard_required(self): + return True + + def _get_backuprestore_wizard_details(self): + return dict(required=self._is_backuprestore_wizard_required()) + + def _get_backuprestore_wizard_name(self): + return gettext("Restore Backup") + Subwizards = type(to_native_str("Subwizards"), tuple(cls for clsname, cls in inspect.getmembers(sys.modules[__name__], inspect.isclass) if clsname.endswith("Subwizard")), diff --git a/src/octoprint/plugins/corewizard/templates/corewizard_backuprestore_wizard.jinja2 b/src/octoprint/plugins/corewizard/templates/corewizard_backuprestore_wizard.jinja2 new file mode 100644 index 000000000..e2f2eb90f --- /dev/null +++ b/src/octoprint/plugins/corewizard/templates/corewizard_backuprestore_wizard.jinja2 @@ -0,0 +1,9 @@ +

{{ _('Restore from a backup') }}

+ +{% trans %}

+ If you would like to restore OctoPrint configuration from a backup now is the time. +

{% endtrans %} + + \ No newline at end of file From 7e4c29befb39e692637511bda089be8f18c53e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 1 Apr 2020 18:58:39 +0200 Subject: [PATCH 13/28] =?UTF-8?q?=E2=9C=A8=20backup:=20Add=20first=20run?= =?UTF-8?q?=20wizard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bypasses permissions in first run mode, allows to restore existing backup. Closes #3496 --- src/octoprint/plugins/backup/__init__.py | 24 +++++++++++++--- .../plugins/backup/static/js/backup.js | 14 ++++++---- .../backup/templates/backup_wizard.jinja2 | 26 +++++++++++++++++ .../corewizard/static/js/corewizard.js | 28 ------------------- .../plugins/corewizard/subwizards.py | 18 ++---------- .../corewizard_backuprestore_wizard.jinja2 | 9 ------ src/octoprint/server/util/sockjs.py | 3 +- src/octoprint/settings.py | 2 +- 8 files changed, 60 insertions(+), 64 deletions(-) create mode 100644 src/octoprint/plugins/backup/templates/backup_wizard.jinja2 delete mode 100644 src/octoprint/plugins/corewizard/templates/corewizard_backuprestore_wizard.jinja2 diff --git a/src/octoprint/plugins/backup/__init__.py b/src/octoprint/plugins/backup/__init__.py index 2d5e7dafd..a980a8eff 100644 --- a/src/octoprint/plugins/backup/__init__.py +++ b/src/octoprint/plugins/backup/__init__.py @@ -61,7 +61,8 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.AssetPlugin, octoprint.plugin.BlueprintPlugin, - octoprint.plugin.StartupPlugin): + octoprint.plugin.StartupPlugin, + octoprint.plugin.WizardPlugin): _pip_caller = None @@ -99,7 +100,8 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, ##~~ TemplatePlugin def get_template_configs(self): - return [dict(type="settings", name=gettext("Backup & Restore"))] + return [dict(type="settings", name=gettext("Backup & Restore")), + dict(type="wizard", name=gettext("Restore Backup?"))] ##~~ BlueprintPlugin @@ -210,9 +212,10 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, return NO_CONTENT @octoprint.plugin.BlueprintPlugin.route("/restore", methods=["POST"]) - @no_firstrun_access - @Permissions.PLUGIN_BACKUP_ACCESS.require(403) def perform_restore(self): + if not Permissions.PLUGIN_BACKUP_ACCESS.can() and not self._settings.global_get(["server", "firstRun"]): + return flask.abort(403) + if not is_os_compatible(["!windows"]): return flask.make_response("Invalid request, the restores are not supported on the underlying operating system", 400) @@ -325,6 +328,14 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, def is_blueprint_protected(self): return False + ##~~ WizardPlugin + + def is_wizard_required(self): + return self._settings.global_get(["server", "firstRun"]) + + def get_wizard_details(self): + return dict(required=self.is_wizard_required()) + ##~~ tornado hook def route_hook(self, *args, **kwargs): @@ -929,6 +940,9 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, os.remove(path) # restart server + if not restart_command: + restart_command = configdata.get("server", dict()).get("commands", dict()).get("serverRestartCommand") + if restart_command: import sarge @@ -949,6 +963,8 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, else: if callable(on_restore_done): on_restore_done(path) + if callable(on_log_error): + on_log_error("No restart command configured. Please restart OctoPrint manually.") return True diff --git a/src/octoprint/plugins/backup/static/js/backup.js b/src/octoprint/plugins/backup/static/js/backup.js index 2414b3a53..8bfe05e00 100644 --- a/src/octoprint/plugins/backup/static/js/backup.js +++ b/src/octoprint/plugins/backup/static/js/backup.js @@ -29,9 +29,10 @@ $(function() { self.backupInProgress = ko.observable(false); self.restoreSupported = ko.observable(true); - self.backupUploadButton = $("#settings-backup-upload"); self.backupUploadData = undefined; - self.backupUploadButton.fileupload({ + self.backupUploadName = ko.observable(); + + var backupFileuploadOptions = { dataType: "json", maxNumberOfFiles: 1, autoUpload: false, @@ -49,8 +50,11 @@ $(function() { self.backupUploadName(undefined); self.backupUploadData = undefined; } - }); - self.backupUploadName = ko.observable(); + }; + + $("#settings-backup-upload").fileupload(backupFileuploadOptions); + $("#wizard-backup-upload").fileupload(backupFileuploadOptions); + self.restoreInProgress = ko.observable(false); self.restoreTitle = ko.observable(); self.restoreDialog = undefined; @@ -284,6 +288,6 @@ $(function() { OCTOPRINT_VIEWMODELS.push({ construct: BackupViewModel, dependencies: ["loginStateViewModel", "settingsViewModel"], - elements: ["#settings_plugin_backup"] + elements: ["#settings_plugin_backup", "#wizard_plugin_backup"] }); }); diff --git a/src/octoprint/plugins/backup/templates/backup_wizard.jinja2 b/src/octoprint/plugins/backup/templates/backup_wizard.jinja2 new file mode 100644 index 000000000..17d6090cc --- /dev/null +++ b/src/octoprint/plugins/backup/templates/backup_wizard.jinja2 @@ -0,0 +1,26 @@ +

{{ _('Restore from a backup?') }}

+ +{% trans %}

+ If you would like to restore OctoPrint configuration from a backup now is the time. +

{% endtrans %} + +
+
+ +
+
+ + {{ _('Browse...') }} + + + +
+
+
+ +
+
+ +
+
+
diff --git a/src/octoprint/plugins/corewizard/static/js/corewizard.js b/src/octoprint/plugins/corewizard/static/js/corewizard.js index e7dd12797..5f3dfa7d0 100644 --- a/src/octoprint/plugins/corewizard/static/js/corewizard.js +++ b/src/octoprint/plugins/corewizard/static/js/corewizard.js @@ -313,30 +313,6 @@ $(function() { }; } - function CoreWizardBackupRestoreViewModel(parameters) { - var self = this; - - self.required = false; - - self.onWizardDetails = function(response) { - if (!self.required) return; - }; - - self.onWizardFinish = function() { - if (!self.required) return; - }; - - self.showRestoreFromBackup = function() { - $showRestorePluginDialogCallback = function () { - OctoPrint.coreui.viewmodels.wizardViewModel.closeDialog(); - $("#settings_dialog_menu").hide() - OctoPrint.coreui.viewmodels.settingsViewModel.show("settings_plugin_backup"); - } - - OctoPrint.coreui.viewmodels.coreWizardAclViewModel._sendData({"ac": false}, $showRestorePluginDialogCallback); - }; - } - OCTOPRINT_VIEWMODELS.push({ construct: CoreWizardAclViewModel, dependencies: ["loginStateViewModel"], @@ -361,9 +337,5 @@ $(function() { construct: CoreWizardPrinterProfileViewModel, dependencies: ["printerProfilesViewModel"], elements: ["#wizard_plugin_corewizard_printerprofile"] - }, { - construct: CoreWizardBackupRestoreViewModel, - dependencies: ["settingsViewModel"], - elements: ["#wizard_plugin_corewizard_backuprestore"] }); }); diff --git a/src/octoprint/plugins/corewizard/subwizards.py b/src/octoprint/plugins/corewizard/subwizards.py index 9e652af9f..7d206ea00 100644 --- a/src/octoprint/plugins/corewizard/subwizards.py +++ b/src/octoprint/plugins/corewizard/subwizards.py @@ -107,7 +107,7 @@ class OnlineCheckSubwizard(object): return dict(required=self._is_onlinecheck_wizard_required()) def _get_onlinecheck_wizard_name(self): - return gettext("Online connectivity check") + return gettext("Online Connectivity Check") def _get_onlinecheck_additional_wizard_template_data(self): return dict(mandatory=self._is_onlinecheck_wizard_required()) @@ -125,7 +125,7 @@ class PluginBlacklistSubwizard(object): return dict(required=self._is_pluginblacklist_wizard_required()) def _get_pluginblacklist_wizard_name(self): - return gettext("Plugin blacklist") + return gettext("Plugin Blacklist") def _get_pluginblacklist_additional_wizard_template_data(self): return dict(mandatory=self._is_pluginblacklist_wizard_required()) @@ -146,20 +146,6 @@ class PrinterProfileSubwizard(object): return gettext("Default Printer Profile") -# noinspection PyUnresolvedReferences,PyMethodMayBeStatic -class BackupRestoreSubwizard(object): - def _is_backuprestore_wizard_firstrunonly(self): - return True - - def _is_backuprestore_wizard_required(self): - return True - - def _get_backuprestore_wizard_details(self): - return dict(required=self._is_backuprestore_wizard_required()) - - def _get_backuprestore_wizard_name(self): - return gettext("Restore Backup") - Subwizards = type(to_native_str("Subwizards"), tuple(cls for clsname, cls in inspect.getmembers(sys.modules[__name__], inspect.isclass) if clsname.endswith("Subwizard")), diff --git a/src/octoprint/plugins/corewizard/templates/corewizard_backuprestore_wizard.jinja2 b/src/octoprint/plugins/corewizard/templates/corewizard_backuprestore_wizard.jinja2 deleted file mode 100644 index e2f2eb90f..000000000 --- a/src/octoprint/plugins/corewizard/templates/corewizard_backuprestore_wizard.jinja2 +++ /dev/null @@ -1,9 +0,0 @@ -

{{ _('Restore from a backup') }}

- -{% trans %}

- If you would like to restore OctoPrint configuration from a backup now is the time. -

{% endtrans %} - - \ No newline at end of file diff --git a/src/octoprint/server/util/sockjs.py b/src/octoprint/server/util/sockjs.py index f051f63a0..83f4d0724 100644 --- a/src/octoprint/server/util/sockjs.py +++ b/src/octoprint/server/util/sockjs.py @@ -83,6 +83,7 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, _emit_permissions = {"connected": [], "reauthRequired": [], + "plugin": lambda payload: [] if payload.get("plugin") == "backup" and settings().getBoolean(["server", "firstRun"]) else [Permissions.STATUS], "*": [Permissions.STATUS]} _unauthed_backlog_max = 100 @@ -419,7 +420,7 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, if permissions is None: permissions = self._emit_permissions.get(type, self._emit_permissions["*"]) - permissions = [x() if callable(x) else x for x in permissions] + permissions = permissions(payload) if callable(permissions) else [x for x in permissions] if not self._user or not all(map(lambda p: self._user.has_permission(p), permissions)): if not self._authed: diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 7d134dbb7..64c6f3557 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -325,7 +325,7 @@ default_settings = { "plugin_pi_support" ], "usersettings": ["access", "interface"], - "wizard": ["access"], + "wizard": ["plugin_backup", "plugin_corewizard_acl"], "about": ["about", "plugin_pi_support", "supporters", "authors", "changelog", "license", "thirdparty", "plugin_pluginmanager"], "generic": [] }, From f99ba720a814d41e963e9da60dede8b45f0245ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 1 Apr 2020 19:24:45 +0200 Subject: [PATCH 14/28] =?UTF-8?q?=E2=99=BB=20backup:=20remove=20code=20rep?= =?UTF-8?q?etition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backup/templates/backup_settings.jinja2 | 22 ++----------------- .../backup/templates/backup_wizard.jinja2 | 22 ++----------------- .../backup/backup_plugin_upload_form.jinja2 | 20 +++++++++++++++++ 3 files changed, 24 insertions(+), 40 deletions(-) create mode 100644 src/octoprint/plugins/backup/templates/snippets/plugin/backup/backup_plugin_upload_form.jinja2 diff --git a/src/octoprint/plugins/backup/templates/backup_settings.jinja2 b/src/octoprint/plugins/backup/templates/backup_settings.jinja2 index 6fcc72ca4..e19733aa5 100644 --- a/src/octoprint/plugins/backup/templates/backup_settings.jinja2 +++ b/src/octoprint/plugins/backup/templates/backup_settings.jinja2 @@ -96,26 +96,8 @@

{{ _('Restore settings & files from an uploaded backup archive.') }}

-
-
- -
-
- - {{ _('Browse...') }} - - - -
-
-
- -
-
- -
-
-
+ {% set plugin_backup_upload_form_id='settings-backup-upload' %} + {% include "snippets/plugin/backup/backup_plugin_upload_form.jinja2" %}
diff --git a/src/octoprint/plugins/backup/templates/backup_wizard.jinja2 b/src/octoprint/plugins/backup/templates/backup_wizard.jinja2 index 17d6090cc..8ba4f479c 100644 --- a/src/octoprint/plugins/backup/templates/backup_wizard.jinja2 +++ b/src/octoprint/plugins/backup/templates/backup_wizard.jinja2 @@ -4,23 +4,5 @@ If you would like to restore OctoPrint configuration from a backup now is the time.

{% endtrans %} -
-
- -
-
- - {{ _('Browse...') }} - - - -
-
-
- -
-
- -
-
-
+{% set plugin_backup_upload_form_id='wizard-backup-upload' %} +{% include "snippets/plugin/backup/backup_plugin_upload_form.jinja2" %} diff --git a/src/octoprint/plugins/backup/templates/snippets/plugin/backup/backup_plugin_upload_form.jinja2 b/src/octoprint/plugins/backup/templates/snippets/plugin/backup/backup_plugin_upload_form.jinja2 new file mode 100644 index 000000000..268a567f5 --- /dev/null +++ b/src/octoprint/plugins/backup/templates/snippets/plugin/backup/backup_plugin_upload_form.jinja2 @@ -0,0 +1,20 @@ +
+
+ +
+
+ + {{ _('Browse...') }} + + + +
+
+
+ +
+
+ +
+
+
From 2cc0e91c38a060844c27295089bf990a2f767254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 2 Apr 2020 17:53:47 +0200 Subject: [PATCH 15/28] =?UTF-8?q?=F0=9F=90=9B=20announcements:=20Fix=20wro?= =?UTF-8?q?ng=20permission=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/plugins/announcements/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/plugins/announcements/__init__.py b/src/octoprint/plugins/announcements/__init__.py index 5997acb02..44719840c 100644 --- a/src/octoprint/plugins/announcements/__init__.py +++ b/src/octoprint/plugins/announcements/__init__.py @@ -149,7 +149,7 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin, def get_template_configs(self): return [ dict(type="settings", name=gettext("Announcements"), template="announcements_settings.jinja2", custom_bindings=True), - dict(type="navbar", template="announcements_navbar.jinja2", styles=["display: none"], data_bind="visible: loginState.hasPermission(access.permissions.PLUGIN_ANNOUNCEMENTS_ANNOUNCEMENT)") + dict(type="navbar", template="announcements_navbar.jinja2", styles=["display: none"], data_bind="visible: loginState.hasPermission(access.permissions.PLUGIN_ANNOUNCEMENTS_READ)") ] # Blueprint Plugin From ee70e9d54610771834cd783cf98b0a2b95bf2113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 2 Apr 2020 18:03:53 +0200 Subject: [PATCH 16/28] =?UTF-8?q?=F0=9F=9A=B8=20Include=20Python=20version?= =?UTF-8?q?=20in=20footer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As suggested in https://community.octoprint.org/t/17819 --- src/octoprint/plugins/pi_support/static/js/pi_support.js | 8 +++----- src/octoprint/server/views.py | 3 +++ src/octoprint/templates/index.jinja2 | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/octoprint/plugins/pi_support/static/js/pi_support.js b/src/octoprint/plugins/pi_support/static/js/pi_support.js index e6b0aaef1..4f3a8a13d 100644 --- a/src/octoprint/plugins/pi_support/static/js/pi_support.js +++ b/src/octoprint/plugins/pi_support/static/js/pi_support.js @@ -29,13 +29,11 @@ $(function() { self.fromThrottleState(response.throttle_state); // OctoPi version - $("#octopi_support_footer").remove(); + $("#pi_support_footer").remove(); if (!response.octopi_version) return; - var octoPrintVersion = $(".footer span.version"); - var octoPiVersion = $(" " + gettext("running on") + " " + gettext("OctoPi") - + " " + response.octopi_version + ""); - $(octoPiVersion).insertAfter(octoPrintVersion); + var octoPiVersion = $(""); + $("#footer_version").append(octoPiVersion); }) }; diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 60aa35401..aed9eaa5e 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -23,6 +23,7 @@ from octoprint.access.permissions import Permissions from octoprint.settings import settings from octoprint.filemanager import full_extension_tree, get_all_extensions from octoprint.util import to_unicode, to_bytes, sv +from octoprint.util.version import get_python_version_string import re import base64 @@ -317,6 +318,7 @@ def index(): def hash_update(value): hash.update(to_bytes(value, encoding="utf-8", errors="replace")) hash_update(octoprint.__version__) + hash_update(get_python_version_string()) hash_update(",".join(sorted(files))) if lastmodified: hash_update(lastmodified) @@ -476,6 +478,7 @@ def _get_render_kwargs(templates, plugin_names, plugin_vars, now): debug=debug, firstRun=first_run, version=dict(number=VERSION, display=DISPLAY_VERSION, branch=BRANCH), + python_version=get_python_version_string(), templates=templates, pluginNames=plugin_names, locales=locales, diff --git a/src/octoprint/templates/index.jinja2 b/src/octoprint/templates/index.jinja2 index 41e216b70..ffb36d8b5 100644 --- a/src/octoprint/templates/index.jinja2 +++ b/src/octoprint/templates/index.jinja2 @@ -153,6 +153,7 @@ From 8ee6b9fdf1109ee113e1ba1ddc671ea8831f6208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 3 Apr 2020 18:24:54 +0200 Subject: [PATCH 20/28] =?UTF-8?q?=E2=9C=A8=20Add=20setting=20to=20disable?= =?UTF-8?q?=20SD=20print=20detection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some firmware variants (Ultimaker 2/2+, maybe others) send a file selected message while just scrolling through the SD file list on the integrated controller unit. M27 polling right after file selection might cause issues for them. This patch allows to work around that. Closes #3479 See also #1407 --- src/octoprint/server/api/settings.py | 2 ++ src/octoprint/settings.py | 1 + src/octoprint/static/js/app/viewmodels/settings.js | 1 + .../templates/dialogs/settings/serialconnection.jinja2 | 7 +++++++ src/octoprint/util/comm.py | 3 ++- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 848c680ad..31864cdb1 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -187,6 +187,7 @@ def getSettings(): "blockWhileDwelling": s.getBoolean(["serial", "blockWhileDwelling"]), "useParityWorkaround": s.get(["serial", "useParityWorkaround"]), "sendM112OnError": s.getBoolean(["serial", "sendM112OnError"]), + "disableSdPrintingDetection": s.getBoolean(["serial", "disableSdPrintingDetection"]), "ackMax": s.getInt(["serial", "ackMax"]), "maxTimeoutsIdle": s.getInt(["serial", "maxCommunicationTimeouts", "idle"]), "maxTimeoutsPrinting": s.getInt(["serial", "maxCommunicationTimeouts", "printing"]), @@ -484,6 +485,7 @@ def _saveSettings(data): if value in ("always", "detect", "never"): s.set(["serial", "useParityWorkaround"], value) if "sendM112OnError" in data["serial"]: s.setBoolean(["serial", "sendM112OnError"], data["serial"]["sendM112OnError"]) + if "disableSdPrintingDetection" in data["serial"]: s.setBoolean(["serial", "disableSdPrintingDetection"], data["serial"]["disableSdPrintingDetection"]) if "ackMax" in data["serial"]: s.setInt(["serial", "ackMax"], data["serial"]["ackMax"]) if "logPositionOnPause" in data["serial"]: s.setBoolean(["serial", "logPositionOnPause"], data["serial"]["logPositionOnPause"]) if "logPositionOnCancel" in data["serial"]: s.setBoolean(["serial", "logPositionOnCancel"], data["serial"]["logPositionOnCancel"]) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 64c6f3557..f784c4a4e 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -153,6 +153,7 @@ default_settings = { "useParityWorkaround": "detect", "maxConsecutiveResends": 10, "sendM112OnError": True, + "disableSdPrintingDetection": False, "ackMax": 1, "capabilities": { diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 597b3af02..499fdf96b 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -207,6 +207,7 @@ $(function() { self.serial_capBusyProtocol = ko.observable(undefined); self.serial_capEmergencyParser = ko.observable(undefined); self.serial_sendM112OnError = ko.observable(undefined); + self.serial_disableSdPrintingDetection = ko.observable(undefined); self.serial_ackMax = ko.observable(undefined); self.folder_uploads = ko.observable(undefined); diff --git a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 index 03c8af4b6..978fe2074 100644 --- a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 +++ b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 @@ -244,6 +244,13 @@
+
+
+ +
+