[elbe-devel] [PATCH 1/5] elbepack: use urllib instead of wget

Thomas Weißschuh thomas.weissschuh at linutronix.de
Tue Aug 20 11:52:11 CEST 2024


The functionality of the urllib module is enough for our usecase.
Using it also improves the user interface and error reporting.
Drop the now unnecessary dependency on wget.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 debian/control           |  1 -
 elbe.spec                |  2 +-
 elbepack/debinstaller.py | 11 +++--------
 elbepack/hashes.py       |  8 +++++---
 4 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/debian/control b/debian/control
index fdec99443be2..1c1365fefe96 100644
--- a/debian/control
+++ b/debian/control
@@ -73,7 +73,6 @@ Depends: ${misc:Depends}, ${python3:Depends},
   python3-gpg,
   python3-libvirt,
   python3-passlib,
-  wget,
   cpio
 Description: common files
  Common files for ELBE (embedded Linux build environment). These
diff --git a/elbe.spec b/elbe.spec
index 1ec9649a0fc0..f55fc66028e1 100644
--- a/elbe.spec
+++ b/elbe.spec
@@ -18,7 +18,7 @@ BuildRequires: python3-setuptools
 BuildRequires: asciidoc
 BuildRequires: xmlto
 
-requires: qemu-kvm, python3-lxml, python3-mako, wget, python3-suds, libvirt-python
+requires: qemu-kvm, python3-lxml, python3-mako, python3-suds, libvirt-python
 
 %description
 ELBE (Embedded Linux Build Environment)
diff --git a/elbepack/debinstaller.py b/elbepack/debinstaller.py
index ef850346a8e6..163d0919fb8e 100644
--- a/elbepack/debinstaller.py
+++ b/elbepack/debinstaller.py
@@ -104,13 +104,6 @@ def setup_apt_keyring(gpg_home, keyring_fname):
             print(f'adding keyring "{key}" to keyring "{ring_path}" failed')
 
 
-def download(url, local_fname):
-    try:
-        subprocess.run(['wget', '-O', local_fname, url], check=True)
-    except subprocess.CalledProcessError:
-        raise NoKinitrdException(f'Failed to download {url}')
-
-
 def verify_release(tmp, base_url):
 
     # setup gpg context, for verifying
@@ -154,7 +147,9 @@ def download_kinitrd(tmp, suite, mirror, skip_signature=False):
     setup_apt_keyring(tmp.fname('/'), 'pubring.gpg')
 
     # download release file
-    download(base_url + 'Release', tmp.fname('Release'))
+    with urlopen(base_url + 'Release') as src, tmp.open('Release', 'wb') as dest:
+        shutil.copyfileobj(src, dest)
+
     if not skip_signature:
         verify_release(tmp, base_url)
 
diff --git a/elbepack/hashes.py b/elbepack/hashes.py
index eaf8e548bd69..e36527dfa1d8 100644
--- a/elbepack/hashes.py
+++ b/elbepack/hashes.py
@@ -3,7 +3,8 @@
 # SPDX-FileCopyrightText: 2018 Linutronix GmbH
 
 import hashlib
-import subprocess
+import shutil
+import urllib.request
 
 
 class HashValidationFailed(Exception):
@@ -43,8 +44,9 @@ class HashValidator:
     def download_and_validate_file(self, upstream_fname, local_fname):
         url = self.base_url + upstream_fname
         try:
-            subprocess.run(['wget', '-O', local_fname, url], check=True)
-        except subprocess.CalledProcessError as e:
+            with urllib.request.urlopen(url) as src, open(local_fname, 'wb') as dest:
+                shutil.copyfileobj(src, dest)
+        except Exception as e:
             raise HashValidationFailed(f'Failed to download {url}') from e
 
         self.validate_file(upstream_fname, local_fname)

-- 
2.46.0



More information about the elbe-devel mailing list