From a8747f7e36a03ff2449b62cdf68b8a26a6fa61b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 8 Dec 2017 15:09:58 +0100 Subject: [PATCH] Fix a bug with release vs dev version detection --- CHANGELOG.md | 1 + .../plugins/softwareupdate/__init__.py | 22 +++---- src/octoprint/util/version.py | 57 +++++++++++++++++++ 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 331d2712..5cc1e5d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bug fixes * Fixed an issue causing redundant software update configuration settings to be written to `config.yaml`, in turn causing issues when downgrading to <1.3.5 + * Fixed an issue detecting whether the installed version is a release version or a development version. ([Commits](https://github.com/foosel/OctoPrint/compare/1.3.6rc2...1.3.6rc3)) diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 6d91000a..ffb2f583 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -973,6 +973,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, if target == "octoprint": from flask.ext.babel import gettext + from octoprint.util.version import is_released_octoprint_version, is_stable_octoprint_version + result["displayName"] = to_unicode(check.get("displayName"), errors="replace") if result["displayName"] is None: # displayName missing or set to None @@ -990,16 +992,16 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, stable_branch = check["stable_branch"]["branch"] if "prerelease_branches" in check: release_branches += [x["branch"] for x in check["prerelease_branches"]] - result["released_version"] = not release_branches or BRANCH in release_branches + result["released_version"] = is_released_octoprint_version() if check["type"] in self.COMMIT_TRACKING_TYPES: result["current"] = REVISION if REVISION else "unknown" else: result["current"] = VERSION - if check["type"] == "github_release" and (check.get("prerelease", None) or BRANCH != stable_branch): - # we are tracking github releases and are either also tracking prerelease OR are currently installed - # from something that is not the stable (master) branch => we need to change some parameters + if check["type"] == "github_release" and (check.get("prerelease", None) or not is_stable_octoprint_version()): + # we are tracking github releases and are either also tracking prerelease OR are currently running + # a non stable version => we need to change some parameters # we compare versions fully, not just the base so that we see a difference # between RCs + stable for the same version release @@ -1019,17 +1021,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, result["update_branch"] = check.get("update_branch", stable_branch) if check.get("update_script", None): - # we force an exact version + # we force an exact version & python unequality check, to be able to downgrade result["force_exact_version"] = True - - if BRANCH != result.get("prerelease_channel"): - # we force python unequality check here because that will also allow us to - # downgrade on a prerelease channel change (rc/devel => rc/maintenance) - # - # we detect channel changes by comparing the current branch with the target - # branch of the release channel - unequality means we might have to handle - # a downgrade - result["release_compare"] = "python_unequal" + result["release_compare"] = "python_unequal" elif check.get("pip", None): # we force python unequality check for pip installs, to be able to downgrade diff --git a/src/octoprint/util/version.py b/src/octoprint/util/version.py index 3db67e15..58f8811c 100644 --- a/src/octoprint/util/version.py +++ b/src/octoprint/util/version.py @@ -46,6 +46,63 @@ def get_octoprint_version(base=False): return octoprint_version +def is_released_octoprint_version(version=None): + """ + >>> import pkg_resources + >>> is_released_octoprint_version(version=pkg_resources.parse_version("1.3.6rc3")) + True + >>> is_released_octoprint_version(version=pkg_resources.parse_version("1.3.6rc3.dev2+g1234")) + False + >>> is_released_octoprint_version(version=pkg_resources.parse_version("1.3.6")) + True + >>> is_released_octoprint_version(version=pkg_resources.parse_version("1.3.6.post1+g1234")) + True + >>> is_released_octoprint_version(version=pkg_resources.parse_version("1.3.6.post1.dev0+g1234")) + False + >>> is_released_octoprint_version(version=pkg_resources.parse_version("1.3.7.dev123+g23545")) + False + """ + + if version is None: + version = get_octoprint_version() + + if isinstance(version, tuple): + # old setuptools + return "*@" not in version + else: + # new setuptools + return "dev" not in version.public + + +def is_stable_octoprint_version(version=None): + """ + >>> import pkg_resources + >>> is_stable_octoprint_version(version=pkg_resources.parse_version("1.3.6rc3")) + False + >>> is_stable_octoprint_version(version=pkg_resources.parse_version("1.3.6rc3.dev2+g1234")) + False + >>> is_stable_octoprint_version(version=pkg_resources.parse_version("1.3.6")) + True + >>> is_stable_octoprint_version(version=pkg_resources.parse_version("1.3.6.post1+g1234")) + True + >>> is_stable_octoprint_version(version=pkg_resources.parse_version("1.3.6.post1.dev0+g1234")) + False + >>> is_stable_octoprint_version(version=pkg_resources.parse_version("1.3.7.dev123+g23545")) + False + """ + + if version is None: + version = get_octoprint_version() + + if not is_released_octoprint_version(version=version): + return False + + if isinstance(version, tuple): + return "*a" not in version and "*b" not in version and "*c" not in version + else: + return not version.is_prerelease + + def is_octoprint_compatible(*compatibility_entries, **kwargs): """ Tests if the current ``octoprint_version`` is compatible to any of the provided ``compatibility_entries``.