euscan: new cpan handler

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
Corentin Chary 2012-04-20 17:27:16 +02:00
parent 3da5fb5240
commit b0ccdd2157
4 changed files with 82 additions and 5 deletions

3
TODO
View File

@ -22,6 +22,9 @@ euscan
- Add a way to how we failled to find a new version - Add a way to how we failled to find a new version
- add a HTTP cache (1day, configurable) - add a HTTP cache (1day, configurable)
- add a way to enable/disable methods: other_distributions,remote_euscan,handlers, etc.... - add a way to enable/disable methods: other_distributions,remote_euscan,handlers, etc....
- try to differenciate stable, beta, alpha versions
- give the full Package() to handlers, not just the cpv string
- better handlers detection logic __init__.py
Site Handlers Site Handlers
------------- -------------

View File

@ -1,6 +1,6 @@
from euscan.handlers import generic, php, pypi, rubygem, kde from euscan.handlers import generic, php, pypi, rubygem, kde, cpan
handlers = [ kde, php, pypi, rubygem, generic ] handlers = [ kde, php, pypi, rubygem, cpan, generic ]
def find_best_handler(cpv, url): def find_best_handler(cpv, url):
for handler in handlers: for handler in handlers:

View File

@ -0,0 +1,75 @@
import re
import portage
import urllib2
import json
from euscan import helpers
import euscan
_cpan_package_name_re = re.compile("mirror://cpan/authors/.*/([^/.]*).*")
def can_handle(cpv, url):
return url.startswith('mirror://cpan/')
def guess_package(cp, url):
match = _cpan_package_name_re.search(url)
pkg = None
if match:
pkg = match.group(1)
try:
cp, ver, rev = portage.pkgsplit('fake/' + pkg)
except:
pass
cat, pkg = cp.split("/")
return pkg
def scan(cpv, url):
cp, ver, rev = portage.pkgsplit(cpv)
pkg = guess_package(cp, url)
orig_url = url
url = 'http://search.cpan.org/api/dist/%s' % pkg
euscan.output.einfo("Using: " + url)
try:
fp = helpers.urlopen(url)
except urllib2.URLError:
return []
except IOError:
return []
if not fp:
return []
data = fp.read()
data = json.loads(data)
if 'releases' not in data:
return []
ret = []
for version in data['releases']:
up_pv = version['version']
pv = helpers.gentoo_mangle_version(up_pv)
if helpers.version_filtered(cp, ver, pv):
continue
url = 'mirror://cpan/authors/id/%s/%s/%s/%s' % \
(version['cpanid'][0], version['cpanid'][0:1], version['cpanid'], version['archive'])
if url == orig_url:
continue
ret.append(( url, pv ))
return ret
def brute_force(cpv, url):
return []

View File

@ -25,7 +25,8 @@ def guess_package_and_channel(cp, url):
return pkg, host return pkg, host
def scan(cpv, url): def scan(cpv, url):
pkg, channel = guess_package_and_channel(cpv, url) cp, ver, rev = portage.pkgsplit(cpv)
pkg, channel = guess_package_and_channel(cp, url)
orig_url = url orig_url = url
url = 'http://%s/rest/r/%s/allreleases.xml' % (channel, pkg.lower()) url = 'http://%s/rest/r/%s/allreleases.xml' % (channel, pkg.lower())
@ -49,8 +50,6 @@ def scan(cpv, url):
nodes = dom.getElementsByTagName("v") nodes = dom.getElementsByTagName("v")
ret = [] ret = []
cp, ver, rev = portage.pkgsplit(cpv)
for node in nodes: for node in nodes:
up_pv = node.childNodes[0].data up_pv = node.childNodes[0].data
pv = helpers.gentoo_mangle_version(up_pv) pv = helpers.gentoo_mangle_version(up_pv)