diff options
author | 2018-03-05 21:04:14 +0100 | |
---|---|---|
committer | 2018-03-05 21:04:14 +0100 | |
commit | 92b8bd0879e5f594d1233091437ac9a8b0c240d7 (patch) | |
tree | c0196bf0d0ad2603198f469e0eda88fe71b7abc0 /utils | |
parent | 528f16547689fa771bc7cb8de0885286dd439c17 (diff) | |
parent | fb4a33e586bc041a43cd415869e91d29287dcefd (diff) | |
download | buildroot-92b8bd0879e5f594d1233091437ac9a8b0c240d7.tar.gz buildroot-92b8bd0879e5f594d1233091437ac9a8b0c240d7.tar.bz2 |
Merge branch 'next'
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/scanpypi | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/utils/scanpypi b/utils/scanpypi index c96f1bc892..2b3188dbf6 100755 --- a/utils/scanpypi +++ b/utils/scanpypi @@ -7,13 +7,13 @@ Any package built by scanpypi should be manually checked for errors. """ from __future__ import print_function +from __future__ import absolute_import import argparse import json -import urllib2 +import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse import sys import os import shutil -import StringIO import tarfile import zipfile import errno @@ -23,6 +23,13 @@ import textwrap import tempfile import imp from functools import wraps +from six.moves import map +from six.moves import zip +from six.moves import input +if six.PY2: + import StringIO +else: + import io BUF_SIZE = 65536 @@ -147,15 +154,15 @@ class BuildrootPackage(): self.metadata_url = 'https://pypi.python.org/pypi/{pkg}/json'.format( pkg=self.real_name) try: - pkg_json = urllib2.urlopen(self.metadata_url).read().decode() - except urllib2.HTTPError as error: + pkg_json = six.moves.urllib.request.urlopen(self.metadata_url).read().decode() + except six.moves.urllib.error.HTTPError as error: print('ERROR:', error.getcode(), error.msg, file=sys.stderr) print('ERROR: Could not find package {pkg}.\n' 'Check syntax inside the python package index:\n' 'https://pypi.python.org/pypi/ ' .format(pkg=self.real_name)) raise - except urllib2.URLError: + except six.moves.urllib.error.URLError: print('ERROR: Could not find package {pkg}.\n' 'Check syntax inside the python package index:\n' 'https://pypi.python.org/pypi/ ' @@ -181,7 +188,7 @@ class BuildrootPackage(): 'md5_digest': None}] # In this case, we can't get the name of the downloaded file # from the pypi api, so we need to find it, this should work - urlpath = urllib2.urlparse.urlparse( + urlpath = six.moves.urllib.parse.urlparse( self.metadata['info']['download_url']).path # urlparse().path give something like # /path/to/file-version.tar.gz @@ -193,8 +200,8 @@ class BuildrootPackage(): try: print('Downloading package {pkg} from {url}...'.format( pkg=self.real_name, url=download_url['url'])) - download = urllib2.urlopen(download_url['url']) - except urllib2.HTTPError as http_error: + download = six.moves.urllib.request.urlopen(download_url['url']) + except six.moves.urllib.error.HTTPError as http_error: download = http_error else: self.used_url = download_url @@ -205,7 +212,7 @@ class BuildrootPackage(): if self.md5_sum == download_url['md5_digest']: break else: - if download.__class__ == urllib2.HTTPError: + if download.__class__ == six.moves.urllib.error.HTTPError: raise download raise DownloadFailed('Failed to download package {pkg}' .format(pkg=self.real_name)) @@ -219,7 +226,10 @@ class BuildrootPackage(): Keyword arguments: tmp_path -- directory where you want the package to be extracted """ - as_file = StringIO.StringIO(self.as_string) + if six.PY2: + as_file = StringIO.StringIO(self.as_string) + else: + as_file = io.BytesIO(self.as_string) if self.filename[-3:] == 'zip': with zipfile.ZipFile(as_file) as as_zipfile: tmp_pkg = os.path.join(tmp_path, self.buildroot_name) @@ -303,8 +313,8 @@ class BuildrootPackage(): if len(item) > 0 and item[0] != '#'] req_not_found = self.pkg_req - self.pkg_req = map(pkg_buildroot_name, self.pkg_req) - pkg_tuples = zip(req_not_found, self.pkg_req) + self.pkg_req = list(map(pkg_buildroot_name, self.pkg_req)) + pkg_tuples = list(zip(req_not_found, self.pkg_req)) # pkg_tuples is a list of tuples that looks like # ('werkzeug','python-werkzeug') because I need both when checking if # dependencies already exist or are already in the download list @@ -412,8 +422,7 @@ class BuildrootPackage(): classifiers_licenses = [regexp.sub(r"\1", lic) for lic in self.metadata['info']['classifiers'] if regexp.match(lic)] - licenses = map(lambda x: license_dict[x] if x in license_dict else x, - classifiers_licenses) + licenses = [license_dict[x] if x in license_dict else x for x in classifiers_licenses] if not len(licenses): print('WARNING: License has been set to "{license}". It is most' ' likely wrong, please change it if need be'.format( @@ -427,7 +436,7 @@ class BuildrootPackage(): for license_file in license_files: with open(license_file) as lic_file: match = liclookup.match(lic_file.read()) - if match.confidence >= 90.0: + if match is not None and match.confidence >= 90.0: license_names.append(match.license.id) if len(license_names) > 0: @@ -583,7 +592,7 @@ class BuildrootPackage(): # \t + two spaces is 3 char long help_lines.append('') help_lines.append('\t ' + self.metadata['info']['home_page']) - help_lines = map(lambda x: x + '\n', help_lines) + help_lines = [x + '\n' for x in help_lines] lines += help_lines with open(path_to_config, 'w') as config_file: @@ -624,7 +633,7 @@ def main(): print('Fetching package', package.real_name) try: package.fetch_package_info() - except (urllib2.URLError, urllib2.HTTPError): + except (six.moves.urllib.error.URLError, six.moves.urllib.error.HTTPError): continue if package.metadata_name.lower() == 'setuptools': # setuptools imports itself, that does not work very well @@ -634,7 +643,7 @@ def main(): try: package.download_package() - except urllib2.HTTPError as error: + except six.moves.urllib.error.HTTPError as error: print('Error: {code} {reason}'.format(code=error.code, reason=error.reason)) print('Error downloading package :', package.buildroot_name) @@ -682,7 +691,7 @@ def main(): continue print('Error: Package {name} already exists' .format(name=package.pkg_dir)) - del_pkg = raw_input( + del_pkg = input( 'Do you want to delete existing package ? [y/N]') if del_pkg.lower() == 'y': shutil.rmtree(package.pkg_dir) |