♻ Extract printer safety warning into dependency
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.
This commit is contained in:
1 parent
8a01d89049
commit
761a0fdb61
15 files changed
+31
-688
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
@@ -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()
|
||||
@@ -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
|
||||
@@ -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;
|
||||
});
|
||||
@@ -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}
|
||||
@@ -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"]
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
<!-- ko foreach: warnings -->
|
||||
<p><strong data-bind="text: $root.warningText($data)"></strong></p>
|
||||
<p class="printer_safety_warning" data-bind="class: $root.cssClass($data)">
|
||||
<span data-bind="text: message"></span><br>
|
||||
<a target="_blank" rel="noreferrer noopener" data-bind="attr: {href: url}">{{ _('Learn more...') }}</a>
|
||||
</p>
|
||||
<!-- /ko -->
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user