From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D67AC433F5 for ; Mon, 10 Jan 2022 03:16:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C6BA830BE; Mon, 10 Jan 2022 04:15:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ZEwUmBLL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 47EE483022; Mon, 10 Jan 2022 04:15:20 +0100 (CET) Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D9E6681C08 for ; Mon, 10 Jan 2022 04:15:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2a.google.com with SMTP id w22so5247574iov.3 for ; Sun, 09 Jan 2022 19:15:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WLTIhEek8KJy6UearuM8ehOLlvmF3ZPPM3ExqeJ0BVI=; b=ZEwUmBLLX/hhIvH74jkuwMqmR47UWGmKgn5MfT2AuNr8IlndRpZDh9oIdAtJdjNdyM gGJwOHobPjraxFXlS45xNAgi//n9tqT1+UKDIw5rkU0jJ43hZ3+nLOVVwPJPVLafmLAd w46aEd9H6cD8HPcRcaSA/5qjsc0QWlXVGLowo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WLTIhEek8KJy6UearuM8ehOLlvmF3ZPPM3ExqeJ0BVI=; b=XPGDuxZX05qR+e88K9RhnXGS+2874+uUn5pw9jgEmYVe40Ngit0Uog88sQqR8iub41 A8QTfX6Hrw/v+4Eh7oVWOnNkb3ZAhUbreqKA7jk753R0UTHU63YmaPotwB0GmCVfYghn 4yNR1I6UIYMYR1UPYV6wcx3kIAPbEEnvXYpfHNbGYWaKWma6YM7krApO4zMO5aSQaAau jOQnyzb0tW+cF2mHU6FeE1FIUXTJ2I0MMPigc8g4iVVMWvRpWwFZqSmuo+msNjNJsv4a RJaKdid9iXecPycMYYlxqa8zoQ80Ryy4B4AUZ4aK6ds/C87Nt6fk2kemWM/rh2LHPdSS vJPg== X-Gm-Message-State: AOAM530iO1QNEd7NEYopZmX+Slod9qddzNzgDNoP201LeBv6SXLM2H05 vRM2hUmQNz14u4DeAUzghUEFcfMpHaU+eA== X-Google-Smtp-Source: ABdhPJxPdfV1D2KGOsDM8DHlVuefHMXLcti/hoqpNGpinReMQ/IR7pk2qYikIAMUaRJYgv/53653aw== X-Received: by 2002:a05:6602:2a49:: with SMTP id k9mr5693504iov.168.1641784511506; Sun, 09 Jan 2022 19:15:11 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id d16sm3542182ioy.29.2022.01.09.19.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jan 2022 19:15:11 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass Subject: [PATCH v2 07/38] patman: Tidy up the download function a little Date: Sun, 9 Jan 2022 20:13:42 -0700 Message-Id: <20220110031413.1970836-8-sjg@chromium.org> X-Mailer: git-send-email 2.34.1.575.g55b058a8bb-goog In-Reply-To: <20220110031413.1970836-1-sjg@chromium.org> References: <20220110031413.1970836-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean 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 --- (no changes since v1) tools/buildman/toolchain.py | 2 +- tools/patman/tools.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py index bcae5ef7415..adc75a7a0b7 100644 --- a/tools/buildman/toolchain.py +++ b/tools/buildman/toolchain.py @@ -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=' ') diff --git a/tools/patman/tools.py b/tools/patman/tools.py index 2f817f61670..24e2bf567b8 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 -- 2.34.1.575.g55b058a8bb-goog