Description: Add some basic support for use in Ubuntu Author: James Page --- a/pydist/generate_fallback_list.py +++ b/pydist/generate_fallback_list.py @@ -21,12 +21,16 @@ import re import sys +from distro_info import DistroInfo from gzip import decompress from os import chdir, mkdir from os.path import dirname, exists, isdir, join, split from urllib.request import urlopen -SOURCE = 'http://ftp.debian.org/debian/dists/unstable/main/Contents-amd64.gz' +UBUNTU_SOURCE = 'http://archive.ubuntu.com/ubuntu/dists/%s/Contents-amd64.gz' \ + % DistroInfo('ubuntu').devel() +DEBIAN_SOURCE = 'http://ftp.debian.org/debian/dists/unstable/main/Contents-amd64.gz' + IGNORED_PKGS = {'python-setuptools', 'python3-setuptools', 'pypy-setuptools'} DEFAULTS = { 'cpython2': [ @@ -60,6 +64,7 @@ public_egg = re.compile(r''' ''', re.VERBOSE).match skip_sensible_names = True if '--skip-sensible-names' in sys.argv else False +SOURCE = DEBIAN_SOURCE if '--ubuntu' not in sys.argv else UBUNTU_SOURCE chdir(dirname(__file__)) if isdir('../dhpython'): @@ -72,12 +77,16 @@ if not isdir('cache'): mkdir('cache') cache_fpath = join('cache', split(SOURCE)[-1]) if not exists(cache_fpath): + print("Retrieving Contents from %s" % SOURCE) data = urlopen(SOURCE).read() with open(cache_fpath, 'wb') as fp: fp.write(data) else: data = open(cache_fpath, 'rb').read() -data = str(decompress(data), encoding='UTF-8') +try: + data = str(decompress(data), encoding='UTF-8') +except UnicodeDecodeError: + data = str(decompress(data), encoding='ISO-8859-15') result = { 'cpython2': {}, @@ -90,7 +99,12 @@ for line in data.splitlines(): if line.startswith('FILE'): is_header = False continue - path, desc = line.rsplit(maxsplit=1) + try: + path, desc = line.rsplit(maxsplit=1) + except ValueError: + # NOTE(jamespage) some lines in Ubuntu are not + # parseable. + continue path = '/' + path.rstrip() section, pkg_name = desc.rsplit('/', 1) if pkg_name in IGNORED_PKGS: --- a/pydist/Makefile +++ b/pydist/Makefile @@ -1,12 +1,14 @@ #!/usr/bin/make -f +FALLBACK_FLAGS = $(shell dpkg-vendor --is ubuntu && echo "--ubuntu") + clean: rm -rf cache #rm -f dist_fallback rm -f README.PyDist.html dist_fallback: - python3 ./generate_fallback_list.py + python3 ./generate_fallback_list.py $(FALLBACK_FLAGS) README.PyDist.html: README.PyDist rst2html $< $@