forked from Mirror/pmbootstrap
Add option to auto-select the best mirror
Signed-off-by: Jens Reidel <adrian@travitia.xyz> Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2559
This commit is contained in:
parent
987793bb24
commit
ec0163ce63
2 changed files with 46 additions and 11 deletions
|
@ -6,6 +6,7 @@ from pmb.helpers import logging
|
|||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import time
|
||||
import urllib.request
|
||||
from typing import Any, Literal, overload
|
||||
import pmb.helpers.cli
|
||||
|
@ -149,3 +150,17 @@ def retrieve_json(url: str, headers: dict[str, str] | None = None) -> Any:
|
|||
See retrieve() for the meaning of the parameters.
|
||||
"""
|
||||
return json.loads(retrieve(url, headers, False))
|
||||
|
||||
|
||||
def measure_latency(url: str) -> float:
|
||||
"""Requests a URL and returns the total time it took to perform the request.
|
||||
|
||||
:param url: the http(s) address of the resource to fetch
|
||||
|
||||
:returns: seconds it took to complete the request
|
||||
"""
|
||||
req = urllib.request.Request(url)
|
||||
start_time = time.monotonic()
|
||||
with urllib.request.urlopen(req) as response:
|
||||
response.read()
|
||||
return time.monotonic() - start_time
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue