diff --git a/qgis-app/plugins/tasks/generate_plugins_xml.py b/qgis-app/plugins/tasks/generate_plugins_xml.py index b677c8fd..79cb0cae 100644 --- a/qgis-app/plugins/tasks/generate_plugins_xml.py +++ b/qgis-app/plugins/tasks/generate_plugins_xml.py @@ -91,8 +91,8 @@ def fetch_and_save_xml(version_or_label, is_label=False): with open(os.path.join(folder_path, file_name), "w+") as file: file.write(response.text) - for version in versions: - fetch_and_save_xml(version) - for label in labels: fetch_and_save_xml(label, is_label=True) + + for version in versions: + fetch_and_save_xml(version) diff --git a/qgis-app/plugins/tests/test_task.py b/qgis-app/plugins/tests/test_task.py index 483d7f0c..a17c41d9 100644 --- a/qgis-app/plugins/tests/test_task.py +++ b/qgis-app/plugins/tests/test_task.py @@ -74,7 +74,8 @@ def test_generate_plugins_xml_with_custom_site(self, mock_open, mock_mkdir, mock # Given mock_response = MagicMock() mock_response.status_code = 200 - mock_response.text = ' QGIS Version 34002|Visit https://download.qgis.org to get your copy of version 3.40.2' + mock_response.text = '' + mock_response.json.return_value = {'latest': {'version': '3.40'}, 'ltr': {'version': '3.40'}} mock_get.return_value = mock_response preferences.SitePreference.qgis_versions = '3.24,3.25' diff --git a/qgis-app/plugins/utils.py b/qgis-app/plugins/utils.py index 546f653e..cfa3c75a 100644 --- a/qgis-app/plugins/utils.py +++ b/qgis-app/plugins/utils.py @@ -72,20 +72,19 @@ def get_version_from_label(param): ValueError: If the parameter value is invalid. Exception: If the request to the QGIS version service fails or the version is not found. """ - if param.lower() in ['ltr', 'stable']: - url = 'https://version.qgis.org/version-ltr.txt' - elif param.lower() == 'latest': - url = 'https://version.qgis.org/version.txt' - else: - raise ValueError('Invalid parameter value') + url = 'https://version.qgis.org/version.json' response = requests.get(url) if response.status_code != 200: raise Exception('Request failed') - content = response.text - match = re.search(r'QGIS Version \d+\|Visit .+ version (\d+\.\d+)', content) - if match: - return match.group(1) - else: - raise Exception('Version not found in response') \ No newline at end of file + content = response.json() + param = param.lower() + + if param == 'stable': + param = 'ltr' + + if param in content: + version_info = content[param] + return version_info['version'] + return None