Skip to content

Commit 190cdd4

Browse files
committed
Markdown - Fix export of modules, server plugin if not installed, include GIT hash with URL if possible
1 parent 965e980 commit 190cdd4

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

lizmap/server_lwc.py

+44-27
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ def config_for_id(auth_id: str) -> Optional[QgsAuthMethodConfig]:
221221
""" Fetch the authentication settings for a given token. """
222222
auth_manager = QgsApplication.authManager()
223223
if not auth_manager.masterPasswordIsSet():
224-
LOGGER.warning("Master password is not set, could not look for ID {}".format(auth_id))
224+
LOGGER.warning(f"Master password is not set, could not look for ID {auth_id}")
225225
return None
226226

227227
conf = QgsAuthMethodConfig()
228228
auth_manager.loadAuthenticationConfig(auth_id, conf, True)
229229
if not conf.id():
230-
LOGGER.debug("Skipping password ID {}, it wasn't found in the password manager".format(auth_id))
230+
LOGGER.debug(f"Skipping password ID {auth_id}, it wasn't found in the password manager")
231231
return None
232232

233233
# LOGGER.info("Found password ID {}".format(auth_id))
@@ -248,7 +248,7 @@ def clean_cache(cls, force=False):
248248
def cache_file_for_name(cls, name: str) -> Path:
249249
""" Return a cache file name according to a server name. """
250250
name = name.replace('/', '-')
251-
cache_file = lizmap_user_folder().joinpath("cache_server_metadata").joinpath('{}.json'.format(name))
251+
cache_file = lizmap_user_folder().joinpath("cache_server_metadata").joinpath(f'{name}.json')
252252
return cache_file
253253

254254
def check_validity_servers(self) -> bool:
@@ -401,7 +401,7 @@ def remove_row(self):
401401
QMessageBox.StandardButton.Ok)
402402
self.table.clearSelection()
403403
return
404-
LOGGER.debug("Row {} removed from the QGIS authentication database".format(auth_id))
404+
LOGGER.debug(f"Row {auth_id} removed from the QGIS authentication database")
405405

406406
self.table.clearSelection()
407407
self.table.removeRow(row)
@@ -503,13 +503,14 @@ def fetch(self, url: str, auth_id: str, row: int):
503503
self.fetchers[row].finished.connect(partial(self.request_finished, row))
504504

505505
if auth_id:
506-
QgsMessageLog.logMessage("Using the token for <a href='{0}'>{0}</a>".format(url), "Lizmap", Qgis.Info)
506+
QgsMessageLog.logMessage(f"Using the token for <a href='{url}'>{url}</a>", "Lizmap", Qgis.Info)
507507

508508
request = QNetworkRequest()
509509
request.setUrl(QUrl(ServerWizard.url_metadata(url)))
510510
request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
511511
# According to QGIS debug panel, this is not working for now
512-
request.setAttribute(QNetworkRequest.Attribute.CacheLoadControlAttribute, QNetworkRequest.CacheLoadControl.PreferNetwork)
512+
request.setAttribute(
513+
QNetworkRequest.Attribute.CacheLoadControlAttribute, QNetworkRequest.CacheLoadControl.PreferNetwork)
513514
self.fetchers[row].fetchContent(request, auth_id)
514515

515516
def request_finished(self, row: int):
@@ -631,7 +632,7 @@ def request_finished(self, row: int):
631632
# Add the JSON metadata in the server combobox
632633
index = self.server_combo.findData(url, ServerComboData.ServerUrl.value)
633634
self.server_combo.setItemData(index, content, ServerComboData.JsonMetadata.value)
634-
LOGGER.info("Saving server metadata from network : {} - {}".format(index, server_alias))
635+
LOGGER.info(f"Saving server metadata from network : {index} - {server_alias}")
635636
self.parent.tooltip_server_combo(index)
636637
# Server combo is refreshed, maybe we can allow the menu bar
637638
self.check_dialog_validity()
@@ -640,10 +641,16 @@ def request_finished(self, row: int):
640641
if self.server_combo.currentData(ServerComboData.ServerUrl.value) == url:
641642
self.parent.refresh_combo_repositories()
642643

