From de295fe5246a21f5642724b8a40eaaa9f6207b81 Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Fri, 19 Nov 2021 07:18:34 -0500 Subject: [PATCH] ubuntutools/misc: return dst Path object from download() --- ubuntutools/misc.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ubuntutools/misc.py b/ubuntutools/misc.py index a6a7a02..dc29cd2 100644 --- a/ubuntutools/misc.py +++ b/ubuntutools/misc.py @@ -304,6 +304,8 @@ def download(src, dst, size=0, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT): it will be stripped from the URL and passed to the requests library. This may throw a DownloadError. + + On success, this will return the dst as a Path object. """ src = str(src) parsedsrc = urlparse(src) @@ -322,11 +324,11 @@ def download(src, dst, size=0, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT): if dst.exists(): if src.samefile(dst): Logger.info(f'Using existing file {dst}') - return + return dst Logger.info(f'Replacing existing file {dst}') Logger.info(f'Copying file {src} to {dst}') shutil.copyfile(src, dst) - return + return dst (src, username, password) = extract_authentication(src) auth = (username, password) if username or password else None @@ -347,6 +349,7 @@ def download(src, dst, size=0, *, blocksize=DOWNLOAD_BLOCKSIZE_DEFAULT): except requests.exceptions.RequestException as e: raise DownloadError(e) shutil.move(tmpdst, dst) + return dst class _StderrProgressBar(object):