Skip to content

Commit

Permalink
scanpypi: rework download_package error handling
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Peter Korsgaard <[email protected]>
  • Loading branch information
yegorich authored and jacmet committed Jun 15, 2018
1 parent 3bf2745 commit fb775f4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions utils/scanpypi
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class BuildrootPackage():
"""
Download a package using metadata from pypi
"""
download = None
try:
self.metadata['urls'][0]['filename']
except IndexError:
Expand All @@ -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
Expand All @@ -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']

Expand Down

0 comments on commit fb775f4

Please sign in to comment.