Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/mirrors.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2022-06-02 13:32:42 +0200
committerGitHub <noreply@github.com>2022-06-02 13:32:42 +0200
commit7943dd82365fd9fb5034a0f1c05de3ccabda468a (patch)
tree5e006c48d6f39d6f551aa441de6a386153ab2364 /archinstall/lib/mirrors.py
parentc2be07e7dc543fd6c5b60e67153061b2136b8575 (diff)
Added more offline functionality, such as skipping package search (#1296)
* Added more offline functionality, such as skipping package search * Disabled list_mirrors() from going online if --offline is given. Defaults to /etc/pacman.d/mirrorlist instead. * Forgot import of pathlib * Made list_mirrors() open /etc/pacman.d/mirrorlist in byte mode to better emulate the result of urllib response reading. * Forgot variable declaration * Made list_mirrors include activated server definitions
Diffstat (limited to 'archinstall/lib/mirrors.py')
-rw-r--r--archinstall/lib/mirrors.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/archinstall/lib/mirrors.py b/archinstall/lib/mirrors.py
index 73921cef..d76e0473 100644
--- a/archinstall/lib/mirrors.py
+++ b/archinstall/lib/mirrors.py
@@ -1,10 +1,12 @@
import logging
+import pathlib
import urllib.error
import urllib.request
from typing import Union, Mapping, Iterable, Dict, Any, List
from .general import SysCommand
from .output import log
+from .storage import storage
def sort_mirrorlist(raw_data :bytes, sort_order=["https", "http"]) -> bytes:
"""
@@ -144,16 +146,22 @@ def re_rank_mirrors(
def list_mirrors(sort_order :List[str] = ["https", "http"]) -> Dict[str, Any]:
- url = "https://archlinux.org/mirrorlist/?protocol=https&protocol=http&ip_version=4&ip_version=6&use_mirror_status=on"
regions = {}
- try:
- response = urllib.request.urlopen(url)
- except urllib.error.URLError as err:
- log(f'Could not fetch an active mirror-list: {err}', level=logging.WARNING, fg="orange")
- return regions
+ if storage['arguments']['offline']:
+ with pathlib.Path('/etc/pacman.d/mirrorlist').open('rb') as fh:
+ mirrorlist = fh.read()
+ else:
+ url = "https://archlinux.org/mirrorlist/?protocol=https&protocol=http&ip_version=4&ip_version=6&use_mirror_status=on"
+
+ try:
+ response = urllib.request.urlopen(url)
+ except urllib.error.URLError as err:
+ log(f'Could not fetch an active mirror-list: {err}', level=logging.WARNING, fg="orange")
+ return regions
+
+ mirrorlist = response.read()
- mirrorlist = response.read()
if sort_order:
mirrorlist = sort_mirrorlist(mirrorlist, sort_order=sort_order)
@@ -170,5 +178,10 @@ def list_mirrors(sort_order :List[str] = ["https", "http"]) -> Dict[str, Any]:
url = line.lstrip('#Server = ')
regions[region][url] = True
+ elif line.startswith('Server = '):
+ regions.setdefault(region, {})
+
+ url = line.lstrip('Server = ')
+ regions[region][url] = True
return regions