1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#! /usr/bin/python3
# Copyright © 2010-2013 Piotr Ożarowski <piotr@debian.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import re
import sys
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'
IGNORED_PKGS = {'python-setuptools', 'python3-setuptools', 'pypy-setuptools'}
DEFAULTS = {
'cpython2': [
'python python\n',
'setuptools python-pkg-resources\n',
'wsgiref python (>= 2.5) | python-wsgiref\n',
'argparse python (>= 2.7) | python-argparse\n',
# not recognized due to .pth file (egg-info is in PIL/ and not in *-packages/)
'pil python-imaging\n'],
'cpython3': [
'setuptools python3-pkg-resources\n',
'argparse python3 (>= 3.2)\n'],
'pypy': []
}
public_egg = re.compile(r'''
/usr/
(
(?P<cpython2>
(lib/python2\.[0-9]/((site)|(dist))-packages)|
(share/python-support/[^/]+)
)|
(?P<cpython3>
(lib/python3/dist-packages)
)|
(?P<pypy>
(lib/pypy/dist-packages)
)
)
/[^/]*\.egg-info
''', re.VERBOSE).match
skip_sensible_names = True if '--skip-sensible-names' in sys.argv else False
chdir(dirname(__file__))
if isdir('../dhpython'):
sys.path.append('..')
else:
sys.path.append('/usr/share/dh-python/dhpython/')
from dhpython.pydist import sensible_pname
if not isdir('cache'):
mkdir('cache')
cache_fpath = join('cache', split(SOURCE)[-1])
if not exists(cache_fpath):
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')
result = {
'cpython2': {},
'cpython3': {},
'pypy': {}}
is_header = True
for line in data.splitlines():
if is_header:
if line.startswith('FILE'):
is_header = False
continue
path, desc = line.rsplit(maxsplit=1)
path = '/' + path.rstrip()
section, pkg_name = desc.rsplit('/', 1)
if pkg_name in IGNORED_PKGS:
continue
match = public_egg(path)
if match:
egg_name = [i.split('-', 1)[0] for i in path.split('/')
if i.endswith('.egg-info')][0]
if egg_name.endswith('.egg'):
egg_name = egg_name[:-4]
impl = next(key for key, value in match.groupdict().items() if value)
if skip_sensible_names and\
sensible_pname(impl, egg_name) == pkg_name:
continue
processed = result[impl]
if egg_name not in processed:
processed[egg_name] = pkg_name
for impl, details in result.items():
with open('{}_fallback'.format(impl), 'w') as fp:
result = DEFAULTS[impl]
if result:
fp.writelines(result)
result = sorted('{} {}\n'.format(egg, pkg) for egg, pkg in details.items())
fp.writelines(result)
|