From d538b3fd38394b3cb3d45bbdbbbbf5296229c37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 25 Aug 2016 15:45:25 +0200 Subject: [PATCH] Adjust swu plugin settings to selected update method --- .../plugins/softwareupdate/__init__.py | 52 +++++++++++++++---- .../static/js/softwareupdate.js | 20 ++++--- .../templates/softwareupdate_settings.jinja2 | 6 +-- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 137b9bc4..7b0dcd55 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -189,6 +189,11 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, data["octoprint_checkout_folder"] = None data["octoprint_type"] = checks["octoprint"].get("type", None) + try: + data["octoprint_method"] = self._get_update_method("octoprint", checks["octoprint"]) + except exceptions.UnknownUpdateType: + data["octoprint_method"] = "unknown" + data["octoprint_release_channel"] = self._settings.get(["octoprint_stable_branch", "branch"]) if checks["octoprint"].get("prerelease", False): channel = checks["octoprint"].get("prerelease_channel", BRANCH) @@ -774,6 +779,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, else: result["current"] = check.get("current", check.get("displayVersion", None)) + if "pip" in result: + if not "pip_command" in check and self._settings.get(["pip_command"]) is not None: + result["pip_command"] = self._settings.get(["pip_command"]) + return result def _get_version_checker(self, target, check): @@ -799,22 +808,45 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, else: raise exceptions.UnknownCheckType() + def _get_update_method(self, target, check, valid_methods=None): + """ + Determines the update method for the given target and check. + + If ``valid_methods`` is provided, determine method must be contained + therein to be considered valid. + + Raises an ``UnknownUpdateType`` exception if method cannot be determined + or validated. + """ + + method = None + if "method" in check: + method = check["method"] + else: + if "update_script" in check: + method = "update_script" + elif "pip" in check: + method = "pip" + elif "python_updater" in check: + method = "python_updated" + + if method is None or (valid_methods and not method in valid_methods): + raise exceptions.UnknownUpdateType() + + return method + def _get_updater(self, target, check): """ Retrieves the updater for the given target and check configuration. Will raise an UnknownUpdateType if updater cannot be determined. """ - if "update_script" in check: - return updaters.update_script - elif "pip" in check: - if not "pip_command" in check and self._settings.get(["pip_command"]) is not None: - check["pip_command"] = self._settings.get(["pip_command"]) - return updaters.pip - elif "python_updater" in check: - return updaters.python_updater - else: - raise exceptions.UnknownUpdateType() + mapping = dict(update_script=updaters.update_script, + pip=updaters.pip, + python_updater=updaters.python_updater) + + method = self._get_update_method(target, check, valid_methods=mapping.keys()) + return mapping[method] __plugin_name__ = "Software Update" __plugin_author__ = "Gina Häußge" diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 142ae8f8..4bbc86ae 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -21,15 +21,13 @@ $(function() { self.config_cacheTtl = ko.observable(); self.config_checkoutFolder = ko.observable(); self.config_checkType = ko.observable(); + self.config_updateMethod = ko.observable(); self.config_releaseChannel = ko.observable(); self.configurationDialog = $("#settings_plugin_softwareupdate_configurationdialog"); self.confirmationDialog = $("#softwareupdate_confirmation_dialog"); - self.config_availableCheckTypes = [ - {"key": "github_release", "name": gettext("Release")}, - {"key": "git_commit", "name": gettext("Commit")} - ]; + self.config_availableCheckTypes = ko.observableArray([]); self.config_availableReleaseChannels = ko.observableArray([]); self.reloadOverlay = $("#reloadui_overlay"); @@ -112,18 +110,28 @@ $(function() { }; self._copyConfig = function() { + var updateMethod = self.settings.settings.plugins.softwareupdate.octoprint_method(); + + var availableCheckTypes = []; + if (updateMethod == "update_script" || updateMethod == "python") { + availableCheckTypes = [{"key": "github_release", "name": gettext("Release")}, + {"key": "git_commit", "name": gettext("Commit")}]; + } else { + availableCheckTypes = []; + } + self.config_availableCheckTypes(availableCheckTypes); + var availableReleaseChannels = []; _.each(self.settings.settings.plugins.softwareupdate.octoprint_branch_mappings(), function(mapping) { availableReleaseChannels.push({"key": mapping.branch(), "name": gettext(mapping.name() || mapping.branch())}); }); self.config_availableReleaseChannels(availableReleaseChannels); + self.config_updateMethod(updateMethod); self.config_cacheTtl(self.settings.settings.plugins.softwareupdate.cache_ttl()); self.config_checkoutFolder(self.settings.settings.plugins.softwareupdate.octoprint_checkout_folder()); self.config_checkType(self.settings.settings.plugins.softwareupdate.octoprint_type()); self.config_releaseChannel(self.settings.settings.plugins.softwareupdate.octoprint_release_channel()); - - log.info("releaseChannel:", self.config_releaseChannel(), ", availableReleaseChannels:", availableReleaseChannels); }; self.fromCheckResponse = function(data, ignoreSeen, showIfNothingNew) { diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index 3c3f18bf..fc90e531 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -74,19 +74,19 @@