Skip to content

Commit

Permalink
Follow up previous commit about LWC 3.10, do not get confused with LW…
Browse files Browse the repository at this point in the history
…C 3.1 fix #608
  • Loading branch information
Gustry committed Oct 21, 2024
1 parent b964ab9 commit 6e5d706
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
32 changes: 30 additions & 2 deletions lizmap/definitions/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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. """
Expand Down
7 changes: 4 additions & 3 deletions lizmap/dialogs/server_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lizmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lizmap/table_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 16 additions & 5 deletions lizmap/test/test_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. """
Expand Down

0 comments on commit 6e5d706

Please sign in to comment.