summaryrefslogtreecommitdiff
path: root/tools/patman
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-01-09 20:13:42 -0700
committerSimon Glass <sjg@chromium.org>2022-01-25 12:36:11 -0700
commit5b7968693f9c2aefea5bd50dc1f143ec3a1caa42 (patch)
treeeb56a33c382bd5e881720fae07140d599bc82ce3 /tools/patman
parent8ea6d23ffb7787c5c42b78c38466e46a43bd55ad (diff)
downloadu-boot-5b7968693f9c2aefea5bd50dc1f143ec3a1caa42.tar.gz
patman: Tidy up the download function a little
Reverse the order of the return tuple, so that the filename is first. This seems more obvious than putting the temporary directory first. Correct a bug that leaves a space on the final line. Allow the caller to control the name of the temporary directory. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman')
-rw-r--r--tools/patman/tools.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 2f817f6167..24e2bf567b 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -634,20 +634,22 @@ def PrintFullHelp(fname):
pager = ['more']
command.Run(*pager, fname)
-def Download(url):
+def Download(url, tmpdir_pattern='.patman'):
"""Download a file to a temporary directory
Args:
- url: URL to download
+ url (str): URL to download
+ tmpdir_pattern (str): pattern to use for the temporary directory
+
Returns:
Tuple:
- Temporary directory name
Full path to the downloaded archive file in that directory,
or None if there was an error while downloading
+ Temporary directory name
"""
- print('Downloading: %s' % url)
+ print('- downloading: %s' % url)
leaf = url.split('/')[-1]
- tmpdir = tempfile.mkdtemp('.buildman')
+ tmpdir = tempfile.mkdtemp(tmpdir_pattern)
response = urllib.request.urlopen(url)
fname = os.path.join(tmpdir, leaf)
fd = open(fname, 'wb')
@@ -671,9 +673,11 @@ def Download(url):
status = status + chr(8) * (len(status) + 1)
print(status, end=' ')
sys.stdout.flush()
+ print('\r', end='')
+ sys.stdout.flush()
fd.close()
if done != size:
print('Error, failed to download')
os.remove(fname)
fname = None
- return tmpdir, fname
+ return fname, tmpdir