From 3985d10e043390c80c53d0b5a0d3942fbdf8e41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 15 Jul 2021 17:01:06 +0200 Subject: [PATCH 01/29] =?UTF-8?q?=F0=9F=91=B7=20Add=20ignore=20label=20to?= =?UTF-8?q?=20PR=20validation=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/pr-validation.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/pr-validation.yml b/.github/pr-validation.yml index b6644f25c..b44ba7855 100644 --- a/.github/pr-validation.yml +++ b/.github/pr-validation.yml @@ -1,5 +1,6 @@ approve_label: "approved" problem_label: "needs some work" +ignore_label: "skip validation" allowed_targets: ["maintenance", "devel", "staging/maintenance", "staging/devel"] forbidden_sources: From e004a24bf03d917a0b317aa2b5474ae6e99976c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 15 Jul 2021 17:31:50 +0200 Subject: [PATCH 02/29] =?UTF-8?q?=F0=9F=91=B7=20Switch=20to=20PR=20target?= =?UTF-8?q?=20deny=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/pr-validation.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/pr-validation.yml b/.github/pr-validation.yml index b44ba7855..20c988189 100644 --- a/.github/pr-validation.yml +++ b/.github/pr-validation.yml @@ -2,14 +2,14 @@ approve_label: "approved" problem_label: "needs some work" ignore_label: "skip validation" -allowed_targets: ["maintenance", "devel", "staging/maintenance", "staging/devel"] +forbidden_targets: ["master"] forbidden_sources: ["master", "maintenance", "devel", "staging/maintenance", "staging/devel"] labels: docs: - additional_allowed_targets: ["master"] + forbidden_targets: [] meta: - additional_allowed_targets: ["master"] + forbidden_targets: [] ci/cd: - additional_allowed_targets: ["master"] + forbidden_targets: [] From 5700695ef31349d677237fc1a61dd1017fafaefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 15 Jul 2021 17:43:32 +0200 Subject: [PATCH 03/29] =?UTF-8?q?=F0=9F=91=B7=20Back=20to=20allowed=5Ftarg?= =?UTF-8?q?ets,=20but=20nerf=20bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/pr-validation.yml | 8 ++++---- .github/workflows/pr_automation.yml | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/pr-validation.yml b/.github/pr-validation.yml index 20c988189..b44ba7855 100644 --- a/.github/pr-validation.yml +++ b/.github/pr-validation.yml @@ -2,14 +2,14 @@ approve_label: "approved" problem_label: "needs some work" ignore_label: "skip validation" -forbidden_targets: ["master"] +allowed_targets: ["maintenance", "devel", "staging/maintenance", "staging/devel"] forbidden_sources: ["master", "maintenance", "devel", "staging/maintenance", "staging/devel"] labels: docs: - forbidden_targets: [] + additional_allowed_targets: ["master"] meta: - forbidden_targets: [] + additional_allowed_targets: ["master"] ci/cd: - forbidden_targets: [] + additional_allowed_targets: ["master"] diff --git a/.github/workflows/pr_automation.yml b/.github/workflows/pr_automation.yml index 659733438..d0e04b09b 100644 --- a/.github/workflows/pr_automation.yml +++ b/.github/workflows/pr_automation.yml @@ -1,7 +1,8 @@ name: "Pull Request Automation" on: pull_request_target: - types: ["opened", "synchronize", "reopened", "edited", "labeled", "unlabeled"] + #types: ["opened", "synchronize", "reopened", "edited", "labeled", "unlabeled"] + types: ["opened"] jobs: pr-automation: From 07040b103fdb1622feb212e74d357e5fa60679b9 Mon Sep 17 00:00:00 2001 From: Ian Wilt Date: Sun, 18 Jul 2021 14:51:28 -0400 Subject: [PATCH 04/29] Added event FilamentChange --- AUTHORS.md | 1 + docs/events/index.rst | 4 ++++ src/octoprint/events.py | 1 + src/octoprint/util/comm.py | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 25fca2f57..5d111ebae 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -146,6 +146,7 @@ date of first contribution): * ["sparxooo"](https://github.com/sparxooo) * ["Stevil Knevil"](https://github.com/StevilKnevil) * [ldursw](https://github.com/ldursw) + * [Ian Wilt](https://github.com/ianwiltdotcom) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/docs/events/index.rst b/docs/events/index.rst index 71a55d68e..87208e6fb 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -607,6 +607,10 @@ Eject EStop An ``M112`` was sent to the printer through OctoPrint (not triggered when printing from SD!) +FilamentChange + An ''M600'', ''M701'' or ''M702'' was sent to the printer through OctoPrint (not triggered when printing from SD!) + + PositionUpdate The response to an ``M114`` was received by OctoPrint. The payload contains the current position information parsed from the response and (in the case of the selected tool ``t`` and the current feedrate ``f``) tracked diff --git a/src/octoprint/events.py b/src/octoprint/events.py index eb2e0878e..c29e22f50 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -106,6 +106,7 @@ class Events(object): REGISTERED_MESSAGE_RECEIVED = "RegisteredMessageReceived" COMMAND_SUPPRESSED = "CommandSuppressed" INVALID_TOOL_REPORTED = "InvalidToolReported" + FILAMENT_CHANGE = "FilamentChange" # Timelapse CAPTURE_START = "CaptureStart" diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 963ebd997..7f69652a0 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -301,6 +301,10 @@ gcodeToEvent = { # motors on/off "M80": Events.POWER_ON, "M81": Events.POWER_OFF, + # filament change + "M600": Events.FILAMENT_CHANGE, + "M701": Events.FILAMENT_CHANGE, + "M702": Events.FILAMENT_CHANGE, } From f7e53a4a50081b7879252cc4a5e65f6c29dab717 Mon Sep 17 00:00:00 2001 From: Ian Wilt Date: Sun, 18 Jul 2021 15:15:40 -0400 Subject: [PATCH 05/29] Shouldn't have been apostrophes oops --- docs/events/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/events/index.rst b/docs/events/index.rst index 87208e6fb..085939118 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -608,7 +608,7 @@ EStop An ``M112`` was sent to the printer through OctoPrint (not triggered when printing from SD!) FilamentChange - An ''M600'', ''M701'' or ''M702'' was sent to the printer through OctoPrint (not triggered when printing from SD!) + An ``M600``, ``M701`` or ``M702`` was sent to the printer through OctoPrint (not triggered when printing from SD!) PositionUpdate From 037519eebd5a4011a65fee21f939cfe45fb7d499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 20 Jul 2021 11:21:54 +0200 Subject: [PATCH 06/29] =?UTF-8?q?=F0=9F=93=9D=20Add=20version=20added=20to?= =?UTF-8?q?=20new=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/events/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/events/index.rst b/docs/events/index.rst index 085939118..a9b030095 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -610,6 +610,7 @@ EStop FilamentChange An ``M600``, ``M701`` or ``M702`` was sent to the printer through OctoPrint (not triggered when printing from SD!) + .. versionadded:: 1.7.0 PositionUpdate The response to an ``M114`` was received by OctoPrint. The payload contains the current position information From 323d7ecb0d5726e28713f6676037187c9f25b46e Mon Sep 17 00:00:00 2001 From: Ben Sycha Date: Fri, 25 Jun 2021 12:40:55 +0100 Subject: [PATCH 07/29] =?UTF-8?q?=F0=9F=93=9D=20add=20instructions=20for?= =?UTF-8?q?=20setting=20up=20vscode=20IDE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AUTHORS.md | 1 + docs/development/environment.rst | 98 ++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 7aecc1391..34651f849 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -141,6 +141,7 @@ date of first contribution): * [Joe Martella](https://github.com/martellaj) * [Scott Lahteine](https://github.com/thinkyhead) * [Karthikeyan Singaravelan](https://github.com/tirkarthi) + * [Ben Sycha](https://github.com/Sycha) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/docs/development/environment.rst b/docs/development/environment.rst index 851bb5aec..7da2b4c72 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -387,3 +387,101 @@ Otherwise go through Settings. Make sure you are running a PyCharm version of 2016.1 or later, or manually fix `a debugger bug contained in earlier versions `_ or plugin management will not work in your developer install when running OctoPrint from PyCharm in debug mode. + +Visual Studio Code (vscode) +--------------------------- + - Install Visual Studio from https://code.visualstudio.com/Download + - Open folder select OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) + settings.json + + - Create a directory '.vscode' if not already present in the root of the project + + - Create the following files inside the .vscode directory + + settings.json + .. code-block:: json + + { + "python.defaultInterpreterPath": "venv3/bin/python", + "python.formatting.provider": "black", + "python.formatting.blackArgs": [ + "--config", + "black.toml" + ], + "editor.formatOnSave": true, + "python.sortImports.args": [ + "--profile=black", + ], + "[python]": { + "editor.codeActionsOnSave": { + "source.organizeImports": true + } + }, + "python.linting.pylintEnabled": false, + "python.linting.flake8Enabled": true, + "python.linting.enabled": true + } + + tasks.json + .. code-block:: json + + { + "version": "2.0.0", + "tasks": [ + { + "label": "clean build artifacts", + "type": "shell", + "command": "python ./setup.py clean" + }, + { + "label": "build docs", + "type": "shell", + "command": "sphinx-build -b html ./docs ./docs/_build" + } + ] + } + + + launch.json + .. code-block:: json + + { + "version": "0.2.0", + "configurations": [ + { + "name": "Octoprint", + "type": "python", + "request": "launch", + "module": "octoprint", + "args": [ + "serve", + "--debug" + ], + "cwd": "${workspaceFolder}/src", + "preLaunchTask": "clean build artifacts" + } + ] + } + + In the terminal install the python extension by running this command: + .. code-block:: bash + + code --install-extension ms-python.python + + In vscode terminal, or with venv active install code formatter black and linter flake8 by running: + .. code-block:: bash + + python -m pip install -U black flake8 flake8-bugbear + + Summary of vscode config: + + * Pressing f5 will now start OctoPrint in debug + + * Your terminal inside vscode uses the virtrual python environment + + * Saving a file will run an auto formatter and import sort + + * Ctrl + shift + b can be used to run the 'build docs' task to rebuild the documentation + + + From e993405785dc0b6ed09266d27e38860763a7fcad Mon Sep 17 00:00:00 2001 From: Ben Sycha Date: Tue, 20 Jul 2021 16:22:44 +0100 Subject: [PATCH 08/29] Apply suggestions from code review Fix typos and remove irrelevant line Co-authored-by: Charlie Powell <31997505+cp2004@users.noreply.github.com> --- docs/development/environment.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/development/environment.rst b/docs/development/environment.rst index 7da2b4c72..b6e56e1d7 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -390,9 +390,8 @@ Otherwise go through Settings. Visual Studio Code (vscode) --------------------------- - - Install Visual Studio from https://code.visualstudio.com/Download + - Install Visual Studio Code from https://code.visualstudio.com/Download - Open folder select OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) - settings.json - Create a directory '.vscode' if not already present in the root of the project @@ -449,7 +448,7 @@ Visual Studio Code (vscode) "version": "0.2.0", "configurations": [ { - "name": "Octoprint", + "name": "OctoPrint", "type": "python", "request": "launch", "module": "octoprint", @@ -477,11 +476,10 @@ Visual Studio Code (vscode) * Pressing f5 will now start OctoPrint in debug - * Your terminal inside vscode uses the virtrual python environment + * Your terminal inside vscode uses the virtual python environment * Saving a file will run an auto formatter and import sort * Ctrl + shift + b can be used to run the 'build docs' task to rebuild the documentation - From 161e21fe0f6344ec3b9b9b541e9b2c472087ba77 Mon Sep 17 00:00:00 2001 From: Ben Sycha Date: Tue, 20 Jul 2021 17:39:01 +0100 Subject: [PATCH 09/29] Apply suggestions from code review to fix RST formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gina Häußge --- docs/development/environment.rst | 117 ++++++++++++++++--------------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/docs/development/environment.rst b/docs/development/environment.rst index b6e56e1d7..47379244c 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -390,96 +390,99 @@ Otherwise go through Settings. Visual Studio Code (vscode) --------------------------- - - Install Visual Studio Code from https://code.visualstudio.com/Download + + - Install Visual Studio Code from `code.visualstudio.com `_ - Open folder select OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) - - Create a directory '.vscode' if not already present in the root of the project + - Create a directory ``.vscode`` if not already present in the root of the project - - Create the following files inside the .vscode directory + - Create the following files inside the ``.vscode`` directory settings.json .. code-block:: json - { - "python.defaultInterpreterPath": "venv3/bin/python", - "python.formatting.provider": "black", - "python.formatting.blackArgs": [ - "--config", - "black.toml" - ], - "editor.formatOnSave": true, - "python.sortImports.args": [ - "--profile=black", - ], - "[python]": { - "editor.codeActionsOnSave": { - "source.organizeImports": true - } - }, - "python.linting.pylintEnabled": false, - "python.linting.flake8Enabled": true, - "python.linting.enabled": true - } + { + "python.defaultInterpreterPath": "venv3/bin/python", + "python.formatting.provider": "black", + "python.formatting.blackArgs": [ + "--config", + "black.toml" + ], + "editor.formatOnSave": true, + "python.sortImports.args": [ + "--profile=black", + ], + "[python]": { + "editor.codeActionsOnSave": { + "source.organizeImports": true + } + }, + "python.linting.pylintEnabled": false, + "python.linting.flake8Enabled": true, + "python.linting.enabled": true + } tasks.json .. code-block:: json - { - "version": "2.0.0", - "tasks": [ - { - "label": "clean build artifacts", - "type": "shell", - "command": "python ./setup.py clean" - }, - { - "label": "build docs", - "type": "shell", - "command": "sphinx-build -b html ./docs ./docs/_build" - } - ] - } + { + "version": "2.0.0", + "tasks": [ + { + "label": "clean build artifacts", + "type": "shell", + "command": "python ./setup.py clean" + }, + { + "label": "build docs", + "type": "shell", + "command": "sphinx-build -b html ./docs ./docs/_build" + } + ] + } launch.json .. code-block:: json - { - "version": "0.2.0", - "configurations": [ - { - "name": "OctoPrint", - "type": "python", - "request": "launch", - "module": "octoprint", - "args": [ - "serve", - "--debug" - ], - "cwd": "${workspaceFolder}/src", - "preLaunchTask": "clean build artifacts" - } - ] - } + { + "version": "0.2.0", + "configurations": [ + { + "name": "OctoPrint", + "type": "python", + "request": "launch", + "module": "octoprint", + "args": [ + "serve", + "--debug" + ], + "cwd": "${workspaceFolder}/src", + "preLaunchTask": "clean build artifacts" + } + ] + } In the terminal install the python extension by running this command: + .. code-block:: bash code --install-extension ms-python.python In vscode terminal, or with venv active install code formatter black and linter flake8 by running: + .. code-block:: bash python -m pip install -U black flake8 flake8-bugbear Summary of vscode config: - * Pressing f5 will now start OctoPrint in debug + * Pressing ``F5`` will now start OctoPrint in debug mode * Your terminal inside vscode uses the virtual python environment * Saving a file will run an auto formatter and import sort - * Ctrl + shift + b can be used to run the 'build docs' task to rebuild the documentation + * ``Ctrl+Shift+B`` can be used to run the ``build docs`` task to rebuild the documentation From 464f0cd83fd6f6d0db054f3b087b77165b025c2c Mon Sep 17 00:00:00 2001 From: Charlie Powell <31997505+cp2004@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:26:37 +0100 Subject: [PATCH 10/29] :pencil2: Additional file information properties documented Closes #2682 --- docs/api/datamodel.rst | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/docs/api/datamodel.rst b/docs/api/datamodel.rst index 703c19c4e..da82c02e7 100644 --- a/docs/api/datamodel.rst +++ b/docs/api/datamodel.rst @@ -365,6 +365,14 @@ Files - 0..1 - :ref:`GCODE analysis information ` - Information from the analysis of the GCODE file, if available. Left out in abridged version. + * - ``prints`` + - 0..1 + - :ref:`Print history information ` + - Information about previous prints of the file. Left out if the file has never been printed. + * - ``statistics`` + - 0..1 + - :ref:`Print statistics information ` + - Statistics about the file, based on the previous print times. Left out if the file has never been printed. .. _sec-api-datamodel-files-fileabridged: @@ -506,6 +514,62 @@ References - The model from which this file was generated (e.g. an STL, currently not used). Never present for folders. +.. _sec-api-datamodel-files-prints: + +Print History +------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``success`` + - 1 + - Number + - Number of successful prints + * - ``failure`` + - 1 + - Number + - Number of failed prints + * - ``last.date`` + - 1 + - Unix Timestamp + - Last date this file was printed + * - ``last.printTime`` + - 1 + - Float + - Last print time in seconds + * - ``last.success`` + - 1 + - Boolean + - Whether the last print was a success or not + +.. _sec-api-datamodel-files-stats: + +Print Statistics +---------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``averagePrintTime`` + - 1 + - Object + - Object that maps printer profile names to the last print time of the file, in seconds + * - ``lastPrintTime`` + - 1 + - Object + - Object that maps printer profile names to the average print time of the file, in seconds + .. _sec-api-datamodel-access: Access control From 19388fc11f6fb62b8840d51ded7498c7b0028e49 Mon Sep 17 00:00:00 2001 From: Charlie Powell <31997505+cp2004@users.noreply.github.com> Date: Wed, 21 Jul 2021 14:51:51 +0100 Subject: [PATCH 11/29] :pencil2: Add link to data model for printer profiles for gcode scripts Closes #3603 --- docs/features/gcode_scripts.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/features/gcode_scripts.rst b/docs/features/gcode_scripts.rst index d836d3fad..a15cc7f79 100644 --- a/docs/features/gcode_scripts.rst +++ b/docs/features/gcode_scripts.rst @@ -70,7 +70,8 @@ Context All GCODE scripts have access to the following template variables through the template context: * ``printer_profile``: The currently selected :ref:`Printer Profile `, including - information such as the extruder count, the build volume size, the filament diameter etc. + information such as the extruder count, the build volume size, the filament diameter etc. The individual properties + follow the common data model for :ref:`printer profiles `. * ``last_position``: Last position reported by the printer via `M114` (might be unset if no `M114` was sent so far!). Consists of ``x``, ``y``, ``z`` and ``e`` coordinates as received by the printer and tracked values for ``f`` and current tool ``t`` taken from commands sent through OctoPrint. All of these coordinates might be ``None`` if no From 52e105416d69ba14cbddf269e5c19f13d1271823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 26 Jul 2021 16:49:49 +0200 Subject: [PATCH 12/29] =?UTF-8?q?=F0=9F=A5=85=20Better=20error=20handling?= =?UTF-8?q?=20of=20resend=20history=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not a fix for #4194, but at least a less fatal handling. --- src/octoprint/util/comm.py | 56 +++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 7f69652a0..8355e6286 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -4153,27 +4153,7 @@ class MachineCom(object): self._lastResendNumber = lineToResend self._currentResendCount = 0 - if ( - self._resendDelta > len(self._lastLines) - or len(self._lastLines) == 0 - or self._resendDelta < 0 - ): - error_text = "Printer requested line {} but no sufficient history is available, can't resend".format( - lineToResend - ) - self._log(error_text) - self._logger.warning( - error_text - + ". Printer requested line {}, current line is {}, line history has {} entries.".format( - lineToResend, self._current_line, len(self._lastLines) - ) - ) - if self.isPrinting(): - # abort the print & disconnect, there's nothing we can do to rescue it - self._trigger_error(error_text, "resend") - else: - # reset resend delta, we can't do anything about it - self._resendDelta = None + self._resendCheckPossibility(lineToResend) # if we log resends, make sure we don't log more resends than the set rate within a window # @@ -4241,9 +4221,14 @@ class MachineCom(object): # resend_ok_timer, so make sure that resendDelta is actually still set (see #2632) return False - cmd = self._lastLines[-self._resendDelta].decode("ascii") lineNumber = self._current_line - self._resendDelta + if not self._resendCheckPossibility(lineNumber): + # Something has gone wrong if we get here, but we already logged and + # handled it. + return False + + cmd = self._lastLines[-self._resendDelta].decode("ascii") result = self._enqueue_for_sending(cmd, linenumber=lineNumber, resend=True) self._resendDelta -= 1 @@ -4258,6 +4243,33 @@ class MachineCom(object): return result + def _resendCheckPossibility(self, lineno): + if ( + self._resendDelta > len(self._lastLines) + or len(self._lastLines) == 0 + or self._resendDelta < 0 + ): + error_text = "Should resend line {} but no sufficient history is available, can't resend".format( + lineno + ) + self._log(error_text) + self._logger.warning( + error_text + + ". Line to resend is {}, current line is {}, line history has {} entries.".format( + lineno, self._current_line, len(self._lastLines) + ) + ) + if self.isPrinting(): + # abort the print & disconnect, there's nothing we can do to rescue it + self._trigger_error(error_text, "resend") + else: + # reset resend delta, we can't do anything about it + self._resendDelta = None + + return False + else: + return True + def _sendCommand(self, cmd, cmd_type=None, on_sent=None, tags=None): # Make sure we are only handling one sending job at a time with self._sendingLock: From 17c3d6e57afcdcfdcee913e95b1f77075f13efc4 Mon Sep 17 00:00:00 2001 From: jneilliii Date: Sat, 17 Jul 2021 11:58:17 -0400 Subject: [PATCH 13/29] added an events bundled plugin for managing event settings --- src/octoprint/plugins/events/__init__.py | 58 +++++++++++++++++ .../plugins/events/static/js/events.js | 57 ++++++++++++++++ .../events/templates/events_settings.jinja2 | 65 +++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 src/octoprint/plugins/events/__init__.py create mode 100644 src/octoprint/plugins/events/static/js/events.js create mode 100644 src/octoprint/plugins/events/templates/events_settings.jinja2 diff --git a/src/octoprint/plugins/events/__init__.py b/src/octoprint/plugins/events/__init__.py new file mode 100644 index 000000000..1e8ff3b4a --- /dev/null +++ b/src/octoprint/plugins/events/__init__.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +from flask_babel import gettext + +import octoprint.events +import octoprint.plugin +from octoprint.access import ADMIN_GROUP + + +class eventsPlugin( + octoprint.plugin.SettingsPlugin, + octoprint.plugin.AssetPlugin, + octoprint.plugin.TemplatePlugin, +): + def on_settings_load(self): + my_settings = { + "availableEvents": octoprint.events.all_events(), + "subscriptions": [], + } + events = self._settings.global_get(["events"]) + if events: + my_settings["subscriptions"] = events["subscriptions"] + return my_settings + + def on_settings_save(self, data): + if type(data.get("subscriptions")) == list: + self._settings.global_set( + ["events", "subscriptions"], data.get("subscriptions", []) + ) + + def get_assets(self): + return {"js": ["js/events.js"]} + + def get_template_configs(self): + return [{"type": "settings", "custom_bindings": True}] + + def get_additional_permissions(self): + return [ + { + "key": "MANAGE", + "name": "Event management", + "description": gettext( + "Allows for the management of event subscriptions." + ), + "default_groups": [ADMIN_GROUP], + "roles": ["manage"], + } + ] + + +__plugin_name__ = "Events" +__plugin_pythoncompat__ = ">=2.7,<4" +__plugin_author__ = "jneilliii" +__plugin_license__ = "AGPLv3" +__plugin_description__ = ( + "Plugin to configure event subscriptions available in config.yaml." +) +__plugin_implementation__ = eventsPlugin() diff --git a/src/octoprint/plugins/events/static/js/events.js b/src/octoprint/plugins/events/static/js/events.js new file mode 100644 index 000000000..7013789a7 --- /dev/null +++ b/src/octoprint/plugins/events/static/js/events.js @@ -0,0 +1,57 @@ +/* + * View model for OctoPrint-EventCoordinator + * + * Author: jneilliii + * License: MIT + */ +$(function () { + function EventcoordinatorViewModel(parameters) { + var self = this; + + self.settingsViewModel = parameters[0]; + self.selected_command = ko.observable(); + + self.event_details = function (data) { + if (data === false) { + return { + event: ko.observable(""), + command: ko.observable(""), + type: ko.observable(""), + enabled: ko.observable(true), + debug: ko.observable(false) + }; + } else { + if (!data.hasOwnProperty("enabled")) { + data["enabled"] = ko.observable(true); + } + if (!data.hasOwnProperty("debug")) { + data["debug"] = ko.observable(false); + } + return data; + } + }; + + self.addEvent = function () { + self.selected_command(self.event_details(false)); + self.settingsViewModel.settings.plugins.events.subscriptions.push( + self.selected_command() + ); + $("#EventCoordinatorEditor").modal("show"); + }; + + self.editEvent = function (data) { + self.selected_command(self.event_details(data)); + $("#EventCoordinatorEditor").modal("show"); + }; + + self.removeEvent = function (data) { + self.settingsViewModel.settings.plugins.events.subscriptions.remove(data); + }; + } + + OCTOPRINT_VIEWMODELS.push({ + construct: EventcoordinatorViewModel, + dependencies: ["settingsViewModel"], + elements: ["#settings_plugin_events"] + }); +}); diff --git a/src/octoprint/plugins/events/templates/events_settings.jinja2 b/src/octoprint/plugins/events/templates/events_settings.jinja2 new file mode 100644 index 000000000..68cf4ffab --- /dev/null +++ b/src/octoprint/plugins/events/templates/events_settings.jinja2 @@ -0,0 +1,65 @@ +
+

