PICARD-1756: Fix plugin update version comparison

Use Version class to implement version comparison. Fixes updater considering 1.10 < 1.9
This commit is contained in:
Philipp Wolfer
2020-02-20 20:02:15 +01:00
parent 265ed0775e
commit b40a3cb9cd
5 changed files with 31 additions and 15 deletions

View File

@@ -38,6 +38,7 @@ PICARD_BUILD_VERSION_STR = ""
def version_to_string(version, short=False):
"""Deprecated: Use picard.version.Version.to_string instead"""
if len(version) != 5:
raise VersionError("Length != 5")
if not isinstance(version, Version):

View File

@@ -27,6 +27,10 @@ from picard import (
log,
)
from picard.const import USER_PLUGIN_DIR
from picard.version import (
Version,
VersionError,
)
_PLUGIN_MODULE_PREFIX = "picard.plugins."
@@ -129,9 +133,9 @@ class PluginWrapper(PluginShared):
@property
def version(self):
try:
return self.data['PLUGIN_VERSION']
except KeyError:
return ""
return Version.from_string(self.data['PLUGIN_VERSION'])
except (KeyError, VersionError):
return Version(0, 0, 0)
@property
def api_versions(self):
@@ -186,6 +190,13 @@ class PluginData(PluginShared):
log.debug('Attribute %r not found for plugin %r', name, self.module_name)
return None
@property
def version(self):
try:
return Version.from_string(self.__dict__['version'])
except (KeyError, VersionError):
return Version(0, 0, 0)
@property
def files_list(self):
return ", ".join(self.files.keys())

View File

@@ -31,11 +31,7 @@ import zipimport
from PyQt5 import QtCore
from picard import (
VersionError,
log,
version_to_string,
)
from picard import log
from picard.const import (
PLUGINS_API,
USER_PLUGIN_DIR,
@@ -47,7 +43,10 @@ from picard.plugin import (
_unregister_module_extensions,
)
import picard.plugins
from picard.version import Version
from picard.version import (
Version,
VersionError,
)
_SUFFIXES = tuple(importlib.machinery.all_suffixes())
@@ -272,7 +271,7 @@ class PluginManager(QtCore.QObject):
log.debug("Loading plugin %r version %s, compatible with API: %s",
plugin.name,
plugin.version,
", ".join([version_to_string(v, short=True) for v in
", ".join([v.to_string(short=True) for v in
sorted(compatible_versions)]))
plugin.compatible = True
setattr(picard.plugins, name, plugin_module)

View File

@@ -130,7 +130,7 @@ class PluginTreeWidgetItem(HashableTreeWidgetItem):
button.hide()
else:
button.show()
button.setToolTip(_("Download and upgrade plugin to version %s") % self.new_version)
button.setToolTip(_("Download and upgrade plugin to version %s") % self.new_version.to_string(short=True))
self.set_icon(button, 'SP_BrowserReload')
def show_enable(self, button, mode):
@@ -319,7 +319,7 @@ class PluginsOptionsPage(OptionsPage):
new_version = None
if plugin.module_name in available_plugins:
latest = available_plugins[plugin.module_name]
if latest.split('.') > plugin.version.split('.'):
if latest > plugin.version:
new_version = latest
self.update_plugin_item(None, plugin,
enabled=self.is_plugin_enabled(plugin),
@@ -472,9 +472,10 @@ class PluginsOptionsPage(OptionsPage):
def update_text():
if item.new_version is not None:
version = "%s%s" % (plugin.version, item.new_version)
version = "%s%s" % (plugin.version.to_string(short=True),
item.new_version.to_string(short=True))
else:
version = plugin.version
version = plugin.version.to_string(short=True)
if item.installed_font is None:
item.installed_font = item.font(COLUMN_NAME)
@@ -561,7 +562,7 @@ class PluginsOptionsPage(OptionsPage):
return int(elem)
except ValueError:
return 0
item.setSortData(COLUMN_VERSION, tuple(v2int(e) for e in plugin.version.split('.')))
item.setSortData(COLUMN_VERSION, plugin.version)
return item

View File

@@ -116,6 +116,10 @@ class VersionsTest(PicardTestCase):
self.assertLess(v1, v2)
self.assertFalse(v2 < v2)
v1 = Version(2, 3, 0, 'final', 1)
v2 = Version(2, 10, 0, 'final', 1)
self.assertLess(v1, v2)
def test_le(self):
v1 = Version(2, 3, 0, 'dev', 1)
v2 = Version(2, 3, 0, 'alpha', 1)