2011-08-31 15:38:32 +02:00
|
|
|
import xmlrpclib
|
|
|
|
import re
|
|
|
|
|
|
|
|
import portage
|
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
from euscan import mangling, helpers, output
|
2012-05-23 16:30:43 +02:00
|
|
|
|
|
|
|
HANDLER_NAME = "pypi"
|
2012-07-27 11:26:54 +02:00
|
|
|
CONFIDENCE = 100
|
2012-07-24 15:02:36 +02:00
|
|
|
PRIORITY = 90
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
def can_handle(pkg, url=None):
|
|
|
|
return url and url.startswith('mirror://pypi/')
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-31 15:38:32 +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
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
def scan_url(pkg, url, options):
|
2011-08-31 15:38:32 +02:00
|
|
|
'http://wiki.python.org/moin/PyPiXmlRpc'
|
|
|
|
|
2012-07-24 08:56:00 +02:00
|
|
|
package = guess_package(pkg.cpv, url)
|
2015-03-09 11:07:00 +01:00
|
|
|
return scan_pkg(pkg, {'data': package})
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-07-26 17:46:53 +02:00
|
|
|
|
2012-08-03 21:50:54 +02:00
|
|
|
def scan_pkg(pkg, options):
|
|
|
|
package = options['data']
|
2012-07-26 17:46:53 +02:00
|
|
|
|
2012-05-23 16:30:43 +02:00
|
|
|
output.einfo("Using PyPi XMLRPC: " + package)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
|
|
|
|
versions = client.package_releases(package)
|
|
|
|
|
|
|
|
if not versions:
|
|
|
|
return versions
|
|
|
|
|
|
|
|
versions.reverse()
|
|
|
|
|
2012-07-24 08:56:00 +02:00
|
|
|
cp, ver, rev = portage.pkgsplit(pkg.cpv)
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
ret = []
|
2012-04-19 15:36:44 +02:00
|
|
|
for up_pv in versions:
|
2012-08-03 21:50:54 +02:00
|
|
|
pv = mangling.mangle_version(up_pv, options)
|
2012-04-19 15:36:44 +02:00
|
|
|
if helpers.version_filtered(cp, ver, pv):
|
2011-08-31 15:38:32 +02:00
|
|
|
continue
|
2012-04-19 15:36:44 +02:00
|
|
|
urls = client.release_urls(package, up_pv)
|
2012-08-07 09:39:49 +02:00
|
|
|
urls = " ".join([mangling.mangle_url(infos['url'], options)
|
|
|
|
for infos in urls])
|
2012-08-03 21:50:54 +02:00
|
|
|
ret.append((urls, pv, HANDLER_NAME, CONFIDENCE))
|
2011-08-31 15:38:32 +02:00
|
|
|
return ret
|