Skip to content

Commit

Permalink
Merge pull request #500 from Xpirix/get_version_from_json
Browse files Browse the repository at this point in the history
Use the version.json to get the version from label
  • Loading branch information
Xpirix authored Jan 9, 2025
2 parents fd393de + 5378137 commit 13ee6cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions qgis-app/plugins/tasks/generate_plugins_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion qgis-app/plugins/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<some xml content> QGIS Version 34002|Visit https://download.qgis.org to get your copy of version 3.40.2'
mock_response.text = '<some xml content>'
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'

Expand Down
23 changes: 11 additions & 12 deletions qgis-app/plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
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

0 comments on commit 13ee6cc

Please sign in to comment.