[elbe-devel] [PATCH 1/2] hashes debinstaller: use wget for downloads, because of improved feedback

Manuel Traut manut at linutronix.de
Wed Nov 21 15:30:13 CET 2018


On Wed, Nov 21, 2018 at 01:08:04PM +0100, Torben Hohn wrote:
> copyfileobj() does not support progress callbacks. getting progress
> reports would require reimplementing it.
> 
> Switch from urlopen() / copyfileobj() to system('wget ...')
> 
> Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
Signed-off-by: Manuel Traut <manut at linutronix.de>
Reviewed-by: Manuel Traut <manut at linutronix.de>

merged into devel/elbe-3.0 - THANKS!

> ---
>  elbepack/debinstaller.py |  8 +++-----
>  elbepack/hashes.py       | 26 ++++----------------------
>  2 files changed, 7 insertions(+), 27 deletions(-)
> 
> diff --git a/elbepack/debinstaller.py b/elbepack/debinstaller.py
> index d251f202..baf8d8d4 100644
> --- a/elbepack/debinstaller.py
> +++ b/elbepack/debinstaller.py
> @@ -116,11 +116,9 @@ def setup_apt_keyring(gpg_home, keyring_fname):
>  
>  def download(url, local_fname):
>      try:
> -        rf = urlopen(url, None, 10)
> -        with open(local_fname, "w") as wf:
> -            copyfileobj(rf, wf)
> -    finally:
> -        rf.close()
> +        system('wget -O "%s" "%s"' % (local_fname, url))
> +    except CommandError:
> +        raise NoKinitrdException('Failed to download %s' % url)
>  
>  
>  def download_release(tmp, base_url):
> diff --git a/elbepack/hashes.py b/elbepack/hashes.py
> index d2dfe053..e32d7456 100644
> --- a/elbepack/hashes.py
> +++ b/elbepack/hashes.py
> @@ -4,21 +4,7 @@
>  # SPDX-License-Identifier: GPL-3.0-or-later
>  
>  import hashlib
> -from shutil import copyfileobj
> -
> -# different module names in python 2 and 3
> -try:
> -    import urllib.request
> -
> -    # when running inside pylint this import fails
> -    # disable no-member here
> -    #
> -    # pylint: disable=no-member
> -
> -    urlopen = urllib.request.urlopen
> -except ImportError:
> -    import urllib2
> -    urlopen = urllib2.urlopen
> +from elbepack.shellhelper import system, CommandError
>  
>  
>  class HashValidationFailed(Exception):
> @@ -57,13 +43,9 @@ class HashValidator(object):
>  
>      def download_and_validate_file(self, upstream_fname, local_fname):
>          url = self.base_url + upstream_fname
> -        rf = None
>          try:
> -            rf = urlopen(url, None, 10)
> -            with open(local_fname, "w") as wf:
> -                copyfileobj(rf, wf)
> -        finally:
> -            if rf is not None:
> -                rf.close()
> +            system('wget -O "%s" "%s"' % (local_fname, url))
> +        except CommandError:
> +            raise HashValidationFailed('Failed to download %s' % url)
>  
>          self.validate_file(upstream_fname, local_fname)
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel



More information about the elbe-devel mailing list