644+
lwc_version_txt = f'* Lizmap Web Client : {lizmap_version}'
645+
git_hash = info.get('commit')
646+
if git_hash:
647+
lwc_version_txt += f" - commit {git_hash} https://github.com/3liz/lizmap-web-client/commit/{git_hash}"
648+
lwc_version_txt += '\n'
649+
643650
# Markdown
644651
markdown = '**Versions :**\n\n'
645-
markdown += '* Lizmap Web Client : {}\n'.format(lizmap_version)
646-
markdown += '* Lizmap plugin : {}\n'.format(version())
652+
markdown += lwc_version_txt
653+
markdown += f'* Lizmap plugin : {version()}\n'
647654
markdown += '* QGIS Desktop : {}\n'.format(Qgis.QGIS_VERSION.split('-')[0])
648655
qgis_cell.setData(Qt.UserRole, markdown)
649656
qgis_cell.setData(Qt.UserRole + 1, content)
@@ -674,17 +681,21 @@ def request_finished(self, row: int):
674681
plugins = qgis_server_info.get('plugins')
675682
# plugins = {'atlasprint': {'version': '3.2.2'}}
676683
# Temporary, add plugins as markdown in the data
677-
markdown += '* QGIS Server : {}\n'.format(qgis_server_version)
684+
markdown += f'* QGIS Server : {qgis_server_version}\n'
678685
py_qgis = qgis_server_info.get('py_qgis_server')
679686
if py_qgis:
680687
py_qgis_version = py_qgis.get('version', 'Not used')
681688
else:
682689
# Legacy, old server running
683690
py_qgis_version = qgis_metadata.get('py_qgis_server_version', 'Not used')
684691

685-
markdown += '* Py-QGIS-Server : {}\n'.format(py_qgis_version)
692+
markdown += f'* Py-QGIS-Server : {py_qgis_version}\n'
686693
for plugin, info in plugins.items():
687-
markdown += '* QGIS Server plugin {} : {}\n'.format(plugin, info['version'])
694+
plugin_version = info['version']
695+
if plugin_version.lower().startswith("not"):
696+
# https://github.com/3liz/qgis-lizmap-server-plugin/commit/4e8e8c51102470eac0dc2ec622db9ab41d37f1c1
697+
continue
698+
markdown += f'* QGIS Server plugin {plugin} : {plugin_version}\n'
688699

689700
markdown += self.modules_to_markdown(content)
690701
qgis_cell.setData(Qt.UserRole, markdown)
@@ -755,9 +766,12 @@ def modules_to_markdown(cls, content: dict) -> str:
755766
text += '<summary>List of Lizmap Web Client modules :</summary>\n'
756767
text += '<br/>\n'
757768
modules = content.get("modules")
758-
if modules:
759-
for module, info in modules.items():
760-
text += f'* {module} : {info.get("version", "")}\n'
769+
if isinstance(modules, dict):
770+
if len(modules.keys()) >= 1:
771+
for module, info in modules.items():
772+
text += f'* {module} : {info.get("version", "")}\n'
773+
else:
774+
text += '* No module\n'
761775
else:
762776
text += '* Version Lizmap Web Client 3.8 needed\n'
763777
text += '</details>\n'
@@ -804,11 +818,11 @@ def refresh_server_combo(self):
804818
with open(cache_file, encoding='utf8') as f:
805819
metadata = json.load(f)
806820
self.server_combo.setItemData(index, metadata, ServerComboData.JsonMetadata.value)
807-
LOGGER.info("Loading server <a href='{}'>{}</a> using cache in the drop down list".format(url, name))
821+
LOGGER.info(f"Loading server <a href='{url}'>{name}</a> using cache in the drop down list")
808822
else:
809823
self.server_combo.setItemData(index, {}, ServerComboData.JsonMetadata.value)
810824
LOGGER.info(
811-
"Loading server <a href='{}'>{}</a> without metadata in the drop down list".format(url, name))
825+
f"Loading server <a href='{url}'>{name}</a> without metadata in the drop down list")
812826

