mirror of
https://git.launchpad.net/~ubuntu-qt-code/+git/calamares-settings-ubuntu
synced 2025-06-18 21:21:47 +00:00
Updated automirror for urllib.request
Summary: Updated automirror for urllib.request Test Plan: Verify basic function in US, but then also have non-US users test for functionality, especially paying attention to time. More specifically, this patch should be able to be applied directly to /usr/lib/(i138-linux-gnu|x86_64-linux-gnu)/calamares/modules/automirror/main.py in a live system, then run the installer and see what happens. Reviewers: tsimonq2, wxl Reviewed By: tsimonq2 Differential Revision: https://phab.lubuntu.me/D23
This commit is contained in:
parent
9c6c1de9fe
commit
4bf7f72786
@ -19,7 +19,10 @@ import json
|
|||||||
import subprocess
|
import subprocess
|
||||||
import libcalamares
|
import libcalamares
|
||||||
from time import strftime
|
from time import strftime
|
||||||
from urllib import request
|
import urllib.request
|
||||||
|
from urllib.error import HTTPError
|
||||||
|
from urllib.error import URLError
|
||||||
|
from socket import timeout
|
||||||
from lsb_release import get_distro_information
|
from lsb_release import get_distro_information
|
||||||
|
|
||||||
global sources
|
global sources
|
||||||
@ -80,23 +83,51 @@ deb URL/ubuntu/ CODENAME-backports main restricted universe multiverse
|
|||||||
# deb http://archive.canonical.com/ubuntu CODENAME partner
|
# deb http://archive.canonical.com/ubuntu CODENAME partner
|
||||||
# deb-src http://archive.canonical.com/ubuntu CODENAME partner"""
|
# deb-src http://archive.canonical.com/ubuntu CODENAME partner"""
|
||||||
|
|
||||||
|
|
||||||
def getcountry():
|
def getcountry():
|
||||||
# This is hardcoded for now, but should eventually be put into the config
|
# This URI hardcoded for now, but should eventually be put into the config
|
||||||
with request.urlopen("https://ipapi.co/json") as url:
|
geoipurl = "https://ipapi.co/json"
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(geoipurl, timeout=75) as url:
|
||||||
localedata = json.loads(url.read().decode())
|
localedata = json.loads(url.read().decode())
|
||||||
|
except HTTPError:
|
||||||
|
logging.error("Data of %s not retrieved because %s - URL: %s",
|
||||||
|
name, error, url)
|
||||||
|
except URLError:
|
||||||
|
if isinstance(error.reason, socket.timeout):
|
||||||
|
logging.error("Socket timed out - URL %s", url)
|
||||||
|
else:
|
||||||
|
logging.error("Non-timeout protocol error.")
|
||||||
|
else:
|
||||||
|
print("Country successfully determined.")
|
||||||
return localedata["country"]
|
return localedata["country"]
|
||||||
|
|
||||||
|
|
||||||
def getmirror(country):
|
def getmirror(country):
|
||||||
with request.urlopen(libcalamares.job.configuration["mirrorList"]) as url:
|
mirrorlisturl = libcalamares.job.configuration["mirrorList"]
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(mirrorlisturl, timeout=75) as url:
|
||||||
mirrors = json.loads(url.read().decode())
|
mirrors = json.loads(url.read().decode())
|
||||||
|
except HTTPError:
|
||||||
|
logging.error("Data of %s not retrieved because %s - URL: %s",
|
||||||
|
name, error, url)
|
||||||
|
except URLError:
|
||||||
|
if isinstance(error.reason, socket.timeout):
|
||||||
|
logging.error("Socket timed out - URL %s", url)
|
||||||
|
else:
|
||||||
|
logging.error("Non-timeout protocol error.")
|
||||||
|
else:
|
||||||
|
print("Mirror successfully determined.")
|
||||||
if country in mirrors.keys():
|
if country in mirrors.keys():
|
||||||
return mirrors[country] + "."
|
return mirrors[country] + "."
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def getcodename():
|
def getcodename():
|
||||||
return get_distro_information()["CODENAME"]
|
return get_distro_information()["CODENAME"]
|
||||||
|
|
||||||
|
|
||||||
def changesources(prefix):
|
def changesources(prefix):
|
||||||
root = libcalamares.globalstorage.value("rootMountPoint")
|
root = libcalamares.globalstorage.value("rootMountPoint")
|
||||||
|
|
||||||
@ -118,6 +149,7 @@ def changesources(prefix):
|
|||||||
sourcesfile.write(sources)
|
sourcesfile.write(sources)
|
||||||
sourcesfile.truncate()
|
sourcesfile.truncate()
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
"""Autoselect a mirror from a list."""
|
"""Autoselect a mirror from a list."""
|
||||||
if libcalamares.globalstorage.value("hasInternet"):
|
if libcalamares.globalstorage.value("hasInternet"):
|
||||||
|
3
debian/changelog
vendored
3
debian/changelog
vendored
@ -8,8 +8,9 @@ calamares-settings-ubuntu (24) cosmic; urgency=medium
|
|||||||
|
|
||||||
[ Walter Lapchynski ]
|
[ Walter Lapchynski ]
|
||||||
* Generalize installation of GRUB for EFI.
|
* Generalize installation of GRUB for EFI.
|
||||||
|
* Add urlopen() error handling to automirror, thanks to Samuel Banya.
|
||||||
|
|
||||||
-- Walter Lapchynski <wxl@ubuntu.com> Tue, 09 Oct 2018 21:51:55 -0700
|
-- Walter Lapchynski <wxl@ubuntu.com> Wed, 10 Oct 2018 08:36:52 -0700
|
||||||
|
|
||||||
calamares-settings-ubuntu (23) cosmic; urgency=medium
|
calamares-settings-ubuntu (23) cosmic; urgency=medium
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user