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: 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: diff --git a/.versioneer-lookup b/.versioneer-lookup index 6075a0bba..22e03c712 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -18,21 +18,21 @@ prerelease HEAD \(detached.* -# maintenance is currently the branch for preparation of maintenance release 1.7.0 +# maintenance is currently the branch for preparation of maintenance release 1.8.0 # so are any fix/... and improve/... branches -maintenance 1.7.0 07c4630d126617c2ae98a9c23ad49facf7bf0bbd pep440-dev -fix/.* 1.7.0 07c4630d126617c2ae98a9c23ad49facf7bf0bbd pep440-dev -improve/.* 1.7.0 07c4630d126617c2ae98a9c23ad49facf7bf0bbd pep440-dev +maintenance 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev +fix/.* 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev +improve/.* 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev # staging/bugfix is the branch for preparation of the 1.6.1 bugfix release # so are any bug/... branches staging/bugfix 1.6.1 29484fb2926960279e62881d6ee073c374a2a5fe pep440-dev bug/.* 1.6.1 29484fb2926960279e62881d6ee073c374a2a5fe pep440-dev -# staging/maintenance is currently the branch for preparation of 1.6.0rc4 +# staging/maintenance is currently the branch for preparation of 1.7.0rc2 # so is regressionfix/... -staging/maintenance 1.6.0rc4 7054a726bb3dc363a98ec6944b24e07879bb389b pep440-dev -regressionfix/.* 1.6.0rc4 7054a726bb3dc363a98ec6944b24e07879bb389b pep440-dev +staging/maintenance 1.7.0rc2 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev +regressionfix/.* 1.7.0rc2 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev # staging/devel is currently inactive (but has the 1.4.1rc4 namespace) staging/devel 1.4.1rc4 650d54d1885409fa1d411eb54b9e8c7ff428910f pep440-dev diff --git a/AUTHORS.md b/AUTHORS.md index 25fca2f57..1016145b9 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -146,6 +146,8 @@ 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) + * [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/SUPPORTERS.md b/SUPPORTERS.md index dcdf69cf9..00a2ccad2 100644 --- a/SUPPORTERS.md +++ b/SUPPORTERS.md @@ -9,6 +9,7 @@ thanks to everyone who contributed! * 3D-TECH * 3DPrinterOS * Arnljot Arntsen + * Artillery 3D * Ash King * BigTreeTech * Boris Hussein @@ -18,56 +19,56 @@ thanks to everyone who contributed! * Chris Lynch * Christian Petropolis * Christian Wolf + * Christian Würthner * Christoph Sigrist * Creality3D - * D Brian Kimmel * Dana Voigt + * David Bounds * DeltaMaker 3D Printers * Dennis Breining - * Dennis Christilaw * Douglas Floyd + * Dr. Frank Wester * Eric Betts * Ernesto Martinez * Franziska Kunsmann * George Robles * Greg Holloway * Hog Duske - * Hopewell Medical Acupuncture Center + * Itay Shem-tov * Jeremy Cole * Joshua Wills * Julian Melo * Justin Kaufman * Kaile Riser - * Kale Stedman * Kazuhiro Ogura * Kelly C McNiece * Kenneth Jiang * Kurt Wubbels * Kyle Menigoz * LA 3D Printer Repair + * Lachlan Bell * Lee Dohm + * LulzBot * Makespace Madrid * Mark Walker * Michael Aumock + * Mike Kershaw * Miles Flavel * Mosaic Manufacturing * Nat Friedman * Neil R. Goldberg * Norman Jaffe * Ory Weaver - * Patrick Glyré + * Peopoly * Pete Barnwell - * Prof Yuh Wen Chen * Raise3D * Randy C. Will * Ranjib Dey * Richard McGuire * Richard Michaud * Richard Stocks - * Rigid3D * Robert Gusek * Ronald Griehsler - * Sacha Telgenhof * Sebastien Andrivet * Stefan Krister * Steve Thompson @@ -77,4 +78,4 @@ thanks to everyone who contributed! * Ulderico Cirello * Ulrich Kempken -and 2350 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [GitHub Sponsors](https://github.com/users/foosel/sponsorship)! +and 2334 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [GitHub Sponsors](https://github.com/users/foosel/sponsorship)! diff --git a/docs/api/datamodel.rst b/docs/api/datamodel.rst index 514631c74..24a10f904 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 diff --git a/docs/development/environment.rst b/docs/development/environment.rst index d0bab6915..f8dcfb258 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -315,3 +315,102 @@ 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 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 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 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 + + diff --git a/docs/events/index.rst b/docs/events/index.rst index 71a55d68e..a9b030095 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -607,6 +607,11 @@ 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!) + + .. versionadded:: 1.7.0 + 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/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 diff --git a/setup.py b/setup.py index 9d96e782e..acf650fe4 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ INSTALL_REQUIRES = [ # additional OctoPrint plugins that are maintained on a different release cycle "OctoPrint-FileCheck>=2021.2.23", "OctoPrint-FirmwareCheck>=2021.2.4", - "OctoPrint-PiSupport>=2021.3.26", + "OctoPrint-PiSupport>=2021.8.2", # 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 @@ -35,12 +35,12 @@ INSTALL_REQUIRES = [ "flask>=1.1.2,<2", "Jinja2>=2.11.2,<3", "Flask-Login>=0.5,<0.6", # flask-login doesn't use semver & breaks stuff on minor version increases - "Flask-Babel>=1.0,<2", + "Flask-Babel>=1.0,<2", # newer versions require Python 3 "Flask-Assets>=2.0,<3", - "werkzeug>=1.0.1,<2", - "itsdangerous>=1.1.0,<2", - "cachelib>=0.1,<1", - "PyYAML>=5.3.1,<6", + "werkzeug>=1.0.1,<2", # newer versions require Python 3 + "itsdangerous>=1.1.0,<2", # newer versions require Python 3 + "cachelib>=0.1,<0.2", # newer versions require Python 3 + "PyYAML>=5.4.1,<6", "pyserial>=3.4,<4", "netaddr>=0.7.19,<1", "watchdog==1.0.0", @@ -53,26 +53,26 @@ INSTALL_REQUIRES = [ "semantic_version>=2.8.5,<3", "psutil>=5.7,<6", "Click>=7.1.2,<8", - "feedparser>=6.0.2,<7", + "feedparser>=6.0.8,<7", "future>=0.18.2,<1", # not really needed anymore, but leaving in for py2/3 compat plugins "websocket-client>=0.57,<1", "wrapt>=1.12.1,<2", "emoji>=0.5.4,<1", - "immutabledict>=1.2.0,<2", + "immutabledict>=2.1,<3", "sentry-sdk>=0.15.1,<1", "filetype>=1.0.7,<2", - "zeroconf>=0.24,<0.25", + "zeroconf>=0.33,<0.34", "zipstream-new>=1.1.8,<1.2", "pathvalidate>=2.4.1,<3", "colorlog>=5.0.1,<6", # vendor bundled dependencies - "unidecode>=0.04.14,<0.05", # dependency of awesome-slugify + "unidecode", # dependency of awesome-slugify, leave w/o range to not cause dependency hell w/ Octolapse deps "blinker>=1.4,<2", # dependency of flask_principal ] # OSX specific requirements INSTALL_REQUIRES_OSX = [ - "appdirs>=1.4.4", + "appdirs>=1.4.4,<2", ] # Additional requirements for optional install options diff --git a/src/octoprint/__init__.py b/src/octoprint/__init__.py index a34230eb5..ff8632fe9 100644 --- a/src/octoprint/__init__.py +++ b/src/octoprint/__init__.py @@ -266,16 +266,16 @@ def init_logging( "formatters": { "simple": {"format": simple_format}, "colored": { - "class": "colorlog.ColoredFormatter", - "format": "%(log_color)s" + simple_format, + "()": "colorlog.ColoredFormatter", + "format": "%(log_color)s" + simple_format + "%(reset)s", + "reset": True, "log_colors": { - "DEBUG": "light_white", + "DEBUG": "cyan", "INFO": "white", "WARNING": "yellow", "ERROR": "red", "CRITICAL": "bold_red", }, - "reset": True, }, "serial": {"format": "%(asctime)s - %(message)s"}, "timings": {"format": "%(asctime)s - %(message)s"}, diff --git a/src/octoprint/events.py b/src/octoprint/events.py index f93553ee9..17ed69b1e 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -98,6 +98,7 @@ class Events: REGISTERED_MESSAGE_RECEIVED = "RegisteredMessageReceived" COMMAND_SUPPRESSED = "CommandSuppressed" INVALID_TOOL_REPORTED = "InvalidToolReported" + FILAMENT_CHANGE = "FilamentChange" # Timelapse CAPTURE_START = "CaptureStart" diff --git a/src/octoprint/plugins/errortracking/__init__.py b/src/octoprint/plugins/errortracking/__init__.py index 9d2975d7e..4e7432b07 100644 --- a/src/octoprint/plugins/errortracking/__init__.py +++ b/src/octoprint/plugins/errortracking/__init__.py @@ -18,10 +18,10 @@ from octoprint.util.version import ( ) SENTRY_URL_SERVER = ( - "https://6a544965fe6c4c6eb96f7e39352b2924@o118517.ingest.sentry.io/1373987" + "https://72786e02c7bf4e8487cc987b24f855fd@o118517.ingest.sentry.io/1373987" ) SENTRY_URL_COREUI = ( - "https://840570e9555741bcb82bd56a084fb46e@o118517.ingest.sentry.io/1374096" + "https://94a57f3316ec4d2a80d454695fcb72dd@o118517.ingest.sentry.io/1374096" ) SETTINGS_DEFAULTS = { diff --git a/src/octoprint/plugins/eventmanager/__init__.py b/src/octoprint/plugins/eventmanager/__init__.py new file mode 100644 index 000000000..da8a54eac --- /dev/null +++ b/src/octoprint/plugins/eventmanager/__init__.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- + +from flask_babel import gettext + +import octoprint.events +import octoprint.plugin +from octoprint.access import ADMIN_GROUP + + +class EventManagerPlugin( + 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.get("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, + "name": gettext("Event Manager"), + } + ] + + 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__ = gettext("Event Manager") +__plugin_pythoncompat__ = ">=2.7,<4" +__plugin_author__ = "jneilliii" +__plugin_license__ = "AGPLv3" +__plugin_description__ = gettext( + "Plugin to configure event subscriptions available in config.yaml." +) +__plugin_implementation__ = EventManagerPlugin() diff --git a/src/octoprint/plugins/eventmanager/static/js/events.js b/src/octoprint/plugins/eventmanager/static/js/events.js new file mode 100644 index 000000000..f30e4972f --- /dev/null +++ b/src/octoprint/plugins/eventmanager/static/js/events.js @@ -0,0 +1,59 @@ +/* + * View model for OctoPrint-EventCoordinator + * + * Author: jneilliii + * License: AGPLv3 + */ +$(function () { + function eventManagerViewModel(parameters) { + var self = this; + + self.settingsViewModel = parameters[0]; + self.selectedCommand = ko.observable(); + + self.eventDetails = 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.selectedCommand(self.eventDetails(false)); + self.settingsViewModel.settings.plugins.eventmanager.subscriptions.push( + self.selectedCommand() + ); + $("#EventManagerEditor").modal("show"); + }; + + self.editEvent = function (data) { + self.selectedCommand(self.eventDetails(data)); + $("#EventManagerEditor").modal("show"); + }; + + self.removeEvent = function (data) { + self.settingsViewModel.settings.plugins.eventmanager.subscriptions.remove( + data + ); + }; + } + + OCTOPRINT_VIEWMODELS.push({ + construct: eventManagerViewModel, + dependencies: ["settingsViewModel"], + elements: ["#settings_plugin_eventmanager"] + }); +}); diff --git a/src/octoprint/plugins/eventmanager/templates/eventmanager_settings.jinja2 b/src/octoprint/plugins/eventmanager/templates/eventmanager_settings.jinja2 new file mode 100644 index 000000000..9f070759b --- /dev/null +++ b/src/octoprint/plugins/eventmanager/templates/eventmanager_settings.jinja2 @@ -0,0 +1,65 @@ +
+

{{ _('For additional information on OctoPrint events please see the official documentation.', url='https://docs.octoprint.org/en/master/events/index.html') }}

+

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

+
+
+
{{ _('Event') }}
+
{{ _('Command') }}
+
+ +
+
+
+
+
+
+
+ + +
+
+
+ + diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 9b79bf63a..50f618867 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -63,6 +63,8 @@ class SoftwareUpdatePlugin( OCTOPRINT_RESTART_TYPES = ("pip", "single_file_plugin") + VALID_RESTART_TYPES = ("octoprint", "environment") + DATA_FORMAT_VERSION = "v4" CHECK_OVERLAY_KEY = "softwareupdate_check_overlay" @@ -625,15 +627,45 @@ class SoftwareUpdatePlugin( self._save_update_log() def _is_octoprint_outdated_and_can_update(self): - information, update_available, update_possible = self.get_current_versions() - if not update_available or not update_possible or "octoprint" not in information: + checks = self._get_configured_checks() + check = checks.get("octoprint", None) + if not check: return False - octoprint_information = information["octoprint"] - return ( - octoprint_information["updateAvailable"] - and octoprint_information["updatePossible"] + check = self._populated_check("octoprint", check) + credentials = self._settings.get(["credentials"], merged=True) + + _, update_available, update_possible, _, _ = self._get_current_version( + "octoprint", check, credentials=credentials ) + if not update_available or not update_possible: + return False + + restart_type = self._get_restart_type(check) + restart_command = self._get_restart_command(restart_type) + return restart_command is not None + + def _get_restart_type(self, check): + if check.get("restart") in self.VALID_RESTART_TYPES: + return check["restart"] + elif "pip" in check or check.get("method") in self.OCTOPRINT_RESTART_TYPES: + return "octoprint" + else: + target_restart_type = None + + return target_restart_type + + def _get_restart_command(self, restart_type): + if restart_type == "octoprint": + return self._settings.global_get( + ["server", "commands", "serverRestartCommand"] + ) + elif restart_type == "environment": + return self._settings.global_get( + ["server", "commands", "systemRestartCommand"] + ) + else: + return None # ~~ SettingsPlugin API @@ -1087,6 +1119,8 @@ class SoftwareUpdatePlugin( )(view)() @octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"]) + @no_firstrun_access + @Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.require(403) def check_for_update(self): if ( not Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.can() @@ -1428,7 +1462,11 @@ class SoftwareUpdatePlugin( def _is_wizard_update_required(self): firstrun = self._settings.global_get(["server", "firstRun"]) - return firstrun and self._is_octoprint_outdated_and_can_update() + return ( + firstrun + and self._is_octoprint_outdated_and_can_update() + and not self._is_settings_wizard_required() + ) def _is_settings_wizard_required(self): checks = self._get_configured_checks() @@ -1442,6 +1480,14 @@ class SoftwareUpdatePlugin( def get_wizard_version(self): return 1 + def get_wizard_details(self): + result = {} + if self._is_wizard_update_required(): + information, _, _ = self.get_current_versions() + data = information.get("octoprint", {}) + result["update"] = data + return result + ##~~ EventHandlerPlugin API def on_event(self, event, payload): @@ -1881,15 +1927,7 @@ class SoftwareUpdatePlugin( if target_result is not None: target_results[target] = target_result - if "restart" in check: - target_restart_type = check["restart"] - elif ( - "pip" in check - or check.get("method") in self.OCTOPRINT_RESTART_TYPES - ): - target_restart_type = "octoprint" - else: - target_restart_type = None + target_restart_type = self._get_restart_type(check) # if our update requires a restart we have to determine which type if restart_type is None or ( @@ -1920,16 +1958,7 @@ class SoftwareUpdatePlugin( # one of our updates requires a restart of either type "octoprint" or "environment". Let's see if # we can actually perform that - restart_command = None - if restart_type == "octoprint": - restart_command = self._settings.global_get( - ["server", "commands", "serverRestartCommand"] - ) - elif restart_type == "environment": - restart_command = self._settings.global_get( - ["server", "commands", "systemRestartCommand"] - ) - + restart_command = self._get_restart_command(restart_type) if restart_command: self._send_client_message( "restarting", diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 11eee8226..f812219d7 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -306,74 +306,79 @@ $(function () { ); }; + self._enrichInformation = function (key, information) { + information["key"] = key; + + if ( + !information.hasOwnProperty("displayName") || + information.displayName === "" + ) { + information.displayName = information.key; + } + if ( + !information.hasOwnProperty("displayVersion") || + information.displayVersion === "" + ) { + information.displayVersion = information.information.local.name; + } + if ( + !information.hasOwnProperty("releaseNotes") || + information.releaseNotes === "" + ) { + information.releaseNotes = undefined; + } + + var fullNameTemplate = gettext("%(name)s: %(version)s"); + information.fullNameLocal = _.sprintf(fullNameTemplate, { + name: _.escape(information.displayName), + version: _.escape(information.displayVersion) + }); + + var fullNameRemoteVars = { + name: _.escape(information.displayName), + version: gettext("unknown") + }; + if ( + information.hasOwnProperty("information") && + information.information.hasOwnProperty("remote") && + information.information.remote.hasOwnProperty("name") + ) { + fullNameRemoteVars.version = _.escape( + information.information.remote.name + ); + } + information.fullNameRemote = _.sprintf(fullNameTemplate, fullNameRemoteVars); + + if (information.releaseChannels && information.releaseChannels.current) { + information.releaseChannels.current = ko.observable( + information.releaseChannels.current + ); + information.releaseChannels.current.subscribe(function (selected) { + var patch = {}; + patch[key] = {channel: selected}; + OctoPrint.plugins.softwareupdate.configure(patch).done(function () { + self.performCheck(false, false, false, [key]); + }); + }); + } + + information.toggleDisabled = function () { + var patch = {}; + patch[key] = {disabled: !information.disabled}; + OctoPrint.plugins.softwareupdate.configure(patch).done(function () { + self.performCheck(false, false, false, [key]); + }); + }; + + return information; + }; + self.fromCheckResponse = function (data, ignoreSeen, showIfNothingNew) { self.cacheTimestamp(data.timestamp); var versions = []; _.each(data.information, function (value, key) { - value["key"] = key; - - if (!value.hasOwnProperty("displayName") || value.displayName === "") { - value.displayName = value.key; - } - if ( - !value.hasOwnProperty("displayVersion") || - value.displayVersion === "" - ) { - value.displayVersion = value.information.local.name; - } - if (!value.hasOwnProperty("releaseNotes") || value.releaseNotes === "") { - value.releaseNotes = undefined; - } - - var fullNameTemplate = gettext("%(name)s: %(version)s"); - value.fullNameLocal = _.sprintf(fullNameTemplate, { - name: _.escape(value.displayName), - version: _.escape(value.displayVersion) - }); - - var fullNameRemoteVars = { - name: _.escape(value.displayName), - version: gettext("unknown") - }; - if ( - value.hasOwnProperty("information") && - value.information.hasOwnProperty("remote") && - value.information.remote.hasOwnProperty("name") - ) { - fullNameRemoteVars.version = _.escape(value.information.remote.name); - } - value.fullNameRemote = _.sprintf(fullNameTemplate, fullNameRemoteVars); - - if (value.releaseChannels && value.releaseChannels.current) { - value.releaseChannels.current = ko.observable( - value.releaseChannels.current - ); - value.releaseChannels.current.subscribe(function (selected) { - var patch = {}; - patch[key] = {channel: selected}; - OctoPrint.plugins.softwareupdate - .configure(patch) - .done(function () { - self.performCheck(false, false, false, [key]); - }); - }); - } - - value.toggleDisabled = function () { - var patch = {}; - patch[key] = {disabled: !value.disabled}; - OctoPrint.plugins.softwareupdate.configure(patch).done(function () { - self.performCheck(false, false, false, [key]); - }); - }; - - if (key === "octoprint") { - self.octoprintData.item = value; - self.octoprintData.current(value.information.local.name); - self.octoprintData.available(value.information.remote.name); - } - + self._enrichInformation(key, value); versions.push(value); }); self.versions.updateItems(versions); @@ -683,14 +688,7 @@ $(function () { }; self.performUpdate = function (force, items) { - if ( - !( - self.loginState.hasPermission( - self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE - ) || CONFIG_FIRST_RUN - ) - ) - return; + if (!self.updateAccess()) return; if (self.printerState.isPrinting()) return; self.updateInProgress = true; @@ -747,15 +745,16 @@ $(function () { return self.update(force, self.availableAndPossibleAndEnabled()); }; + self.updateAccess = function () { + return ( + self.loginState.hasPermission( + self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE + ) || CONFIG_FIRST_RUN + ); + }; + self.update = function (force, items) { - if ( - self.updateInProgress || - !( - self.loginState.hasPermission( - self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE - ) || CONFIG_FIRST_RUN - ) - ) { + if (self.updateInProgress || !self.updateAccess()) { self._updateClicked = false; return; } @@ -851,8 +850,10 @@ $(function () { self._showWorkingDialog = function (title) { if ( - !self.loginState.hasPermission( - self.access.permissions.PLUGIN_SOFTWAREUPDATE_CHECK + !( + self.loginState.hasPermission( + self.access.permissions.PLUGIN_SOFTWAREUPDATE_CHECK + ) || CONFIG_FIRST_RUN ) ) { return; @@ -929,6 +930,21 @@ $(function () { self.performCheck(); }; + self.onWizardDetails = function (data) { + if ( + data.softwareupdate && + data.softwareupdate.details && + data.softwareupdate.details.update + ) { + var value = data.softwareupdate.details.update; + self._enrichInformation("octoprint", value); + + self.octoprintData.item = value; + self.octoprintData.current(value.information.local.name); + self.octoprintData.available(value.information.remote.name); + } + }; + self.onDataUpdaterReconnect = function () { if (self.waitingForRestart) { self.waitingForRestart = false; diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index 0efe80cfd..a995fe21c 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -203,9 +203,9 @@