mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-10-01 06:21:56 -09:00
utils/update-rust: use urllib.request from stdlib instead of requests
We can use urllib.request without adding any addition lines of code compared with requests which is not part of the stdlib. Signed-off-by: James Hilliard <james.hilliard1@gmail.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
committed by
Thomas Petazzoni
parent
3b9d62dac5
commit
8436a5141b
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
import requests
|
|
||||||
import sys
|
import sys
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
# When updating this list, also update:
|
# When updating this list, also update:
|
||||||
# - package/rustc/Config.in.host:
|
# - package/rustc/Config.in.host:
|
||||||
@@ -87,12 +87,12 @@ def gen_hash_file_src(hash_file, new_version):
|
|||||||
f_name = f"rustc-{new_version}-src.tar.xz"
|
f_name = f"rustc-{new_version}-src.tar.xz"
|
||||||
print(f"\r\033[KUpdating {f_name}", end="")
|
print(f"\r\033[KUpdating {f_name}", end="")
|
||||||
h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
|
h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
|
||||||
r = requests.get(h_url)
|
with urllib.request.urlopen(h_url) as r:
|
||||||
if r.status_code != 200:
|
if r.status != 200:
|
||||||
raise RuntimeError(f"No hash for {f_name}. Has source been removed?")
|
raise RuntimeError(f"No hash for {f_name}. Has source been removed?")
|
||||||
# rstrip() content, and explicitly add the \n, in case
|
# rstrip() content, and explicitly add the \n, in case
|
||||||
# a hash file does not have a trailing \n.
|
# a hash file does not have a trailing \n.
|
||||||
fd.write(f"# From {h_url}\nsha256 {r.content.decode().rstrip()}\n")
|
fd.write(f"# From {h_url}\nsha256 {r.read().decode().rstrip()}\n")
|
||||||
fd.write("# Locally generated\n")
|
fd.write("# Locally generated\n")
|
||||||
for license in LICENSES:
|
for license in LICENSES:
|
||||||
fd.write(f"sha256 {LICENSES[license]} LICENSE-{license}\n")
|
fd.write(f"sha256 {LICENSES[license]} LICENSE-{license}\n")
|
||||||
@@ -105,22 +105,22 @@ def gen_hash_file_bin(hash_file, new_version):
|
|||||||
f_name = f"rust-{new_version}-{host}.tar.xz"
|
f_name = f"rust-{new_version}-{host}.tar.xz"
|
||||||
print(f"\r\033[KUpdating {f_name}", end="")
|
print(f"\r\033[KUpdating {f_name}", end="")
|
||||||
h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
|
h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
|
||||||
r = requests.get(h_url)
|
with urllib.request.urlopen(h_url) as r:
|
||||||
if r.status_code != 200:
|
if r.status != 200:
|
||||||
raise RuntimeError(f"No hash for {f_name}. Has host {host} been removed?")
|
raise RuntimeError(f"No hash for {f_name}. Has host {host} been removed?")
|
||||||
# rstrip() content, and explicitly add the \n, in case
|
# rstrip() content, and explicitly add the \n, in case
|
||||||
# a hash file does not have a trailing \n.
|
# a hash file does not have a trailing \n.
|
||||||
fd.write(f"# From {h_url}\nsha256 {r.content.decode().rstrip()}\n")
|
fd.write(f"# From {h_url}\nsha256 {r.read().decode().rstrip()}\n")
|
||||||
for target in RUST_TARGETS:
|
for target in RUST_TARGETS:
|
||||||
f_name = f"rust-std-{new_version}-{target}.tar.xz"
|
f_name = f"rust-std-{new_version}-{target}.tar.xz"
|
||||||
print(f"\r\033[KUpdating {f_name}", end="")
|
print(f"\r\033[KUpdating {f_name}", end="")
|
||||||
h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
|
h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
|
||||||
r = requests.get(h_url)
|
with urllib.request.urlopen(h_url) as r:
|
||||||
if r.status_code != 200:
|
if r.status != 200:
|
||||||
raise RuntimeError(f"No hash for {f_name}. Has target {target} been removed?")
|
raise RuntimeError(f"No hash for {f_name}. Has target {target} been removed?")
|
||||||
# rstrip() content, and explicitly add the \n, in case
|
# rstrip() content, and explicitly add the \n, in case
|
||||||
# a hash file does not have a trailing \n.
|
# a hash file does not have a trailing \n.
|
||||||
fd.write(f"# From {h_url}\nsha256 {r.content.decode().rstrip()}\n")
|
fd.write(f"# From {h_url}\nsha256 {r.read().decode().rstrip()}\n")
|
||||||
fd.write("# Locally generated\n")
|
fd.write("# Locally generated\n")
|
||||||
for license in LICENSES:
|
for license in LICENSES:
|
||||||
fd.write(f"sha256 {LICENSES[license]} LICENSE-{license}\n")
|
fd.write(f"sha256 {LICENSES[license]} LICENSE-{license}\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user