euscan-ng/pym/euscan/handlers/url/pypi.py

62 lines
1.3 KiB
Python
Raw Normal View History

import xmlrpclib
import re
import portage
from euscan import helpers, output
HANDLER_NAME = "pypi"
CONFIDENCE = 100.0
PRIORITY = 90
2012-04-28 18:16:05 +02:00
def can_handle(pkg, url):
return url.startswith('mirror://pypi/')
2012-04-28 18:16:05 +02:00
def guess_package(cp, url):
match = re.search('mirror://pypi/\w+/(.*)/.*', url)
if match:
return match.group(1)
cat, pkg = cp.split("/")
return pkg
2012-04-28 18:16:05 +02:00
def scan(pkg, url):
'http://wiki.python.org/moin/PyPiXmlRpc'
package = guess_package(pkg.cpv, url)
ret = []
for urls, pv in scan_remote(pkg, [package]):
ret.append((urls, pv, HANDLER_NAME, CONFIDENCE))
return ret
def scan_remote(pkg, remote_data):
package = remote_data[0]
output.einfo("Using PyPi XMLRPC: " + package)
client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
versions = client.package_releases(package)
if not versions:
return versions
versions.reverse()
cp, ver, rev = portage.pkgsplit(pkg.cpv)
ret = []
for up_pv in versions:
pv = helpers.gentoo_mangle_version(up_pv)
if helpers.version_filtered(cp, ver, pv):
continue
urls = client.release_urls(package, up_pv)
2012-04-28 18:16:05 +02:00
urls = " ".join([infos['url'] for infos in urls])
ret.append((urls, pv))
return ret