✨ SWU: UI for release channels by plugins

This commit is contained in:
Gina Häußge committed 2020-09-17 15:23:11 +02:00
1 parent 64b57186da
commit cfb9c93e65
7 files changed
+120 -24

No files matched your search

@@ -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()
@@ -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;
});
@@ -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}
#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}
@@ -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);
})
@@ -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 {
@@ -87,6 +87,7 @@
<a href="javascript:void(0)" data-bind="click: function() { $root.update(false, [$data]) }, visible: $root.enableUpdate() && updateAvailable && updatePossible" class="btn btn-primary pull-right">{{ _('Update') }}</a>
<strong data-bind="text: displayName"></strong>: <span data-bind="text: displayVersion"></span> <span data-bind="invisible: updatePossible"><i class="fa fa-exclamation-triangle" data-bind="css: {'fa-unlink': !online && information && information.needs_online, 'fa-exclamation-triangle': !(!online && information && information.needs_online)}, attr: {title: $root.iconTitleForEntry($data)}"></i></span><br>
<small class="muted">
<span data-bind="visible: releaseChannels && releaseChannels.available" class="line">{{ _('Release Channel:') }} <select class="settings_plugin_softwareupdate_release_channel" data-bind="visible: releaseChannels && releaseChannels.available, value: releaseChannels.current, options: releaseChannels.available, optionsText: 'name', optionsValue: 'channel'"></select> <a href="https://faq.octoprint.org/using-release-channels" target="_blank"><i class="fa fa-question-circle"></i></a></span>
<span class="line">{{ _('Installed:') }} <span data-bind="text: information.local.name"></span></span>
<span class="line">{{ _('Available:') }} <span data-bind="text: information.remote.name"></span></span>
<span class="line" data-bind="visible: releaseNotes">{{ _('Release Notes:') }} <a data-bind="attr: {href: releaseNotes}, text: releaseNotes" target="_blank" rel="noreferrer noopener"></a></span>
@@ -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" %}
<div class="control-group">
@@ -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