diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 49b92a7ec..38279bee3 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -352,6 +352,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, data["octoprint_type"] = None data["octoprint_branch_mappings"] = [] + data["pip_enable_check"] = "pip" in checks + return data def on_settings_save(self, data): @@ -377,6 +379,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, ) updated_octoprint_check_config = False + update_pip_check_config = False if "octoprint_checkout_folder" in data: self._settings.set(["checks", "octoprint", "checkout_folder"], data["octoprint_checkout_folder"], defaults=defaults, force=True) @@ -421,6 +424,18 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._settings.set(["checks", "octoprint", "prerelease_channel"], None, defaults=defaults, force=True) updated_octoprint_check_config = True + if "pip_enable_check" in data: + checks = self._settings.get(["checks"], merged=True) + if data["pip_enable_check"] in octoprint.settings.valid_boolean_trues: + checks["pip"] = dict(type="pypi_release", + package="pip", + pip="pip=={target_version}") + elif "pip" in checks: + del checks["pip"] + self._settings.set(["checks"], checks, force=True) + self._settings.save() + update_pip_check_config = True + if updated_octoprint_check_config: self._refresh_configured_checks = True try: @@ -429,6 +444,14 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, pass self._version_cache_dirty = True + if update_pip_check_config: + self._refresh_configured_checks = True + try: + del self._version_cache["pip"] + except KeyError: + pass + self._version_cache_dirty = True + def get_settings_version(self): return 6 @@ -903,6 +926,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, to_be_updated.remove("octoprint") tmp = ["octoprint"] + to_be_updated to_be_updated = tmp + if "pip" in to_be_updated: + to_be_updated.remove("pip") + tmp = ["pip"] + to_be_updated + to_be_updated = tmp updater_thread = threading.Thread(target=self._update_worker, args=(populated_checks, to_be_updated, force)) updater_thread.daemon = False @@ -941,7 +968,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, if "restart" in check: target_restart_type = check["restart"] - elif "pip" in check: + elif "pip" in check and target != "pip": target_restart_type = "octoprint" else: target_restart_type = None @@ -1095,13 +1122,14 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, raise exceptions.RestartFailed() def _populated_check(self, target, check): + from flask_babel import gettext + if not "type" in check: raise exceptions.UnknownCheckType() result = dict(check) if target == "octoprint": - from flask_babel import gettext from octoprint.util.version import is_released_octoprint_version, is_stable_octoprint_version @@ -1160,6 +1188,23 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, # we force python unequality check for pip installs, to be able to downgrade result["release_compare"] = "python_unequal" + elif target == "pip": + import pkg_resources + + displayName = check.get("displayName") + if displayName is None: + # displayName missing or set to None + displayName = gettext("pip") + result["displayName"] = to_unicode(displayName, errors="replace") + + displayVersion = check.get("displayVersion") + if displayVersion is None: + # displayVersion missing or set to None + distribution = pkg_resources.get_distribution("pip") + if distribution: + displayVersion = distribution.version + result["displayVersion"] = to_unicode(displayVersion, errors="replace") + else: result["displayName"] = to_unicode(check.get("displayName"), errors="replace") if result["displayName"] is None: diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 8e96865b6..d9057556d 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -53,6 +53,7 @@ $(function() { self.config_pipTarget = ko.observable(); self.config_checkType = ko.observable(); self.config_releaseChannel = ko.observable(); + self.config_pipEnableCheck = ko.observable(); self.error_checkoutFolder = ko.pureComputed(function() { return self.config_checkType() === "git_commit" @@ -164,7 +165,8 @@ $(function() { octoprint_release_channel: self.config_releaseChannel(), octoprint_checkout_folder: self.config_checkoutFolder(), octoprint_tracked_branch: self.config_trackedBranch(), - octoprint_pip_target: self.config_pipTarget() + octoprint_pip_target: self.config_pipTarget(), + pip_enable_check: self.config_pipEnableCheck() } } }; @@ -201,6 +203,8 @@ $(function() { self.config_checkoutFolder(self.settings.settings.plugins.softwareupdate.octoprint_checkout_folder()); self.config_trackedBranch(self.settings.settings.plugins.softwareupdate.octoprint_tracked_branch()); self.config_pipTarget(self.settings.settings.plugins.softwareupdate.octoprint_pip_target()); + + self.config_pipEnableCheck(self.settings.settings.plugins.softwareupdate.pip_enable_check()); }; self._copyConfigBack = function() { diff --git a/src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/pipEnableCheck.jinja2 b/src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/pipEnableCheck.jinja2 new file mode 100644 index 000000000..100791318 --- /dev/null +++ b/src/octoprint/plugins/softwareupdate/templates/snippets/plugins/softwareupdate/pipEnableCheck.jinja2 @@ -0,0 +1,8 @@ +