From 4df094b3f304999a8f7138254ce0b6112fe4cac8 Mon Sep 17 00:00:00 2001 From: Xpirix Date: Mon, 6 Jan 2025 11:33:40 +0300 Subject: [PATCH 1/2] Add latest, ltr and stable to cache --- dockerize/sites-enabled/prod.conf | 14 -------------- qgis-app/plugins/tasks/generate_plugins_xml.py | 17 ++++++++++++----- qgis-app/plugins/views.py | 5 ----- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/dockerize/sites-enabled/prod.conf b/dockerize/sites-enabled/prod.conf index 517b0bc5..03d24bf5 100644 --- a/dockerize/sites-enabled/prod.conf +++ b/dockerize/sites-enabled/prod.conf @@ -110,17 +110,3 @@ server { allow all; } } - -# Redirect requests on analytics.qgis.org over to the feed -# This is just a conveneience in case we ever decide to host -# metabase on its own server. -# Note that we also have a cloudflare trasnform rule in place -# which will redirect users from analytics.qgis.org over to the public dashboard -# https://dash.cloudflare.com/a2cec2d89cc90579a20a30365bedcaf7/qgis.org/rules/transform-rules -server { - listen 80; - server_name plugins-analytics.qgis.org; - ssl_certificate /etc/letsencrypt/live/plugins-analytics.qgis.org/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/plugins-analytics.qgis.org/privkey.pem; - return 301 $scheme://plugins.qgis.org/metabase/public/dashboard/7ecd345f-7321-423d-9844-71e526a454a9; -} \ No newline at end of file diff --git a/qgis-app/plugins/tasks/generate_plugins_xml.py b/qgis-app/plugins/tasks/generate_plugins_xml.py index a7415b60..b677c8fd 100644 --- a/qgis-app/plugins/tasks/generate_plugins_xml.py +++ b/qgis-app/plugins/tasks/generate_plugins_xml.py @@ -6,6 +6,7 @@ from preferences import preferences from django.conf import settings from preferences import preferences +from plugins.utils import get_version_from_label logger = get_task_logger(__name__) @@ -28,6 +29,7 @@ def generate_plugins_xml(site=""): plugins_url = "{}/plugins/plugins_new.xml".format(site) versions = preferences.SitePreference.qgis_versions + labels = ["latest", "stable", "ltr"] if versions: versions = versions.split(",") @@ -80,12 +82,17 @@ def generate_plugins_xml(site=""): if not os.path.exists(folder_path): os.mkdir(folder_path) - for version in versions: - response = requests.get( - "{url}?qgis={version}".format(url=plugins_url, version=version) - ) + def fetch_and_save_xml(version_or_label, is_label=False): + version = get_version_from_label(version_or_label) if is_label else version_or_label + response = requests.get(f"{plugins_url}?qgis={version}") if response.status_code == 200: - file_name = "plugins_{}.xml".format(version) + file_name = f"plugins_{version_or_label}.xml" 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) diff --git a/qgis-app/plugins/views.py b/qgis-app/plugins/views.py index 69eb394d..e41f5125 100644 --- a/qgis-app/plugins/views.py +++ b/qgis-app/plugins/views.py @@ -1630,11 +1630,6 @@ def xml_plugins(request, qg_version=None, stable_only=None, package_name=None): """ request_version = request.GET.get("qgis", "1.8.0") - if request_version in ["latest", "ltr", "stable"]: - numbered_version = get_version_from_label(request_version) - # Redirect to this view using the numbered version because - # the xml file is cached with that. - return HttpResponseRedirect(reverse("xml_plugins") + f"?qgis={numbered_version}") version_level = len(str(request_version).split('.')) - 1 qg_version = ( qg_version From 88923ad1c4b232a00fbbcf07e10b694a420ab353 Mon Sep 17 00:00:00 2001 From: Xpirix Date: Mon, 6 Jan 2025 12:17:02 +0300 Subject: [PATCH 2/2] Fix unit test --- qgis-app/plugins/tests/test_task.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qgis-app/plugins/tests/test_task.py b/qgis-app/plugins/tests/test_task.py index 7cf22545..483d7f0c 100644 --- a/qgis-app/plugins/tests/test_task.py +++ b/qgis-app/plugins/tests/test_task.py @@ -46,7 +46,7 @@ def test_generate_plugins_xml(self, mock_open, mock_mkdir, mock_exists, mock_get # Given mock_response = MagicMock() mock_response.status_code = 200 - mock_response.text = '' + mock_response.text = ' QGIS Version 34002|Visit https://download.qgis.org to get your copy of version 3.40.2' mock_get.return_value = mock_response preferences.SitePreference.qgis_versions = '3.24,3.25' @@ -74,7 +74,7 @@ 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 = '' + mock_response.text = ' QGIS Version 34002|Visit https://download.qgis.org to get your copy of version 3.40.2' mock_get.return_value = mock_response preferences.SitePreference.qgis_versions = '3.24,3.25'