Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds+github@gmail.com>2020-09-01 12:22:44 +0200
committerAnton Hvornum <anton.feeds+github@gmail.com>2020-09-01 12:22:44 +0200
commit5bba102c45a9709891c5ad7ed20a42b1f036d9a2 (patch)
tree2b98bc79a5f99f218e1b7655f78aa95167414e37 /archinstall
parent2ac417239474cfb428dab6a9b7bf574fe613842f (diff)
Added list_mirrors() and prepared for selecting mirrors in guided.py
Diffstat (limited to 'archinstall')
-rw-r--r--archinstall/lib/mirrors.py42
1 files changed, 37 insertions, 5 deletions
diff --git a/archinstall/lib/mirrors.py b/archinstall/lib/mirrors.py
index 6cfccf19..53849a2a 100644
--- a/archinstall/lib/mirrors.py
+++ b/archinstall/lib/mirrors.py
@@ -1,7 +1,9 @@
+import urllib.request
+
from .exceptions import *
from .general import *
-def filter_mirrors_by_region(regions, *args, **kwargs):
+def filter_mirrors_by_region(regions, destination='/etc/pacman.d/mirrorlist', tmp_dir='/root', *args, **kwargs):
"""
This function will change the active mirrors on the live medium by
filtering which regions are active based on `regions`.
@@ -12,9 +14,9 @@ def filter_mirrors_by_region(regions, *args, **kwargs):
region_list = []
for region in regions.split(','):
region_list.append(f'country={region}')
- o = b''.join(sys_command((f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(region_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O /root/mirrorlist")))
- o = b''.join(sys_command(("/usr/bin/sed -i 's/#Server/Server/' /root/mirrorlist")))
- o = b''.join(sys_command(("/usr/bin/mv /root/mirrorlist /etc/pacman.d/")))
+ o = b''.join(sys_command((f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(region_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O {tmp_dir}/mirrorlist")))
+ o = b''.join(sys_command((f"/usr/bin/sed -i 's/#Server/Server/' {tmp_dir}/mirrorlist")))
+ o = b''.join(sys_command((f"/usr/bin/mv {tmp_dir}/mirrorlist {destination}")))
return True
@@ -54,7 +56,37 @@ def insert_mirrors(mirrors, *args, **kwargs):
return True
+def use_mirrors(regions :dict, destination='/etc/pacman.d/mirrorlist'):
+ for region, mirrors in regions.items():
+ with open(destination, 'w') as mirrorlist:
+ for mirror in mirrors:
+ mirrorlist.write(f'## {region}\n')
+ mirrorlist.write(f'Server = {mirror}\n')
+ return True
+
def re_rank_mirrors(top=10, *positionals, **kwargs):
if sys_command((f'/usr/bin/rankmirrors -n {top} /etc/pacman.d/mirrorlist > /etc/pacman.d/mirrorlist')).exit_code == 0:
return True
- return False \ No newline at end of file
+ return False
+
+def list_mirrors():
+ url = f"https://www.archlinux.org/mirrorlist/?protocol=https&ip_version=4&ip_version=6&use_mirror_status=on"
+
+ response = urllib.request.urlopen(url)
+ regions = {}
+
+ region = 'Unknown region'
+ for line in response.readlines():
+ if len(line.strip()) == 0: continue
+
+ line = line.decode('UTF-8').strip('\n').strip('\r')
+ if line[:3] == '## ':
+ region = line[3:]
+ elif line[:10] == '#Server = ':
+ if not region in regions:
+ regions[region] = {}
+
+ url = line[1:].lstrip('Server = ')
+ regions[region][url] = True
+
+ return regions \ No newline at end of file