813827
self.parent.tooltip_server_combo(index)
814828

@@ -905,10 +919,11 @@ def _messages_for_version(
905919
split_version = lizmap_version.split('.')
906920
if len(split_version) not in (3, 4):
907921
# 3.4.0-pre but also 3.4.0-rc.1
922+
# noinspection PyTypeChecker
908923
QgsMessageLog.logMessage(
909-
"The version '{}' is not correct.".format(lizmap_version), "Lizmap", Qgis.Critical)
924+
f"The version '{lizmap_version}' is not correct.", "Lizmap", Qgis.Critical)
910925

911-
branch = '{}.{}'.format(split_version[0], split_version[1])
926+
branch = f'{split_version[0]}.{split_version[1]}'
912927
full_version = '{}.{}'.format(branch, split_version[2].split('-')[0])
913928

914929
messages = []
@@ -1008,10 +1023,12 @@ def _messages_for_version(
10081023
messages.append(tr("Running a .0 version, upgrade to the latest bugfix release"))
10091024
elif bugfix != 0 and status in (ReleaseStatus.ReleaseCandidate, ReleaseStatus.Stable, ReleaseStatus.SecurityBugfixOnly, ReleaseStatus.Retired):
10101025
# Even if the branch is retired, we encourage people upgrading to the latest
1011-
messages.append(
1012-
tr(
1013-
'Not latest bugfix release, {version} is available'
1014-
).format(version=json_version['latest_release_version']))
1026+
if not lizmap_cloud:
1027+
# Only advertise if it's not a customer
1028+
messages.append(
1029+
tr(
1030+
'Not latest bugfix release, {version} is available'
1031+
).format(version=json_version['latest_release_version']))
10151032

10161033
if is_pre_package:
10171034
# Pre-release, maybe the package got some updates
@@ -1295,7 +1312,7 @@ def migrate_password_manager(self, servers: list):
12951312

12961313
if '@{}'.format(url) in conf.name():
12971314
# Old format
1298-
LOGGER.warning("Migrating the URL {} in the QGIS authentication database".format(url))
1315+
LOGGER.warning(f"Migrating the URL {url} in the QGIS authentication database")
12991316
user = conf.config('username')
13001317
password = conf.config('password')
13011318

@@ -1328,7 +1345,7 @@ def migrate_password_manager(self, servers: list):
13281345
split = conf.name().split('@')
13291346
if QUrl(split[-1]).isValid():
13301347
LOGGER.critical(
1331-
"Is the password ID '{}' in the QGIS authentication database a Lizmap server URL ? If yes, "
1332-
"please remove it manually, otherwise skip this message. Go in the QGIS global properties, "
1333-
"then 'Authentication' panel and check this ID.".format(config)
1348+
f"Is the password ID '{config}' in the QGIS authentication database a Lizmap server URL ? If yes, "
1349+
f"please remove it manually, otherwise skip this message. Go in the QGIS global properties, "
1350+
f"then 'Authentication' panel and check this ID."
13341351
)

lizmap/test/test_version_info.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,15 @@ def test_version_info_qgis_server_status(self):
280280
'qgis_desktop': qgis_desktop,
281281
'error': "NO_ACCESS",
282282
}
283+
# QGIS server 3.22 is EOL since February 2023, but the 2024 is hardcoded, as we do not have 3.22 on the
284+
# infrastructure
285+
# TODO, to be fixed with a proper table
283286
self.assertEqual(
284287
ServerManager._messages_for_version(**data, lizmap_cloud=True),
285288
(
286289
Qgis.Critical,
287290
[
288-
'QGIS Server version 3.22 is not maintained anymore by QGIS.org since February 2023. Please visit '
291+
'QGIS Server version 3.22 is not maintained anymore by QGIS.org since February 2024. Please visit '
289292
'your administration panel in the web browser to ask for the update.',
290293
'QGIS Server version < QGIS Desktop version. Either upgrade your QGIS Server 3.22 or downgrade '
291294
'your QGIS Desktop 3.28',

0 commit comments

Comments
 (0)