[gimp-web/wip/Jehan/issue-236-new-sponsor-page: 5/25] plugins: use mirrors.json and display pretty organization names.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-web/wip/Jehan/issue-236-new-sponsor-page: 5/25] plugins: use mirrors.json and display pretty organization names.
- Date: Sun, 19 Sep 2021 17:31:15 +0000 (UTC)
commit 1fa1e122507d4d4e9c8df5f9c205e9ad72228fee
Author: Jehan <jehan girinstud io>
Date: Sat Aug 28 00:41:57 2021 +0200
plugins: use mirrors.json and display pretty organization names.
mirrors2.json is deprecated as mirrors.json is now the file with the
manually curated names, and containing the exact list of mirrors used on
GNOME webservers (i.e. validated by their process which resulting on
giving out rsync credentials).
I still leave mirrors2.json for now because I will do a last call before
making the move so that mirrors currently listed have a chance to get
their rsync credentials before we replace the list.
Note that we still update the country through pygeoip.GeoIP instead of
using the "location" field in the json file. I think actually we should
do a comparison to make sure the officially announced country and the
IP-detected countries are the same. But it will require straightening
the list (sometimes it contains cities or other information).
plugins/gimp_mirrors/gimp_mirrors.py | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)
---
diff --git a/plugins/gimp_mirrors/gimp_mirrors.py b/plugins/gimp_mirrors/gimp_mirrors.py
index 24a720ce..15af69ec 100644
--- a/plugins/gimp_mirrors/gimp_mirrors.py
+++ b/plugins/gimp_mirrors/gimp_mirrors.py
@@ -4,6 +4,7 @@ from os.path import basename
import socket
import json
import pygeoip
+from urllib.parse import urlparse
'''
@@ -30,21 +31,19 @@ Update 2016-07-20
class UnexpectedException(Exception): pass
-def html_output( data ):
-
+def html_output(data):
html = u"<dl class='download-mirrors'>\n"
- for key, values in sorted(data.items()):
-
- html += u"<dt>{}</dt>".format( key )
+ for country, values in sorted(data.items()):
+ html += u"<dt>{}</dt>".format(country)
- for value in values:
- if isinstance(value, str):
+ for name, url in sorted(values.items()):
+ if isinstance(url, str):
# In Python3 str are unicode strings.
- tmp = value
+ tmp = url
else:
- tmp = value.decode('utf-8')
- html += u"<dd><a href='{}'>{}</a></dd>\n".format( tmp, tmp )
+ tmp = url.decode('utf-8')
+ html += u"<dd><a href='{}'>{}</a></dd>\n".format(tmp, name)
html += u"</dl>"
@@ -68,21 +67,18 @@ def do_mirrors(path, context):
# load mirrors2.json file from content
try:
- with open('./content/downloads/mirrors2.json') as data_file:
+ with open('./content/downloads/mirrors.json') as data_file:
data = json.load(data_file)
for record in data:
- #print("####")
- #print record
-
try:
- country = gi.country_name_by_name( record )
- #print(country)
+ domain = urlparse(data[record]['mirrors'][0]).netloc
+ country = gi.country_name_by_name(domain)
if country in mirrors:
- mirrors[ country ] += data[ record ]
+ mirrors[country][record] = data[record]['about']
else:
- mirrors[ country ] = data[ record ]
+ mirrors[country] = { record: data[record]['about'] }
except:
print("cannot resolve record: ", record)
@@ -94,7 +90,7 @@ def do_mirrors(path, context):
s = s.decode('utf-8').replace(u"<!-- MIRRORS -->", html_output(mirrors))
with open( path, 'wb') as f:
- f.write( s.encode('utf-8') )
+ f.write(s.encode('utf-8'))
except:
print("Trouble with reading/writing path.")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]