diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index e87f92caa..1f65e91af 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -1698,6 +1698,37 @@ octoprint.system.additional_commands :return: a list of command specifications :rtype: list +.. _sec-plugins-hook-systeminfo-additional_bundle_files: + +octoprint.systeminfo.additional_bundle_files +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. py:function:: additional_bundle_files_hook(*args, **kwargs) + + .. versionadded:: 1.7.0 + + Allows bundled plugins to extend the list of files to include in the systeminfo bundle. + Note that this hook will ignore third party plugins. Handlers must return a dictionary + mapping file names in the bundle to either local log paths on disk or a ``callable`` + that will be called to generate the file's content inside the bundle. + + **Example** + + Add a plugin's ``console`` log file to the systeminfo bundle: + + .. code-block:: python + + def get_additional_bundle_files(*args, **kwargs): + console_log = self._settings.get_plugin_logfile_path(postfix="console") + return {os.path.basename(console_log): console_log} + + __plugin_hooks__ = { + "octoprint.systeminfo.additional_bundle_files": get_additional_bundle_files + } + + :return: a dictionary mapping bundle file names to bundle file content + :rtype: dict + .. _sec-plugins-hook-timelapse-extensions: octoprint.timelapse.extensions diff --git a/src/octoprint/cli/systeminfo.py b/src/octoprint/cli/systeminfo.py index ccbb66edd..f069120c9 100644 --- a/src/octoprint/cli/systeminfo.py +++ b/src/octoprint/cli/systeminfo.py @@ -39,7 +39,7 @@ def get_systeminfo(environment_detector, connectivity_checker, additional_fields return flattened -def get_systeminfo_bundle(systeminfo, logbase, printer=None): +def get_systeminfo_bundle(systeminfo, logbase, printer=None, plugin_manager=None): from octoprint.util import to_bytes systeminfotxt = [] @@ -80,13 +80,41 @@ def get_systeminfo_bundle(systeminfo, logbase, printer=None): for log in ( "octoprint.log", "serial.log", - "plugin_softwareupdate_console.log", - "plugin_pluginmanager_console.log", ): logpath = os.path.join(logbase, log) if os.path.exists(logpath): z.write(logpath, arcname=log, compress_type=compress_type) + # add additional bundle contents from bundled plugins + if plugin_manager: + for name, hook in plugin_manager.get_hooks( + "octoprint.systeminfo.additional_bundle_files" + ).items(): + try: + plugin = plugin_manager.get_plugin_info(name) + if not plugin.bundled: + # we only support this for bundled plugins because we don't want + # third party logs to blow up the bundles + continue + + logs = hook() + + for log, content in logs.items(): + if isinstance(content, str): + # log path + if os.path.exists(content) and os.access(content, os.R_OK): + z.write(content, arcname=log, compress_type=compress_type) + elif callable(content): + # content generating callable + z.writestr(log, to_bytes(content()), compress_type=compress_type) + except Exception: + logging.getLogger(__name__).exception( + "Error while retrieving additional bundle contents for plugin {}".format( + name + ), + extra={"plugin": name}, + ) + return z @@ -137,7 +165,9 @@ def systeminfo_command(ctx, path, **kwargs): zipfilename = os.path.join(path, get_systeminfo_bundle_name()) click.echo(f"Writing systeminfo bundle to {zipfilename}...") - z = get_systeminfo_bundle(systeminfo, settings.getBaseFolder("logs")) + z = get_systeminfo_bundle( + systeminfo, settings.getBaseFolder("logs"), plugin_manager=plugin_manager + ) try: with open(zipfilename, "wb") as f: for data in z: diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index a3ec96bba..b3be4b0cb 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -1103,7 +1103,7 @@ class WizardPlugin(OctoPrintPlugin, ReloadNeedingPlugin): * the current and seen versions are identical * the current version is None and the seen version is not - * the current version is less or equal than the seen one + * the seen version is not None and the current version is less or equal than the seen one .. code-block:: none @@ -1155,7 +1155,7 @@ class WizardPlugin(OctoPrintPlugin, ReloadNeedingPlugin): return ( (current == seen) or (current is None and seen is not None) - or (current <= seen) + or (seen is not None and current <= seen) ) diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index a35f16e19..912f99249 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -239,6 +239,12 @@ class PluginManagerPlugin( }, ] + # Additional bundle contents + + def get_additional_bundle_files(self, *args, **kwargs): + console_log = self._settings.get_plugin_logfile_path(postfix="console") + return {os.path.basename(console_log): console_log} + ##~~ StartupPlugin def on_after_startup(self): @@ -2124,6 +2130,7 @@ def __plugin_load__(): "octoprint.ui.web.templatetypes": __plugin_implementation__.get_template_types, "octoprint.events.register_custom_events": _register_custom_events, "octoprint.access.permissions": __plugin_implementation__.get_additional_permissions, + "octoprint.systeminfo.additional_bundle_files": __plugin_implementation__.get_additional_bundle_files, } global __plugin_helpers__ diff --git a/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css b/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css index a3336d2e1..4525678b4 100644 --- a/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css +++ b/src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css @@ -1 +1 @@ -#settings_plugin_pluginmanager_pluginlist{height:calc(-350vh);display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em;position:relative;border-top:1px solid #eee;padding-top:6px}#settings_plugin_pluginmanager_pluginlist>table{margin-top:0}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name .prop,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name .prop{white-space:nowrap}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a.disabled,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_orphanlist{display:block;width:auto;max-height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px;margin-bottom:1em}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_id,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_id{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a.disabled,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_repositorydialog h4{position:relative}#settings_plugin_pluginmanager_repositorydialog h4 a.dropdown-toggle{color:inherit;text-decoration:none;font-size:14px}#settings_plugin_pluginmanager_repositorydialog h4 ul.dropdown-menu{font-size:14px}#settings_plugin_pluginmanager_repositorydialog .form-search{text-align:center;margin-bottom:5px!important}#settings_plugin_pluginmanager_repositorydialog .form-inline{padding:5px 10px 5px 5px;margin-bottom:0}#settings_plugin_pluginmanager_repositorydialog .form-inline .help-block{margin-bottom:0;font-size:85%}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable{overflow:hidden;width:100%;height:400px;background-image:url(../img/repo_unavailable.png);text-align:center;display:table}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty div,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable div{display:table-cell;vertical-align:middle}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list{width:auto;height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry{border-bottom:1px solid #ddd;padding:5px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .meta{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .stats .prop{white-space:nowrap}#settings_plugin_pluginmanager_workingdialog_output .message{font-weight:700}#settings_plugin_pluginmanager_workingdialog_output .error{font-weight:700;color:#900}#settings_plugin_pluginmanager_workingdialog_output .stdout{color:#333}#settings_plugin_pluginmanager_workingdialog_output .stderr{color:#900}#settings_plugin_pluginmanager_workingdialog_output .call{color:#009} \ No newline at end of file +#settings_plugin_pluginmanager_pluginlist{height:calc(100vh - 450px);display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em;position:relative;border-top:1px solid #eee;padding-top:6px}#settings_plugin_pluginmanager_pluginlist>table{margin-top:0}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name .prop,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name .prop{white-space:nowrap}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a.disabled,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_orphanlist{display:block;width:auto;max-height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px;margin-bottom:1em}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_id,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_id{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a.disabled,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_repositorydialog h4{position:relative}#settings_plugin_pluginmanager_repositorydialog h4 a.dropdown-toggle{color:inherit;text-decoration:none;font-size:14px}#settings_plugin_pluginmanager_repositorydialog h4 ul.dropdown-menu{font-size:14px}#settings_plugin_pluginmanager_repositorydialog .form-search{text-align:center;margin-bottom:5px!important}#settings_plugin_pluginmanager_repositorydialog .form-inline{padding:5px 10px 5px 5px;margin-bottom:0}#settings_plugin_pluginmanager_repositorydialog .form-inline .help-block{margin-bottom:0;font-size:85%}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable{overflow:hidden;width:100%;height:400px;background-image:url(../img/repo_unavailable.png);text-align:center;display:table}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty div,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable div{display:table-cell;vertical-align:middle}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list{width:auto;height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry{border-bottom:1px solid #ddd;padding:5px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .meta{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .stats .prop{white-space:nowrap}#settings_plugin_pluginmanager_workingdialog_output .message{font-weight:700}#settings_plugin_pluginmanager_workingdialog_output .error{font-weight:700;color:#900}#settings_plugin_pluginmanager_workingdialog_output .stdout{color:#333}#settings_plugin_pluginmanager_workingdialog_output .stderr{color:#900}#settings_plugin_pluginmanager_workingdialog_output .call{color:#009} \ No newline at end of file diff --git a/src/octoprint/plugins/pluginmanager/static/less/pluginmanager.less b/src/octoprint/plugins/pluginmanager/static/less/pluginmanager.less index 07c06d881..5ddbbc00d 100644 --- a/src/octoprint/plugins/pluginmanager/static/less/pluginmanager.less +++ b/src/octoprint/plugins/pluginmanager/static/less/pluginmanager.less @@ -2,7 +2,7 @@ } #settings_plugin_pluginmanager_pluginlist { - height: calc(100vh - 450px); + height: ~"calc(100vh - 450px)"; display: block; width: auto; overflow-x: hidden; diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index c0c954cd7..9b79bf63a 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -4,6 +4,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms import copy +import datetime import hashlib import logging import logging.handlers @@ -41,6 +42,8 @@ MINIMUM_PYTHON = "2.7.9" MINIMUM_SETUPTOOLS = "39.0.1" MINIMUM_PIP = "9.0.3" +DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" + ##~~ Plugin @@ -85,6 +88,11 @@ class SoftwareUpdatePlugin( self._overlay_cache_ttl = 0 self._overlay_cache_timestamp = None + self._update_log = [] + self._update_log_path = None + self._update_log_dirty = False + self._update_log_mutex = threading.RLock() + self._environment_supported = True self._environment_versions = {} self._environment_ready = threading.Event() @@ -107,6 +115,11 @@ class SoftwareUpdatePlugin( ) self._load_version_cache() + self._update_log_path = os.path.join( + self.get_plugin_data_folder(), "updatelog.yaml" + ) + self._load_update_log() + self._overlay_cache_ttl = self._settings.get_int(["check_overlay_ttl"]) * 60 def refresh_checks(name, plugin): @@ -145,6 +158,38 @@ class SoftwareUpdatePlugin( }, ] + # Additional bundle contents + + def get_additional_bundle_files(self, *args, **kwargs): + console_log = self._settings.get_plugin_logfile_path(postfix="console") + + def updatelog(): + if not self._update_log: + self._load_update_log() + + result = [] + for entry in self._update_log: + line = "{datetime} - {display_name} - {current_version} -> {target_version} - {success} - {text}".format( + datetime=entry["datetime"].replace("T", " "), + display_name=entry["display_name"], + current_version=entry["current_version"], + target_version=entry["target_version"], + success="SUCCESS" if entry["success"] else "FAILED", + text=entry["text"] + + ( + " (Release notes: {})".format(entry["release_notes"]) + if entry["release_notes"] + else "" + ), + ) + result.append(line) + return "\n".join(result) + + return { + os.path.basename(console_log): console_log, + "plugin_softwareupdate_update.log": updatelog, + } + def on_startup(self, host, port): console_logging_handler = logging.handlers.RotatingFileHandler( self._settings.get_plugin_logfile_path(postfix="console"), @@ -490,6 +535,106 @@ class SoftwareUpdatePlugin( pass self._version_cache_dirty = True + def _load_update_log(self): + if not os.path.isfile(self._update_log_path): + return + + import yaml + + try: + with open(self._update_log_path, encoding="utf-8") as f: + data = yaml.safe_load(f) + except Exception: + self._logger.exception("Error while loading update log from disk") + else: + # clean up data older than updatelog_cutoff hours + before_cleanup = len(data) + cutoff = ( + datetime.datetime.now() + - datetime.timedelta(minutes=self._settings.get_int(["updatelog_cutoff"])) + ).strftime(DATETIME_FORMAT) + data = sorted( + list( + filter( + lambda x: x.get("datetime") and x["datetime"] > cutoff, + data, + ) + ), + key=lambda x: x["datetime"], + ) + cleaned_up = len(data) - before_cleanup + if cleaned_up: + self._logger.info(f"Cleaned up {cleaned_up} old update log entries") + + with self._update_log_mutex: + self._update_log = data + self._update_log_dirty = False + + self._logger.info("Loaded update log from disk") + + def _save_update_log(self): + import yaml + + from octoprint.util import atomic_write + + with self._update_log_mutex: + with atomic_write( + self._update_log_path, mode="wt", max_permissions=0o666 + ) as file_obj: + yaml.safe_dump( + sorted(self._update_log, key=lambda x: x["datetime"]), + stream=file_obj, + default_flow_style=False, + indent=2, + allow_unicode=True, + ) + self._update_log_dirty = False + + self._logger.info("Saved update log to disk") + + def _add_update_log_entry( + self, + target, + current_version, + target_version, + success, + text, + display_name=None, + release_notes="", + save=True, + ): + if display_name is None: + display_name = target + + with self._update_log_mutex: + self._update_log.append( + { + "datetime": datetime.datetime.now().strftime(DATETIME_FORMAT), + "target": target, + "current_version": current_version, + "target_version": target_version, + "display_name": display_name, + "release_notes": release_notes if release_notes else "", + "success": success, + "text": text, + }, + ) + self._update_log_dirty = True + + if save: + 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: + return False + + octoprint_information = information["octoprint"] + return ( + octoprint_information["updateAvailable"] + and octoprint_information["updatePossible"] + ) + # ~~ SettingsPlugin API def get_settings_defaults(self): @@ -534,13 +679,14 @@ class SoftwareUpdatePlugin( }, }, "pip_command": None, - "cache_ttl": 24 * 60, + "cache_ttl": 24 * 60, # 1 day "notify_users": True, "ignore_throttled": False, "minimum_free_storage": 150, "check_overlay_url": "https://plugins.octoprint.org/update_check_overlay.json", "check_overlay_py2_url": "https://plugins.octoprint.org/update_check_overlay_py2.json", - "check_overlay_ttl": 6 * 60, + "check_overlay_ttl": 6 * 60, # 6 hours + "updatelog_cutoff": 30 * 24 * 60, # 30 days "credentials": { "github": None, "bitbucket_user": None, @@ -596,6 +742,7 @@ class SoftwareUpdatePlugin( else: data["octoprint_checkout_folder"] = None data["octoprint_type"] = None + data["octoprint_release_channel"] = None # ~~ pip check settings @@ -912,10 +1059,41 @@ class SoftwareUpdatePlugin( # ~~ BluePrint API - @octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"]) + @octoprint.plugin.BlueprintPlugin.route("/updatelog", methods=["GET"]) @no_firstrun_access - @Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.require(403) + @Permissions.ADMIN.require(403) + def get_update_log(self): + def view(): + return flask.jsonify(updatelog=list(reversed(self._update_log))) + + def etag(lm=None): + hash = hashlib.sha1() + + def hash_update(value): + value = value.encode("utf-8") + hash.update(value) + + hash_update(repr(self._update_log)) + return hash.hexdigest() + + def lastmodified(): + if os.path.exists(self._update_log_path): + return os.stat(self._update_log_path).st_mtime + else: + return 0 + + return with_revalidation_checking( + etag_factory=etag, lastmodified_factory=lastmodified + )(view)() + + @octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"]) def check_for_update(self): + if ( + not Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.can() + and not self._settings.global_get(["server", "firstRun"]) + ): + flask.abort(403) + request_data = flask.request.values if "targets" in request_data or "check" in request_data: @@ -1065,9 +1243,13 @@ class SoftwareUpdatePlugin( )(view)() @octoprint.plugin.BlueprintPlugin.route("/update", methods=["POST"]) - @no_firstrun_access - @Permissions.PLUGIN_SOFTWAREUPDATE_UPDATE.require(403) def perform_update(self): + if ( + not Permissions.PLUGIN_SOFTWAREUPDATE_UPDATE.can() + and not self._settings.global_get(["server", "firstRun"]) + ): + flask.abort(403) + throttled = self._get_throttled() if ( throttled @@ -1216,20 +1398,49 @@ class SoftwareUpdatePlugin( def get_template_configs(self): from flask_babel import gettext - return [{"type": "settings", "name": gettext("Software Update")}] + templates = [ + {"type": "settings", "name": gettext("Software Update")}, + ] + + if self._is_wizard_update_required(): + templates.append( + { + "type": "wizard", + "name": gettext("Update?"), + "template": "softwareupdate_wizard_update.jinja2", + "suffix": "_update", + } + ) + + if self._is_settings_wizard_required(): + templates.append( + { + "type": "wizard", + "name": gettext("Software Update"), + "template": "softwareupdate_wizard_settings.jinja2", + "suffix": "_settings", + } + ) + + return templates ##~~ WizardPlugin API - def is_wizard_required(self): + def _is_wizard_update_required(self): + firstrun = self._settings.global_get(["server", "firstRun"]) + return firstrun and self._is_octoprint_outdated_and_can_update() + + def _is_settings_wizard_required(self): checks = self._get_configured_checks() check = checks.get("octoprint", None) checkout_folder = self._get_octoprint_checkout_folder(checks=checks) - return ( - check - and "method" in check - and check["method"] == "update_script" - and not checkout_folder - ) + return check and check.get("method") == "update_script" and not checkout_folder + + def is_wizard_required(self): + return self._is_wizard_update_required() or self._is_settings_wizard_required() + + def get_wizard_version(self): + return 1 ##~~ EventHandlerPlugin API @@ -1264,6 +1475,8 @@ class SoftwareUpdatePlugin( if check_targets is None: check_targets = list(checks.keys()) + # TODO: caching doesn't take check_targets into account! + update_available = False update_possible = False information = {} @@ -1360,28 +1573,9 @@ class SoftwareUpdatePlugin( local_name = target_information["local"]["name"] local_value = target_information["local"]["value"] - release_notes = None - if ( - target_information - and target_information["remote"] - and target_information["remote"]["value"] - ): - if ( - "release_notes" in populated_check - and populated_check["release_notes"] - ): - release_notes = populated_check["release_notes"] - elif "release_notes" in target_information["remote"]: - release_notes = target_information["remote"][ - "release_notes" - ] - - if release_notes: - release_notes = release_notes.format( - octoprint_version=VERSION, - target_name=target_information["remote"]["name"], - target_version=target_information["remote"]["value"], - ) + release_notes = self._get_release_notes( + target_information, populated_check + ) information[target] = { "updateAvailable": target_update_available, @@ -1450,6 +1644,24 @@ class SoftwareUpdatePlugin( return information, update_available, update_possible + def _get_release_notes(self, information, populated_check): + release_notes = None + + if information and information["remote"] and information["remote"]["value"]: + if populated_check.get("release_notes"): + release_notes = populated_check["release_notes"] + elif "release_notes" in information["remote"]: + release_notes = information["remote"]["release_notes"] + + if release_notes: + release_notes = release_notes.format( + octoprint_version=VERSION, + target_name=information["remote"]["name"], + target_version=information["remote"]["value"], + ) + + return release_notes + def _get_check_hash(self, check): def dict_to_sorted_repr(d): lines = [] @@ -1690,6 +1902,9 @@ class SoftwareUpdatePlugin( # we might have needed to update the config, so we'll save that now self._settings.save() + # we also need to save our update log changes + self._save_update_log() + # also, we are now longer updating self._update_in_progress = False @@ -1743,8 +1958,22 @@ class SoftwareUpdatePlugin( information, update_available, update_possible, _, _ = self._get_current_version( target, check, online=online, credentials=credentials ) + populated_check = self._populated_check(target, check) + + def add_update_log(success, text): + self._add_update_log_entry( + target, + information["local"]["value"], + information["remote"]["value"], + success, + text, + display_name=populated_check["displayName"], + release_notes=self._get_release_notes(information, populated_check), + save=False, + ) if not update_available and not force: + add_update_log(False, "Target is already up to date") return False, None if not update_possible: @@ -1753,6 +1982,7 @@ class SoftwareUpdatePlugin( target ) ) + add_update_log(False, "Update not possible, missing information") return False, None if not information.get("compatible", True): @@ -1761,6 +1991,7 @@ class SoftwareUpdatePlugin( target ) ) + add_update_log(False, "Update is incompatible") return False, None # determine the target version to update to @@ -1791,7 +2022,6 @@ class SoftwareUpdatePlugin( ### The actual update procedure starts here... - populated_check = self._populated_check(target, check) try: self._logger.info(f"Starting update of {target} to {target_version}...") self._send_client_message( @@ -1826,6 +2056,7 @@ class SoftwareUpdatePlugin( "reason": "Unknown update type", }, ) + add_update_log(False, "Update failed, unknown update type") return False, None except exceptions.CannotUpdateOffline: @@ -1842,6 +2073,8 @@ class SoftwareUpdatePlugin( "reason": "No internet connection", }, ) + add_update_log(False, "No internet connection") + return False, None except Exception as e: self._logger.exception( @@ -1875,6 +2108,7 @@ class SoftwareUpdatePlugin( "reason": "unknown", }, ) + add_update_log(False, "Update failed") else: # make sure that any external changes to config.yaml are loaded into the system @@ -1886,6 +2120,8 @@ class SoftwareUpdatePlugin( del self._version_cache[target] self._version_cache_dirty = True + add_update_log(True, "Update successful") + return target_error, target_result def _persist_check_current(self, target, check, current): @@ -2189,4 +2425,5 @@ def __plugin_load__(): "octoprint.cli.commands": cli.commands, "octoprint.events.register_custom_events": _register_custom_events, "octoprint.access.permissions": __plugin_implementation__.get_additional_permissions, + "octoprint.systeminfo.additional_bundle_files": __plugin_implementation__.get_additional_bundle_files, } diff --git a/src/octoprint/plugins/softwareupdate/static/clientjs/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/clientjs/softwareupdate.js index 94e3d5feb..e4bf77a80 100644 --- a/src/octoprint/plugins/softwareupdate/static/clientjs/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/clientjs/softwareupdate.js @@ -12,6 +12,7 @@ this.checkUrl = url + "check"; this.updateUrl = url + "update"; this.configureUrl = url + "configure"; + this.updatelogUrl = url + "updatelog"; }; OctoPrintSoftwareUpdateClient.prototype.checkEntries = function ( @@ -88,6 +89,10 @@ return this.base.postJson(this.configureUrl, data, opts); }; + OctoPrintSoftwareUpdateClient.prototype.getUpdatelog = function (opts) { + return this.base.get(this.updatelogUrl, opts); + }; + OctoPrintClient.registerPluginComponent( "softwareupdate", OctoPrintSoftwareUpdateClient diff --git a/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css b/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css index 5ab41874e..c159b5570 100644 --- a/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css +++ b/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css @@ -1 +1 @@ -#settings_plugin_softwareupdate_updatelist{display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em}div.swupdate-advanced{margin-bottom:5px}td.settings_plugin_softwareupdate_column_update{width:16px}td.settings_plugin_softwareupdate_column_update a{text-decoration:none;color:#000}td.settings_plugin_softwareupdate_column_information .line{display:block}td.settings_plugin_softwareupdate_column_information .settings_plugin_softwareupdate_release_channel{line-height:20px;height:20px;font-size:9px;margin-bottom:0;vertical-align:baseline}#settings_plugin_softwareupdate_workingdialog_output{font-size:.8em}#settings_plugin_softwareupdate_workingdialog_output .message{font-weight:700}#settings_plugin_softwareupdate_workingdialog_output .separator{font-weight:700;color:#666}#settings_plugin_softwareupdate_workingdialog_output .stdout{color:#333}#settings_plugin_softwareupdate_workingdialog_output .stderr{color:#900}#settings_plugin_softwareupdate_workingdialog_output .call{color:#009}#settings_plugin_softwareupdate_workingdialog_output .message_error{font-weight:700;color:#900}.softwareupdate_notification ul{margin:10px 0 10px 25px}.softwareupdate_notification ul .name{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:block} \ No newline at end of file +#settings_plugin_softwareupdate_updatelist{display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em}div.swupdate-advanced{margin-bottom:5px}td.settings_plugin_softwareupdate_column_update{width:16px}td.settings_plugin_softwareupdate_column_update a{text-decoration:none;color:#000}td.settings_plugin_softwareupdate_column_information .line{display:block}td.settings_plugin_softwareupdate_column_information .settings_plugin_softwareupdate_release_channel{line-height:20px;height:20px;font-size:9px;margin-bottom:0;vertical-align:baseline}#settings_plugin_softwareupdate_updatelog_list .line{display:block}#settings_plugin_softwareupdate_updatelog_list td.settings_plugin_softwareupdate_column_datetime{width:150px}#settings_plugin_softwareupdate_workingdialog_output{font-size:.8em}#settings_plugin_softwareupdate_workingdialog_output .message{font-weight:700}#settings_plugin_softwareupdate_workingdialog_output .separator{font-weight:700;color:#666}#settings_plugin_softwareupdate_workingdialog_output .stdout{color:#333}#settings_plugin_softwareupdate_workingdialog_output .stderr{color:#900}#settings_plugin_softwareupdate_workingdialog_output .call{color:#009}#settings_plugin_softwareupdate_workingdialog_output .message_error{font-weight:700;color:#900}.softwareupdate_notification ul{margin:10px 0 10px 25px}.softwareupdate_notification ul .name{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:block} \ No newline at end of file diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index ebad30908..11eee8226 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -131,6 +131,14 @@ $(function () { 0 ); + self.octoprintData = { + item: undefined, + current: ko.observable("unknown"), + available: ko.observable("unknown") + }; + + self.updatelog = ko.observableArray([]); + self.availableAndPossible = ko.pureComputed(function () { return _.filter(self.versions.items(), function (info) { return info.updateAvailable && info.updatePossible; @@ -161,6 +169,10 @@ $(function () { } else { self._closePopup(); } + + if (self.loginState.hasPermission(self.access.permissions.ADMIN)) { + self.requestUpdatelog(); + } }; self._showPopup = function (options, eventListeners, singleButtonNotify) { @@ -356,6 +368,12 @@ $(function () { }); }; + if (key === "octoprint") { + self.octoprintData.item = value; + self.octoprintData.current(value.information.local.name); + self.octoprintData.available(value.information.remote.name); + } + versions.push(value); }); self.versions.updateItems(versions); @@ -556,6 +574,16 @@ $(function () { }); }; + self.fromUpdatelogResponse = function (response) { + self.updatelog(response.updatelog); + }; + + self.requestUpdatelog = function () { + OctoPrint.plugins.softwareupdate + .getUpdatelog() + .done(self.fromUpdatelogResponse); + }; + self.iconTitleForEntry = function (data) { if (data.updatePossible) { return ""; @@ -656,8 +684,10 @@ $(function () { self.performUpdate = function (force, items) { if ( - !self.loginState.hasPermission( - self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE + !( + self.loginState.hasPermission( + self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE + ) || CONFIG_FIRST_RUN ) ) return; @@ -720,8 +750,10 @@ $(function () { self.update = function (force, items) { if ( self.updateInProgress || - !self.loginState.hasPermission( - self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE + !( + self.loginState.hasPermission( + self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE + ) || CONFIG_FIRST_RUN ) ) { self._updateClicked = false; @@ -1139,7 +1171,8 @@ $(function () { elements: [ "#settings_plugin_softwareupdate", "#softwareupdate_confirmation_dialog", - "#wizard_plugin_softwareupdate" + "#wizard_plugin_softwareupdate_update", + "#wizard_plugin_softwareupdate_settings" ] }); }); diff --git a/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less b/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less index 76545f2ba..28a6d98bf 100644 --- a/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less +++ b/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less @@ -33,6 +33,16 @@ td.settings_plugin_softwareupdate_column_information { } } +#settings_plugin_softwareupdate_updatelog_list { + .line { + display: block; + } + + td.settings_plugin_softwareupdate_column_datetime { + width: 150px; + } +} + #settings_plugin_softwareupdate_workingdialog_output { font-size: 0.8em; diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index 1dd4cf8e3..0efe80cfd 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -73,52 +73,83 @@
{% endtrans %} -| + + + | +
+ {{ _('Update') }}
+ : + + {{ _('Release Channel:') }} + {{ _('Installed:') }} + {{ _('Available:') }} + {{ _('Release Notes:') }} + + + + {{ _('Newer versions of this plugin are not compatible to this setup.') }} + + |
+
| + | + ➡ + + {{ _('Release Notes') }} + | +
| - - - | -
- {{ _('Update') }}
- : - - {{ _('Release Channel:') }} - {{ _('Installed:') }} - {{ _('Available:') }} - {{ _('Release Notes:') }} - - - - {{ _('Newer versions of this plugin are not compatible to this setup.') }} - - |
-