diff --git a/lizmap/definitions/definitions.py b/lizmap/definitions/definitions.py index a8e58aae..50c6d991 100755 --- a/lizmap/definitions/definitions.py +++ b/lizmap/definitions/definitions.py @@ -7,6 +7,7 @@ from collections import namedtuple from enum import Enum, unique from functools import total_ordering +from typing import List from qgis.PyQt.QtCore import Qt @@ -27,7 +28,22 @@ class LwcVersions(Enum): def __lt__(self, other): if self.__class__ is other.__class__: - return self.value < other.value + return self.version_as_list(self.value) < self.version_as_list(other.value) + return NotImplemented + + def __ge__(self, other): + if self.__class__ is other.__class__: + return self.version_as_list(self.value) >= self.version_as_list(other.value) + return NotImplemented + + def __gt__(self, other): + if self.__class__ is other.__class__: + return self.version_as_list(self.value) > self.version_as_list(other.value) + return NotImplemented + + def __le__(self, other): + if self.__class__ is other.__class__: + return self.version_as_list(self.value) <= self.version_as_list(other.value) return NotImplemented @staticmethod @@ -49,8 +65,9 @@ def oldest(): @classmethod def find(cls, version_string: str, raise_exception: bool = False): """Return the LWC version for the given string.""" + branch = cls.branch_from_version(version_string) for lwc_version in cls.__members__.values(): - if version_string.startswith(lwc_version.value): + if branch == lwc_version.value: return lwc_version if raise_exception: @@ -64,6 +81,17 @@ def find(cls, version_string: str, raise_exception: bool = False): # It should be fixed ASAP. return LwcVersions.oldest() + @classmethod + def branch_from_version(cls, version_string: str) -> str: + """ Return the branch as a string from a version string. """ + split_version = version_string.split('.') + return f"{split_version[0]}.{split_version[1]}" + + @classmethod + def version_as_list(cls, version: str) -> List: + """ List from a version string. """ + return [int(v) for v in version.split(".")] + @classmethod def find_from_metadata(cls, metadata: dict): """ Return the release status from metadata. """ diff --git a/lizmap/dialogs/server_wizard.py b/lizmap/dialogs/server_wizard.py index 05839658..e8cd7136 100644 --- a/lizmap/dialogs/server_wizard.py +++ b/lizmap/dialogs/server_wizard.py @@ -44,7 +44,7 @@ ) from qgis.utils import OverrideCursor, iface -from lizmap.definitions.definitions import UNSTABLE_VERSION_PREFIX +from lizmap.definitions.definitions import UNSTABLE_VERSION_PREFIX, LwcVersions from lizmap.definitions.online_help import online_lwc_help from lizmap.definitions.qgis_settings import Settings from lizmap.logger import log_function @@ -1081,8 +1081,9 @@ def request_check_url(self, url: str, login: str, password: str) -> Tuple[bool, return False, tr('No "info" in the JSON document'), False lizmap_version = info.get('version') - if lizmap_version.startswith(('3.1', '3.2', '3.3', '3.4')): - # Wait for EOL QGIS 3.10 because linked to LWC 3.5 + branch = LwcVersions.branch_from_version(lizmap_version) + if branch in ('3.1', '3.2', '3.3', '3.4'): + # Wait for EOL QGIS_VERSION_INT 3.10 because linked to LWC 3.5 return True, '', True # For other versions, we continue to see the access diff --git a/lizmap/plugin.py b/lizmap/plugin.py index 4c8ed4c6..d7b31c76 100755 --- a/lizmap/plugin.py +++ b/lizmap/plugin.py @@ -227,6 +227,7 @@ def __init__(self, iface, lwc_version: LwcVersions = None): # Must only be used in tests # In production, version is coming from the UI, according to the current server selected + # In production, this variable must be None self._version = lwc_version # Keep it for a few months @@ -456,6 +457,10 @@ def write_log_message(message, tag, level): # Permalink, will be backported to 3.7, but wait a little before adding it to the 3.7 list self.dlg.automatic_permalink, ] + self.lwc_versions[LwcVersions.Lizmap_3_9] = [ + ] + self.lwc_versions[LwcVersions.Lizmap_3_10] = [ + ] self.lizmap_cloud = [ self.dlg.label_lizmap_search_grant, diff --git a/lizmap/table_manager/base.py b/lizmap/table_manager/base.py index fa5d66a2..c5e949cd 100755 --- a/lizmap/table_manager/base.py +++ b/lizmap/table_manager/base.py @@ -60,6 +60,8 @@ def __init__( self.lwc_versions.append(LwcVersions.Lizmap_3_6) self.lwc_versions.append(LwcVersions.Lizmap_3_7) self.lwc_versions.append(LwcVersions.Lizmap_3_8) + self.lwc_versions.append(LwcVersions.Lizmap_3_9) + self.lwc_versions.append(LwcVersions.Lizmap_3_10) self.keys = [i for i, j in self.definitions.layer_config.items() if j.get('plural') is None] self.table.setColumnCount(len(self.keys)) diff --git a/lizmap/test/test_definitions.py b/lizmap/test/test_definitions.py index a299ec45..7f50b45d 100644 --- a/lizmap/test/test_definitions.py +++ b/lizmap/test/test_definitions.py @@ -14,6 +14,8 @@ def test_lwc_version_string(self): self.assertEqual(LwcVersions.find('3.5.0'), LwcVersions.Lizmap_3_5) self.assertEqual(LwcVersions.find('3.5.2-pre'), LwcVersions.Lizmap_3_5) self.assertEqual(LwcVersions.find('3.5.2-pre.5204'), LwcVersions.Lizmap_3_5) + self.assertEqual(LwcVersions.find('3.1.0'), LwcVersions.Lizmap_3_1) + self.assertEqual(LwcVersions.find('3.10.0'), LwcVersions.Lizmap_3_10) # Check a non-existing release in Python source code # The release string can be provided the online JSON file @@ -33,13 +35,22 @@ def test_version_comparaison(self): self.assertTrue(LwcVersions.Lizmap_3_6 == LwcVersions.Lizmap_3_6) self.assertTrue(LwcVersions.Lizmap_3_6 != LwcVersions.Lizmap_3_5) - self.assertFalse(LwcVersions.Lizmap_3_4 > LwcVersions.Lizmap_3_5) - self.assertTrue(LwcVersions.Lizmap_3_6 >= LwcVersions.Lizmap_3_6) + self.assertTrue(LwcVersions.Lizmap_3_4 < LwcVersions.Lizmap_3_5) self.assertTrue(LwcVersions.Lizmap_3_6 > LwcVersions.Lizmap_3_5) - - self.assertTrue(LwcVersions.Lizmap_3_5 < LwcVersions.Lizmap_3_6) + self.assertTrue(LwcVersions.Lizmap_3_6 >= LwcVersions.Lizmap_3_6) self.assertTrue(LwcVersions.Lizmap_3_5 <= LwcVersions.Lizmap_3_5) - self.assertFalse(LwcVersions.Lizmap_3_5 < LwcVersions.Lizmap_3_4) + + self.assertEqual(LwcVersions.Lizmap_3_10, LwcVersions.latest()) + + # Do not confuse LWC 3.1 and 3.10 + self.assertTrue(LwcVersions.Lizmap_3_10 > LwcVersions.Lizmap_3_9) + self.assertTrue(LwcVersions.Lizmap_3_9 < LwcVersions.Lizmap_3_10) + self.assertTrue(LwcVersions.Lizmap_3_10 >= LwcVersions.Lizmap_3_10) + self.assertTrue(LwcVersions.Lizmap_3_10 <= LwcVersions.Lizmap_3_10) + + def test_version_list(self): + """ Test version as a list. """ + self.assertListEqual([3, 10], LwcVersions.version_as_list(LwcVersions.Lizmap_3_10.value)) def test_release_status(self): """ Test to retrieve release status. """