diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 87c1909ca..f2e0de500 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -26,7 +26,7 @@ from . import version_checks, updaters, exceptions, util, cli from flask_babel import gettext from octoprint.server.util.flask import no_firstrun_access, with_revalidation_checking, check_etag -from octoprint.server import VERSION, REVISION, BRANCH +from octoprint.server import VERSION, REVISION, BRANCH, NO_CONTENT from octoprint.access import USER_GROUP, ADMIN_GROUP from octoprint.access.permissions import Permissions from octoprint.util import dict_merge, to_unicode, get_formatted_size @@ -114,6 +114,12 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, description=gettext("Allows to perform software updates"), default_groups=[ADMIN_GROUP], roles=["update"], + dangerous=True), + dict(key="CONFIGURE", + name="Configure", + description=gettext("Allows to configure software update"), + default_groups=[ADMIN_GROUP], + roles=["configure"], dangerous=True) ] @@ -200,7 +206,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, plugin_and_not_enabled = lambda k: k in check_providers and \ not check_providers[k] in self._plugin_manager.enabled_plugins obsolete_plugin_checks = list(filter(plugin_and_not_enabled, - config_checks.keys())) + config_checks.keys())) for key in obsolete_plugin_checks: self._logger.debug("Check for key {} was provided by plugin {} that's no longer available, ignoring it".format(key, check_providers[key])) del self._configured_checks[key] @@ -314,6 +320,14 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._version_cache_timestamp = time.time() self._logger.info("Saved version cache to disk") + def _invalidate_version_cache(self, target): + self._refresh_configured_checks = True + try: + del self._version_cache[target] + except KeyError: + pass + self._version_cache_dirty = True + #~~ SettingsPlugin API def get_settings_defaults(self): @@ -481,23 +495,13 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, update_pip_check_config = True if updated_octoprint_check_config: - self._refresh_configured_checks = True - try: - del self._version_cache["octoprint"] - except KeyError: - pass - self._version_cache_dirty = True + self._invalidate_version_cache("octoprint") if update_pip_check_config: - self._refresh_configured_checks = True - try: - del self._version_cache["pip"] - except KeyError: - pass - self._version_cache_dirty = True + self._invalidate_version_cache("pip") def get_settings_version(self): - return 8 + return 9 def on_settings_migrate(self, target, current=None): @@ -753,6 +757,57 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, to_be_checked, checks = self.perform_updates(targets=targets, force=force) return flask.jsonify(dict(order=to_be_checked, checks=checks)) + @octoprint.plugin.BlueprintPlugin.route("/configure", methods=["POST"]) + @no_firstrun_access + @Permissions.PLUGIN_SOFTWAREUPDATE_CONFIGURE.require(403) + def configure_update(self): + json_data = flask.request.get_json(silent=True) + if json_data is None: + return flask.make_response("Invalid JSON", 400) + + checks = self._get_configured_checks() + + settings_dirty = False + for target, data in json_data.items(): + if not target in checks: + continue + + try: + populated_check = self._populated_check(target, checks[target]) + except exceptions.UnknownCheckType: + self._logger.debug("Ignoring unknown check type for target {}".format(target)) + continue + except Exception: + self._logger.exception("Error while populating check prior to configuration for target {}".format(target)) + continue + + patch = dict() + + # switched release channel + if "channel" in data: + if populated_check["type"] == "github_release" and "stable_branch" in populated_check and "prerelease_branches" in populated_check: + valid_channel = data["channel"] == populated_check["stable_branch"].get("branch") \ + or any(map(lambda x: data["channel"] == x.get("branch"), populated_check["prerelease_branches"])) + prerelease = data["channel"] != populated_check["stable_branch"].get("branch") + + if valid_channel: + patch["prerelease"] = prerelease + patch["prerelease_channel"] = data["channel"] + + # do we have changes to apply? + if patch: + current = self._settings.get(["checks", target], incl_defaults=False) + updated = dict_merge(current, patch) + self._settings.set(["checks", target], updated) + + settings_dirty = True + self._invalidate_version_cache(target) + + if settings_dirty: + self._settings.save() + + return NO_CONTENT + def is_blueprint_protected(self): return False @@ -884,10 +939,26 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, local_value=local_value), releaseNotes=release_notes, online=target_online, - error=target_error) + error=target_error, + releaseChannels=dict()) - if target == "octoprint" and "released_version" in populated_check: - information[target]["released_version"] = populated_check["released_version"] + if populated_check["type"] == "github_release" and "stable_branch" in populated_check and "prerelease_branches" in populated_check: + # target supports release channels via github branches and releases + def to_release_channel(branch_info): + return dict(name=branch_info["name"], + channel=branch_info["branch"]) + + stable_channel = populated_check["stable_branch"]["branch"] + current_channel = populated_check.get("prerelease_channel") + release_channels = [to_release_channel(populated_check["stable_branch"]),] + \ + list(map(to_release_channel, + populated_check["prerelease_branches"])) + information[target]["releaseChannels"] = dict(available=release_channels, + current=current_channel if current_channel else stable_channel, + stable=stable_channel) + + if "released_version" in populated_check: + information[target]["releasedVersion"] = populated_check["released_version"] if self._version_cache_dirty: self._save_version_cache() diff --git a/src/octoprint/plugins/softwareupdate/static/clientjs/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/clientjs/softwareupdate.js index 932dcf8ce..43635e90f 100644 --- a/src/octoprint/plugins/softwareupdate/static/clientjs/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/clientjs/softwareupdate.js @@ -11,6 +11,7 @@ var url = this.base.getBlueprintUrl("softwareupdate"); this.checkUrl = url + "check"; this.updateUrl = url + "update"; + this.configureUrl = url + "configure"; }; OctoPrintSoftwareUpdateClient.prototype.checkEntries = function(entries, force, opts) { @@ -79,6 +80,10 @@ return this.base.postJson(this.updateUrl, data, opts); }; + OctoPrintSoftwareUpdateClient.prototype.configure = function(data, opts) { + return this.base.postJson(this.configureUrl, data, opts); + } + OctoPrintClient.registerPluginComponent("softwareupdate", OctoPrintSoftwareUpdateClient); return OctoPrintSoftwareUpdateClient; }); diff --git a/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css b/src/octoprint/plugins/softwareupdate/static/css/softwareupdate.css index bab0b6b7b..622c64131 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;max-height:500px;overflow-x:hidden;overflow-y:scroll;padding-right:2px;margin-bottom:1em}td.settings_plugin_softwareupdate_column_update{width:16px}td.settings_plugin_softwareupdate_column_information .line{display:block}#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;max-height:500px;overflow-x:hidden;overflow-y:scroll;padding-right:2px;margin-bottom:1em}td.settings_plugin_softwareupdate_column_update{width:16px}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 diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index da81c859f..5d4752535 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -245,12 +245,24 @@ $(function() { } 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]); + }); + }) + } + versions.push(value); }); self.versions.updateItems(versions); var octoprint = data.information["octoprint"]; - self.octoprintReleasedVersion(!octoprint || octoprint.released_version); + self.octoprintReleasedVersion(!octoprint || octoprint.releasedVersion); self.environmentSupported(data.environment.supported); self.environmentVersions(data.environment.versions); @@ -362,9 +374,9 @@ $(function() { } }; - self.performCheck = function(showIfNothingNew, force, ignoreSeen) { + self.performCheck = function(showIfNothingNew, force, ignoreSeen, entries) { self.checking(true); - OctoPrint.plugins.softwareupdate.check(force) + OctoPrint.plugins.softwareupdate.check({entries: entries, force: force}) .done(function(data) { self.fromCheckResponse(data, ignoreSeen, showIfNothingNew); }) diff --git a/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less b/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less index 950b0e495..4279dd23f 100644 --- a/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less +++ b/src/octoprint/plugins/softwareupdate/static/less/softwareupdate.less @@ -16,6 +16,14 @@ td.settings_plugin_softwareupdate_column_information { .line { display: block; } + + .settings_plugin_softwareupdate_release_channel { + line-height: 20px; + height: 20px; + font-size: 9px; + margin-bottom: 0; + vertical-align: baseline; + } } #settings_plugin_softwareupdate_workingdialog_output { diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index 63996cb8f..2191eac07 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -87,6 +87,7 @@ {{ _('Update') }} :
+ {{ _('Release Channel:') }} {{ _('Installed:') }} {{ _('Available:') }} {{ _('Release Notes:') }} @@ -120,7 +121,6 @@ {% include "snippets/plugins/softwareupdate/versionTracking.jinja2" %} {% include "snippets/plugins/softwareupdate/trackedBranch.jinja2" %} {% include "snippets/plugins/softwareupdate/checkoutFolder.jinja2" %} - {% include "snippets/plugins/softwareupdate/releaseChannel.jinja2" %} {% include "snippets/plugins/softwareupdate/pipTarget.jinja2" %} {% include "snippets/plugins/softwareupdate/pipEnableCheck.jinja2" %}
diff --git a/src/octoprint/plugins/softwareupdate/version_checks/github_release.py b/src/octoprint/plugins/softwareupdate/version_checks/github_release.py index 782758340..429ef454a 100644 --- a/src/octoprint/plugins/softwareupdate/version_checks/github_release.py +++ b/src/octoprint/plugins/softwareupdate/version_checks/github_release.py @@ -270,7 +270,7 @@ def get_latest(target, check, custom_compare=None, online=True): # determine valid "commitish" values in case we track prereleases commitish = None - if prerelease_channel: + if include_prerelease and prerelease_channel: prerelease_branches = check.get("prerelease_branches", None) if prerelease_branches: # fetch valid commitish list from configured prerelease_branches for selected channel