For additional information on OctoPrint events please see the official documentation here.

+

Warning: For changes to take effect you must restart OctoPrint after saving.

+
+
+
Event
+
Command
+
+ +
+
+
+
+
+
+
+ + +
+
+
+ + From 51b4375ed78b0ece29b874e65116f0cf9e5d68c3 Mon Sep 17 00:00:00 2001 From: jneilliii Date: Thu, 22 Jul 2021 12:42:35 -0400 Subject: [PATCH 14/29] order events in settings --- src/octoprint/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 2015d0e5e..381c8ab4e 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -375,6 +375,7 @@ default_settings = { "plugin_pluginmanager", "plugin_softwareupdate", "plugin_announcements", + "plugin_events", "plugin_backup", "plugin_tracking", "plugin_errortracking", From 122a6667ea4ff4c04b6c280f3cbffebf1f9e2820 Mon Sep 17 00:00:00 2001 From: jneilliii Date: Thu, 22 Jul 2021 19:15:32 -0400 Subject: [PATCH 15/29] add localization, per @cp2004 --- src/octoprint/plugins/events/__init__.py | 2 +- .../events/templates/events_settings.jinja2 | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/octoprint/plugins/events/__init__.py b/src/octoprint/plugins/events/__init__.py index 1e8ff3b4a..b59f11fc1 100644 --- a/src/octoprint/plugins/events/__init__.py +++ b/src/octoprint/plugins/events/__init__.py @@ -32,7 +32,7 @@ class eventsPlugin( return {"js": ["js/events.js"]} def get_template_configs(self): - return [{"type": "settings", "custom_bindings": True}] + return [{"type": "settings", "custom_bindings": True, "name": gettext("Events")}] def get_additional_permissions(self): return [ diff --git a/src/octoprint/plugins/events/templates/events_settings.jinja2 b/src/octoprint/plugins/events/templates/events_settings.jinja2 index 68cf4ffab..bbcecb2ee 100644 --- a/src/octoprint/plugins/events/templates/events_settings.jinja2 +++ b/src/octoprint/plugins/events/templates/events_settings.jinja2 @@ -1,12 +1,12 @@
-

For additional information on OctoPrint events please see the official documentation here.

-

Warning: For changes to take effect you must restart OctoPrint after saving.

+

{{ _('For additional information on OctoPrint events please see the official documentation') }} {{ _('here') }}.

+

{{ _('Warning:') }} {{ _('For changes to take effect you must restart OctoPrint after saving.') }}

-
Event
-
Command
+
{{ _('Event') }}
+
{{ _('Command') }}
- +
@@ -23,35 +23,35 @@
-
+
@@ -20,7 +20,7 @@
-