]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
patman: Tidy up the download function a little
authorSimon Glass <sjg@chromium.org>
Mon, 10 Jan 2022 03:13:42 +0000 (20:13 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 25 Jan 2022 19:36:11 +0000 (12:36 -0700)
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>
tools/buildman/toolchain.py
tools/patman/tools.py

index bcae5ef7415e91aada3e49bd2f991012d48bccf8..adc75a7a0b75ecfefac901439bb0781c486afd47 100644 (file)
@@ -571,7 +571,7 @@ class Toolchains:
             os.mkdir(dest)
 
         # Download the tar file for this toolchain and unpack it
-        tmpdir, tarfile = tools.Download(url)
+        tarfile, tmpdir = tools.Download(url, '.buildman')
         if not tarfile:
             return 1
         print(col.Color(col.GREEN, 'Unpacking to: %s' % dest), end=' ')
index 2f817f6167041b21b1b4b64c3b414ddf376b527e..24e2bf567b8d84f6768d7560bd32d8120c417bca 100644 (file)
@@ -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