Fix: More flexibility when parsing plugin compatibility

If compatibility information is provided only as a version number it's
prefixed with >= for the check (so stating a compatibility of only
1.2.0 will now make the plugin compatible to all versions that follow
too).

Alternatively the compatibility information may now contain stuff like
">=1.2,<1.3" in which case the plugin will only be shown as compatible
to OctoPrint versions 1.2 and up but not 1.3 or anything above that.
This commit is contained in:
Gina Häußge 2015-06-29 10:13:44 +02:00
parent 9caf13d620
commit d5692d797d

View file

@ -510,22 +510,46 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
if "compatibility" in entry: if "compatibility" in entry:
if "octoprint" in entry["compatibility"] and entry["compatibility"]["octoprint"] is not None and len(entry["compatibility"]["octoprint"]): if "octoprint" in entry["compatibility"] and entry["compatibility"]["octoprint"] is not None and len(entry["compatibility"]["octoprint"]):
import semantic_version result["is_compatible"]["octoprint"] = self._is_octoprint_compatible(octoprint_version, entry["compatibility"]["octoprint"])
for octo_compat in entry["compatibility"]["octoprint"]:
s = semantic_version.Spec("=={}".format(octo_compat))
if semantic_version.Version(octoprint_version) in s:
break
else:
result["is_compatible"]["octoprint"] = False
if "os" in entry["compatibility"] and entry["compatibility"]["os"] is not None and len(entry["compatibility"]["os"]): if "os" in entry["compatibility"] and entry["compatibility"]["os"] is not None and len(entry["compatibility"]["os"]):
result["is_compatible"]["os"] = current_os in entry["compatibility"]["os"] result["is_compatible"]["os"] = self._is_os_compatible(current_os, entry["compatibility"]["os"])
return result return result
self._repository_plugins = map(map_repository_entry, repo_data) self._repository_plugins = map(map_repository_entry, repo_data)
return True return True
def _is_octoprint_compatible(self, octoprint_version, compatibility_entries):
"""
Tests if the current ``octoprint_version`` is compatible to any of the provided ``compatibility_entries``.
"""
import semantic_version
for octo_compat in compatibility_entries:
for version_string in (octo_compat, ">={}".format(octo_compat)):
try:
s = semantic_version.Spec(version_string)
if semantic_version.Version(octoprint_version) in s:
break
except ValueError:
# that just means that octo_compat directly wasn't a valid version spec string, so we try
# prefixing that with ">=" next and check again
pass
else:
continue
break
else:
return False
return True
def _is_os_compatible(self, current_os, compatibility_entries):
"""
Tests if the ``current_os`` matches any of the provided ``compatibility_entries``.
"""
return current_os in compatibility_entries
def _get_os(self): def _get_os(self):
if sys.platform == "win32": if sys.platform == "win32":
return "windows" return "windows"