It looks like you are tracking an OctoPrint RC release channel. It " + + "would be great if you would enable error reporting so that any kind of errors that occur " + + "with an RC can be looked into more easily. Thank you!
" + + "You can find more information on error reporting " + + "under Settings > Error Tracking
"), + hide: false, + confirm: { + confirm: true, + buttons: [{ + text: gettext("Ignore"), + click: function() { + notification.remove(); + notification = undefined; + new PNotify({ + text: gettext("You can still enable error tracking via \"Settings\" > \"Error Tracking\"") + }); + + if (Modernizr.localstorage) { + localStorage["plugin.errortracking.notification_ignored"] = JSON.stringify(true); + } + } + }, { + text: gettext("Enable"), + addClass: "btn-primary", + click: function() { + self.settings.saveData({ + plugins: { + errortracking: { + enabled: true + } + } + }).done(function() { + notification.remove(); + notification = undefined; + location.reload(true); + }); + } + }] + }, + buttons: { + closer: false, + sticker: false + } + }); + + // not an RC release channel, close notification + } else if (notification !== undefined) { + notification.remove(); + notification = undefined; + } + }; + + var subbed = false; + self.onStartup = self.onUserLoggedIn = self.onUserLoggedOut = function() { + performCheck(); + if (self.settings && self.settings.settings && self.settings.settings.plugins && self.settings.settings.plugins.softwareupdate && !subbed) { + subbed = true; + self.settings.settings.plugins.softwareupdate.octoprint_release_channel.subscribe(performCheck); + } + }; + } + + OCTOPRINT_VIEWMODELS.push({ + construct: ErrorTrackingViewModel, + dependencies: ["settingsViewModel", "loginStateViewModel"] + }); +}); diff --git a/src/octoprint/plugins/errortracking/static/js/sentry.min.js b/src/octoprint/plugins/errortracking/static/js/sentry.min.js new file mode 100644 index 000000000..e4979d05a --- /dev/null +++ b/src/octoprint/plugins/errortracking/static/js/sentry.min.js @@ -0,0 +1,3 @@ +/*! @sentry/browser 4.5.1 (6a390acf) | https://github.com/getsentry/sentry-javascript */ +var Sentry=function(t){"use strict";var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,n)};function n(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r,o,i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n+ Error tracking will cause any logged exceptions in the server and the browser interface to be sent + to OctoPrint's Sentry instance. +
++ By enabling it you help to gather detailed information on the cause of bugs or other issues. This is especially valuable + on release candidates, which is why this plugin will also prompt you to enable error tracking if it detects that + you are subscribed to an RC release channel. +
++ Please enable this if you are running a release candidate, or are prompted to do so while debugging an issue that you reported. +
+{% endtrans %} + + + +{% trans %} ++ The Error Tracking plugin is using a Sentry instance kindly provided by + sentry.io. For information on their service + please refer to their Security & Compliance documentation + and their Privacy Policy. +
+{% endtrans %} diff --git a/src/octoprint/plugins/printer_safety_check/__init__.py b/src/octoprint/plugins/printer_safety_check/__init__.py index 713a444b9..36ee30df7 100644 --- a/src/octoprint/plugins/printer_safety_check/__init__.py +++ b/src/octoprint/plugins/printer_safety_check/__init__.py @@ -9,7 +9,8 @@ import octoprint.plugin from octoprint.events import Events from octoprint.access import USER_GROUP from octoprint.access.permissions import Permissions -from octoprint.util.version import get_comparable_version + +from .checks.firmware_unsafe import FirmwareUnsafeChecks import flask from flask_babel import gettext @@ -25,58 +26,10 @@ Learn more at https://faq.octoprint.org/warning-{warning_type} """ -# Anet A8 -ANETA8_M115_TEST = ("aneta8", lambda name, data: name and name.lower().startswith("anet_a8_")) - -# Anycubic MEGA -ANYCUBIC_AUTHOR1 = "| Author: (Jolly, xxxxxxxx.CO.)".lower() -ANYCUBIC_AUTHOR2 = "| Author: (**Jolly, xxxxxxxx.CO.**)".lower() -ANYCUBIC_RECEIVED_TEST = ("anycubic", lambda line: line and (ANYCUBIC_AUTHOR1 in line.lower() or ANYCUBIC_AUTHOR2 in line.lower())) - -# Creality CR-10s -CR10S_AUTHOR = " | Author: (CR-10Slanguage)".lower() -CR10S_RECEIVED_TEST = ("cr10s", lambda line: line and CR10S_AUTHOR in line.lower()) - -# Creality Ender 3 -ENDER3_AUTHOR = " | Author: (Ender3)".lower() -ENDER3_RECEIVED_TEST = ("ender3", lambda line: line and ENDER3_AUTHOR in line.lower()) - -# iMe on Micro3D -IME_M115_TEST = ("ime", lambda name, data: name and name.lower().startswith("ime")) - -# Malyan M200 aka Monoprice Select Mini, versions less than 4.0 -MALYANM200_M115_TEST = ("malyan_m200", lambda name, data: name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < get_comparable_version("4.0")) - -# Stock Micro3D -MICRO3D_M115_TEST = ("micro3d", lambda name, data: name and name.lower().startswith("micro3d")) - -# Any Repetier versions < 0.92 -REPETIER_BEFORE_092_M115_TEST = ("repetier_before_092", lambda name, data: name and name.lower().startswith("repetier") and extract_repetier_version(name) is not None and extract_repetier_version(name) < get_comparable_version("0.92")) - -# THERMAL_PROTECTION capability reported as disabled -THERMAL_PROTECTION_CAP_TEST = ("capability", lambda cap, enabled: cap == "THERMAL_PROTECTION" and not enabled) - SAFETY_CHECKS = { - "firmware-unsafe": dict(m115=(ANETA8_M115_TEST, IME_M115_TEST, MALYANM200_M115_TEST, MICRO3D_M115_TEST, - REPETIER_BEFORE_092_M115_TEST), - received=(ANYCUBIC_RECEIVED_TEST, CR10S_RECEIVED_TEST, ENDER3_RECEIVED_TEST), - cap=(THERMAL_PROTECTION_CAP_TEST,), - message=gettext("Your printer's firmware is known to lack mandatory safety features (e.g. " - "thermal runaway protection). This is a fire risk.")) + "firmware-unsafe": FirmwareUnsafeChecks.as_dict() } -def extract_repetier_version(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 PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, octoprint.plugin.EventHandlerPlugin, octoprint.plugin.SimpleApiPlugin, @@ -111,6 +64,8 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, def on_event(self, event, payload): if event == Events.DISCONNECTED: self._reset_warnings() + self._reset_state() + self._reset_checks() ##~~ SimpleApiPlugin API @@ -154,20 +109,35 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, changes = False for warning_type, check_data in SAFETY_CHECKS.items(): - checks = check_data.get(check_type) + checks = check_data.get("checks") message = check_data.get("message") if not checks or not message: continue - for check_name, check in checks: - if check(*args, **kwargs): + 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: + self._logger.exception("There was an error running method {} on check {!r}".format(check_type, check)) + continue + + # check if now triggered + if check.triggered: self._register_warning(warning_type, message) # noinspection PyUnresolvedReferences - self._event_bus.fire(Events.PLUGIN_PRINTER_SAFETY_CHECK_WARNING, dict(check_type=check_type, - check_name=check_name, + self._event_bus.fire(Events.PLUGIN_PRINTER_SAFETY_CHECK_WARNING, dict(check_name=check.name, warning_type=warning_type)) - changes = True break @@ -183,6 +153,18 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, 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") diff --git a/src/octoprint/plugins/printer_safety_check/checks/__init__.py b/src/octoprint/plugins/printer_safety_check/checks/__init__.py new file mode 100644 index 000000000..fbc4a22e4 --- /dev/null +++ b/src/octoprint/plugins/printer_safety_check/checks/__init__.py @@ -0,0 +1,55 @@ +# -*- 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 + + 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 + diff --git a/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py b/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py new file mode 100644 index 000000000..f0b0d24c3 --- /dev/null +++ b/src/octoprint/plugins/printer_safety_check/checks/firmware_unsafe.py @@ -0,0 +1,180 @@ +# -*- 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 + +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.")) + +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/server/views.py b/src/octoprint/server/views.py index 63142b445..1942d638b 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -197,7 +197,7 @@ def index(): default_additional_etag = [enable_accesscontrol, enable_gcodeviewer, - enable_timelapse] + enable_timelapse] + sorted(["{}:{}".format(k, v) for k, v in _plugin_vars.items()]) def get_preemptively_cached_view(key, view, data=None, additional_request_data=None, additional_unless=None): if (data is None and additional_request_data is None) or g.locale is None: diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 4e4e987d0..d25fccb99 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -309,7 +309,8 @@ default_settings = { "section_printer", "serial", "printerprofiles", "temperatures", "terminalfilters", "gcodescripts", "section_features", "features", "webcam", "accesscontrol", "gcodevisualizer", "api", "plugin_appkeys", "section_octoprint", "server", "folders", "appearance", "plugin_logging", "plugin_pluginmanager", - "plugin_softwareupdate", "plugin_announcements", "plugin_backup", "plugin_tracking", "plugin_pi_support" + "plugin_softwareupdate", "plugin_announcements", "plugin_backup", "plugin_tracking", "plugin_errortracking", + "plugin_pi_support" ], "usersettings": ["access", "interface"], "wizard": ["access"], diff --git a/src/octoprint/static/js/app/viewmodels/gcode.js b/src/octoprint/static/js/app/viewmodels/gcode.js index d1914e6e2..9fe303427 100644 --- a/src/octoprint/static/js/app/viewmodels/gcode.js +++ b/src/octoprint/static/js/app/viewmodels/gcode.js @@ -569,7 +569,9 @@ $(function() { output.push(gettext("Filament") + ": " + layer.filament[0].toFixed(2) + "mm"); } else { for (var i = 0; i < layer.filament.length; i++) { - output.push(gettext("Filament") + " (" + gettext("Tool") + " " + i + "): " + layer.filament[i].toFixed(2) + "mm"); + if (layer.filament[i] !== undefined) { + output.push(gettext("Filament") + " (" + gettext("Tool") + " " + i + "): " + layer.filament[i].toFixed(2) + "mm"); + } } } } diff --git a/src/octoprint/static/js/app/viewmodels/printerstate.js b/src/octoprint/static/js/app/viewmodels/printerstate.js index 92a0bd49f..9723434e1 100644 --- a/src/octoprint/static/js/app/viewmodels/printerstate.js +++ b/src/octoprint/static/js/app/viewmodels/printerstate.js @@ -71,12 +71,18 @@ $(function() { self.titlePrintButton = ko.observable(self.TITLE_PRINT_BUTTON_UNPAUSED); self.titlePauseButton = ko.observable(self.TITLE_PAUSE_BUTTON_UNPAUSED); - self.estimatedPrintTimeString = ko.pureComputed(function() { + var estimatedPrintTimeStringHlpr = function (fmt) { if (self.lastPrintTime()) - return self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime(self.lastPrintTime()) : formatDuration(self.lastPrintTime()); + return fmt(self.lastPrintTime()); if (self.estimatedPrintTime()) - return self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime(self.estimatedPrintTime()) : formatDuration(self.estimatedPrintTime()); + return fmt(self.estimatedPrintTime()); return "-"; + } + self.estimatedPrintTimeString = ko.pureComputed(function() { + return estimatedPrintTimeStringHlpr(self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime : formatDuration); + }); + self.estimatedPrintTimeExactString = ko.pureComputed(function() { + return estimatedPrintTimeStringHlpr(formatDuration); }); self.byteString = ko.pureComputed(function() { if (!self.filesize()) @@ -94,7 +100,7 @@ $(function() { return "-"; return formatDuration(self.printTime()); }); - self.printTimeLeftString = ko.pureComputed(function() { + var printTimeLeftStringHlpr = function (fmt) { if (self.printTimeLeft() === undefined) { if (!self.printTime() || !(self.isPrinting() || self.isPaused())) { return "-"; @@ -102,8 +108,14 @@ $(function() { return gettext("Still stabilizing..."); } } else { - return self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime(self.printTimeLeft()) : formatDuration(self.printTimeLeft()); + return fmt(self.printTimeLeft()); } + } + self.printTimeLeftString = ko.pureComputed(function() { + return printTimeLeftStringHlpr(self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime : formatDuration); + }); + self.printTimeLeftExactString = ko.pureComputed(function() { + return printTimeLeftStringHlpr(formatDuration); }); self.printTimeLeftOriginString = ko.pureComputed(function() { var value = self.printTimeLeftOrigin(); diff --git a/src/octoprint/templates/sidebar/state.jinja2 b/src/octoprint/templates/sidebar/state.jinja2 index b9ffb6365..499c95c63 100644 --- a/src/octoprint/templates/sidebar/state.jinja2 +++ b/src/octoprint/templates/sidebar/state.jinja2 @@ -10,10 +10,10 @@