All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] utils/update-rust: use urllib.request from stdlib instead of requests
@ 2024-06-23 20:35 James Hilliard
  2024-07-10 21:04 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: James Hilliard @ 2024-06-23 20:35 UTC (permalink / raw)
  To: buildroot; +Cc: James Hilliard

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>
---
 utils/update-rust | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/utils/update-rust b/utils/update-rust
index 6799324fac..407ef69847 100755
--- a/utils/update-rust
+++ b/utils/update-rust
@@ -2,8 +2,8 @@
 
 import argparse
 import pathlib
-import requests
 import sys
+import urllib.request
 
 # When updating this list, also update:
 # - 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"
         print(f"\r\033[KUpdating {f_name}", end="")
         h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
-        r = requests.get(h_url)
-        if r.status_code != 200:
-            raise RuntimeError(f"No hash for {f_name}. Has source been removed?")
-        # rstrip() content, and explicitly add the \n, in case
-        # a hash file does not have a trailing \n.
-        fd.write(f"# From {h_url}\nsha256  {r.content.decode().rstrip()}\n")
+        with urllib.request.urlopen(h_url) as r:
+            if r.status != 200:
+                raise RuntimeError(f"No hash for {f_name}. Has source been removed?")
+            # rstrip() content, and explicitly add the \n, in case
+            # a hash file does not have a trailing \n.
+            fd.write(f"# From {h_url}\nsha256  {r.read().decode().rstrip()}\n")
         fd.write("# Locally generated\n")
         for license in LICENSES:
             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"
             print(f"\r\033[KUpdating {f_name}", end="")
             h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
-            r = requests.get(h_url)
-            if r.status_code != 200:
-                raise RuntimeError(f"No hash for {f_name}. Has host {host} been removed?")
-            # rstrip() content, and explicitly add the \n, in case
-            # a hash file does not have a trailing \n.
-            fd.write(f"# From {h_url}\nsha256  {r.content.decode().rstrip()}\n")
+            with urllib.request.urlopen(h_url) as r:
+                if r.status != 200:
+                    raise RuntimeError(f"No hash for {f_name}. Has host {host} been removed?")
+                # rstrip() content, and explicitly add the \n, in case
+                # a hash file does not have a trailing \n.
+                fd.write(f"# From {h_url}\nsha256  {r.read().decode().rstrip()}\n")
         for target in RUST_TARGETS:
             f_name = f"rust-std-{new_version}-{target}.tar.xz"
             print(f"\r\033[KUpdating {f_name}", end="")
             h_url = f"{RUST_DIST_URL}/{f_name}.sha256"
-            r = requests.get(h_url)
-            if r.status_code != 200:
-                raise RuntimeError(f"No hash for {f_name}. Has target {target} been removed?")
-            # rstrip() content, and explicitly add the \n, in case
-            # a hash file does not have a trailing \n.
-            fd.write(f"# From {h_url}\nsha256  {r.content.decode().rstrip()}\n")
+            with urllib.request.urlopen(h_url) as r:
+                if r.status != 200:
+                    raise RuntimeError(f"No hash for {f_name}. Has target {target} been removed?")
+                # rstrip() content, and explicitly add the \n, in case
+                # a hash file does not have a trailing \n.
+                fd.write(f"# From {h_url}\nsha256  {r.read().decode().rstrip()}\n")
         fd.write("# Locally generated\n")
         for license in LICENSES:
             fd.write(f"sha256  {LICENSES[license]}  LICENSE-{license}\n")
-- 
2.34.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-10 21:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-23 20:35 [Buildroot] [PATCH 1/1] utils/update-rust: use urllib.request from stdlib instead of requests James Hilliard
2024-07-10 21:04 ` Thomas Petazzoni via buildroot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.