From patchwork Wed Jun 13 07:37:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yegor Yefremov X-Patchwork-Id: 928731 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=googlemail.com Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415JVx6lTcz9s19 for ; Wed, 13 Jun 2018 17:37:29 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 6CA3C8B10C; Wed, 13 Jun 2018 07:37:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GXhHnpYqXLZA; Wed, 13 Jun 2018 07:37:26 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 3FF708A01F; Wed, 13 Jun 2018 07:37:26 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 6C1231C276F for ; Wed, 13 Jun 2018 07:37:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 696588A2D6 for ; Wed, 13 Jun 2018 07:37:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nIcd3E8f-juK for ; Wed, 13 Jun 2018 07:37:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.visionsystems.de (mail.visionsystems.de [213.209.99.202]) by hemlock.osuosl.org (Postfix) with ESMTP id 289C18A2EB for ; Wed, 13 Jun 2018 07:37:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.visionsystems.de (Postfix) with ESMTP id C302436A67F; Wed, 13 Jun 2018 09:37:21 +0200 (CEST) Received: from mail.visionsystems.de ([127.0.0.1]) by localhost (mail.visionsystems.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 17038-05; Wed, 13 Jun 2018 09:37:21 +0200 (CEST) Received: from visionsystems.de (kallisto.visionsystems.local [192.168.1.3]) by mail.visionsystems.de (Postfix) with ESMTP id A320836A67E; Wed, 13 Jun 2018 09:37:21 +0200 (CEST) Received: from development1.visionsystems.de ([192.168.1.36]) by visionsystems.de with Microsoft SMTPSVC(6.0.3790.4675); Wed, 13 Jun 2018 09:37:20 +0200 From: yegorslists@googlemail.com To: buildroot@buildroot.org Date: Wed, 13 Jun 2018 09:37:10 +0200 Message-Id: <20180613073710.5715-1-yegorslists@googlemail.com> X-Mailer: git-send-email 2.17.0 X-OriginalArrivalTime: 13 Jun 2018 07:37:20.0963 (UTC) FILETIME=[5CE36930:01D402E9] X-Virus-Scanned: amavisd-new at visionsystems.de Subject: [Buildroot] [PATCH] scanpypi: rework download_package error handling X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Yegor Yefremov Some packages don't provide source archive but only a wheel file. In this case download variable is not defined. So define this variable at the very beginning and check whether it is None after searching for source archives in the metadata. Bonus: fix PEP8 issue with wrong indentation. Signed-off-by: Yegor Yefremov --- utils/scanpypi | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/utils/scanpypi b/utils/scanpypi index 8a2ae00434..12c96b842e 100755 --- a/utils/scanpypi +++ b/utils/scanpypi @@ -178,6 +178,7 @@ class BuildrootPackage(): """ Download a package using metadata from pypi """ + download = None try: self.metadata['urls'][0]['filename'] except IndexError: @@ -201,7 +202,7 @@ class BuildrootPackage(): continue try: print('Downloading package {pkg} from {url}...'.format( - pkg=self.real_name, url=download_url['url'])) + pkg=self.real_name, url=download_url['url'])) download = six.moves.urllib.request.urlopen(download_url['url']) except six.moves.urllib.error.HTTPError as http_error: download = http_error @@ -213,11 +214,14 @@ class BuildrootPackage(): self.md5_sum = hashlib.md5(self.as_string).hexdigest() if self.md5_sum == download_url['digests']['md5']: break - else: - if download.__class__ == six.moves.urllib.error.HTTPError: - raise download - raise DownloadFailed('Failed to download package {pkg}' + + if download is None: + raise DownloadFailed('Failed to download package {pkg}: ' + 'No source archive available' .format(pkg=self.real_name)) + elif download.__class__ == six.moves.urllib.error.HTTPError: + raise download + self.filename = self.used_url['filename'] self.url = self.used_url['url']