Merge branch 'maintenance' into devel

This commit is contained in:
GitHub Nightly Merge Action committed 2022-02-17 00:07:51 +00:00
commit 2598625805
9 files changed
+140 -45

No files matched your search

+1 -1
View File
@@ -139,7 +139,7 @@ class Events:
return name, event
# based on https://stackoverflow.com/a/1176023
_first_cap_re = re.compile("(.)([A-Z][a-z]+)")
_first_cap_re = re.compile("([^_])([A-Z][a-z]+)")
_all_cap_re = re.compile("([a-z0-9])([A-Z])")
@classmethod
+4
View File
@@ -215,6 +215,10 @@ def getSettings():
"waitForStart": s.getBoolean(["serial", "waitForStartOnConnect"]),
"alwaysSendChecksum": s.getBoolean(["serial", "alwaysSendChecksum"]),
"neverSendChecksum": s.getBoolean(["serial", "neverSendChecksum"]),
"sendChecksumWithUnknownCommands": s.getBoolean(
["serial", "sendChecksumWithUnknownCommands"]
),
"unknownCommandsNeedAck": s.getBoolean(["serial", "unknownCommandsNeedAck"]),
"sdRelativePath": s.getBoolean(["serial", "sdRelativePath"]),
"sdAlwaysAvailable": s.getBoolean(["serial", "sdAlwaysAvailable"]),
"sdLowerCase": s.getBoolean(["serial", "sdLowerCase"]),
+41 -41
View File
@@ -415,7 +415,7 @@ default_settings = {
"remoteUserHeader": "REMOTE_USER",
"addRemoteUsers": False,
},
"slicing": {"enabled": True, "defaultSlicer": None, "defaultProfiles": None},
"slicing": {"enabled": True, "defaultSlicer": None, "defaultProfiles": {}},
"events": {"enabled": True, "subscriptions": []},
"api": {"allowCrossOrigin": False, "apps": {}},
"terminalFilters": [
@@ -554,35 +554,9 @@ class HierarchicalChainMap:
"""
@staticmethod
def _unflatten(kv_pairs, prefix=""):
"""
:type kv_pairs: Iterable[Tuple[str, any]]
"""
result = dict()
for key, value in kv_pairs:
if not key.startswith(prefix):
continue
subkeys = key[len(prefix) :].split(_CHAINMAP_SEP)
current = result
for subkey in subkeys[:-1]:
if subkey not in current:
current[subkey] = {}
current = current[subkey]
current[subkeys[-1]] = value
def _flatten(d: dict, parent_key: str = "") -> dict:
"""Flattens a hierarchical dictionary."""
return result
def __init__(self, *maps):
self._chainmap = ChainMap(*map(self._flatten, maps))
@staticmethod
def from_layers(*layers):
result = HierarchicalChainMap()
result._chainmap.maps = layers
return result
@staticmethod
def _flatten(d, parent_key=""):
if d is None:
return {}
@@ -595,8 +569,26 @@ class HierarchicalChainMap:
items.append((new_key, v))
return dict(items)
def deep_dict(self):
return self._unflatten(self._chainmap.items())
@staticmethod
def _unflatten(d: dict, prefix: str = "") -> dict:
"""Unflattens a flattened dictionary."""
if d is None:
return {}
result = dict()
for key, value in d.items():
if not key.startswith(prefix):
continue
subkeys = key[len(prefix) :].split(_CHAINMAP_SEP)
current = result
for subkey in subkeys[:-1]:
if subkey not in current or current[subkey] is None:
current[subkey] = {}
current = current[subkey]
current[subkeys[-1]] = value
return result
@staticmethod
def _path_to_key(path):
@@ -605,6 +597,18 @@ class HierarchicalChainMap:
"""
return _CHAINMAP_SEP.join(path)
@staticmethod
def from_layers(*layers):
result = HierarchicalChainMap()
result._chainmap.maps = layers
return result
def __init__(self, *maps):
self._chainmap = ChainMap(*map(self._flatten, maps))
def deep_dict(self):
return self._unflatten(self._chainmap)
def has_path(self, path, only_local=False, only_defaults=False):
if only_defaults:
current = self._chainmap.parents
@@ -630,19 +634,15 @@ class HierarchicalChainMap:
# the first level where we find the value.
if not merged and not only_local:
for layer in current.maps:
for k in layer:
if k.startswith(key):
current = layer
break
else:
continue
break
if key in layer:
current = layer
break
if key not in current:
# we might be trying to grab a dict, look for children
key = key + _CHAINMAP_SEP
result = self._unflatten(
((k, v) for k, v in current.items() if k.startswith(key)), prefix=key
{k: v for k, v in current.items() if k.startswith(key)}, prefix=key
)
if not result:
raise KeyError("Could not find entry for " + str(path))
@@ -728,7 +728,7 @@ class HierarchicalChainMap:
@property
def top_map(self):
"""This is the layer that is written to"""
return self._unflatten(self._chainmap.maps[0].items())
return self._unflatten(self._chainmap.maps[0])
@top_map.setter
def top_map(self, value):
@@ -1861,7 +1861,7 @@ class Settings:
for key in keys:
try:
value = chain.get_by_path(
parent_path + [key], only_local=not incl_defaults
parent_path + [key], only_local=not incl_defaults, merged=merged
)
except KeyError:
raise NoSuchSettingsPath()
@@ -48,7 +48,7 @@ $(function () {
self.enablePrint = ko.pureComputed(function () {
return (
self.isOperational() &&
self.isReady() &&
(self.isReady() || self.isPaused()) &&
!self.isPrinting() &&
!self.isCancelling() &&
!self.isPausing() &&
@@ -219,6 +219,8 @@ $(function () {
self.serial_triggerOkForM29 = ko.observable(undefined);
self.serial_waitForStart = ko.observable(undefined);
self.serial_sendChecksum = ko.observable("print");
self.serial_sendChecksumWithUnknownCommands = ko.observable(undefined);
self.serial_unknownCommandsNeedAck = ko.observable(undefined);
self.serial_sdRelativePath = ko.observable(undefined);
self.serial_sdLowerCase = ko.observable(undefined);
self.serial_sdAlwaysAvailable = ko.observable(undefined);
@@ -343,7 +343,23 @@
</label>
</div>
</div>
</div>
<div class="control-group" title="{{ _('Send line numbers & checksums for non-GCODE commands')|edq }}">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_sendChecksumWithUnknownCommands" id="settings-sendChecksumWithUnknownCommands"> {{ _('Send line numbers & checksums for non-GCODE commands') }} <span class="label">{{ _('Prusa Firmware') }}</span>
<span class="help-block">{{ _('Check this if your printer supports commands outside of the GCODE format (e.g. <code>Tx</code> or similar) but requires them to be treated identical to GCODE.') }}</span>
</label>
</div>
</div>
<div class="control-group" title="{{ _('Wait for \'ok\' for non-GCODE commands')|edq }}">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_unknownCommandsNeedAck" id="settings-unknownCommandsNeedAck"> {{ _('Wait for acknowledging <code>ok</code> for non-GCODE commands') }} <span class="label">{{ _('Prusa Firmware') }}</span>
<span class="help-block">{{ _('Check this if your printer supports commands outside of the GCODE format (e.g. <code>Tx</code> or similar) but requires them to be treated identical to GCODE.') }}</span>
</label>
</div>
</div>
</div>
<div>
<div><small><a href="#" class="muted" data-bind="toggleContent: { class: 'fa-caret-right fa-caret-down', container: '#settings_serial_protocol_firmware .hide' }"><i class="fas fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
<div class="hide">
@@ -457,7 +473,8 @@
<label class="control-label" for="settings-serialEmergencyCommands">{{ _('Emergency commands') }}</label>
<div class="controls">
<input type="text" class="input-block-level" id="settings-serialEmergencyCommands" data-bind="value: serial_emergencyCommands">
<span class="help-inline">{{ _('Use this to specify emergency commands which should jump any queues and - if supported by the firmware - be force sent. Just the G or M code, comma separated. Defaults to <code>M112</code>, <code>M108</code> and <code>M410</code>.') }}</span> </div>
<span class="help-inline">{{ _('Use this to specify emergency commands which should jump any queues and - if supported by the firmware - be force sent. Just the G or M code, comma separated. Defaults to <code>M112</code>, <code>M108</code> and <code>M410</code>.') }}</span>
</div>
</div>
<div>
<div><small><a href="#" class="muted" data-bind="toggleContent: { class: 'fa-caret-right fa-caret-down', container: '#settings_serial_protocol_finetuning .hide' }"><i class="fas fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
+2
View File
@@ -2816,6 +2816,8 @@ class MachineCom:
)
self._sdLowerCase = True
self._sendChecksumWithUnknownCommands = True
self._unknownCommandsNeedAck = True
self._firmware_info_received = True
self._firmware_info = data
+22
View File
@@ -0,0 +1,22 @@
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
__copyright__ = "Copyright (C) 2022 The OctoPrint Project - Released under terms of the AGPLv3 License"
import unittest
import ddt
import octoprint.events
@ddt.ddt
class TestEvents(unittest.TestCase):
@ddt.data(
("plugin_example_event", "PLUGIN_EXAMPLE_EVENT"),
("plugin_Example_event", "PLUGIN_EXAMPLE_EVENT"),
("plugin_ExAmple_Event", "PLUGIN_EX_AMPLE_EVENT"),
("plugin_exAmple_EvEnt", "PLUGIN_EX_AMPLE_EV_ENT"),
)
@ddt.unpack
def test_to_identifier(self, value, expected):
actual = octoprint.events.Events._to_identifier(value)
self.assertEqual(actual, expected)
+48
View File
@@ -29,3 +29,51 @@ class TestHelpers(unittest.TestCase):
@ddt.unpack
def test_valid_boolean_trues(self, value, expected):
self.assertEqual(expected, value in octoprint.settings.valid_boolean_trues)
def _key(*path):
return octoprint.settings._CHAINMAP_SEP.join(path)
@ddt.ddt
class ChainmapTest(unittest.TestCase):
@ddt.data(
(
{"a": 1},
{_key("a"): 1},
),
({"a": {"b": "b"}}, {_key("a", "b"): "b"}),
(
{"a": {"b": "b", "c": "c", "d": {"e": "e"}}},
{_key("a", "b"): "b", _key("a", "c"): "c", _key("a", "d", "e"): "e"},
),
)
@ddt.unpack
def test_flatten(self, value, expected):
self.assertEqual(
expected, octoprint.settings.HierarchicalChainMap._flatten(value)
)
@ddt.data(
(
{_key("a"): 1},
{"a": 1},
),
(
{_key("a", "b"): "b"},
{"a": {"b": "b"}},
),
(
{_key("a", "b"): "b", _key("a", "c"): "c", _key("a", "d", "e"): "e"},
{"a": {"b": "b", "c": "c", "d": {"e": "e"}}},
),
(
{_key("a"): None, _key("a", "b"): "b"},
{"a": {"b": "b"}},
),
)
@ddt.unpack
def test_unflatten(self, value, expected):
self.assertEqual(
expected, octoprint.settings.HierarchicalChainMap._unflatten(value)
)